Skip to content
Snippets Groups Projects
Commit 0898c7ce authored by Francois Romain's avatar Francois Romain
Browse files

chore: configuration docker

parent 986fa7e1
No related branches found
No related tags found
No related merge requests found
node_modules
npm-debug.log
\ No newline at end of file
node_modules
\ No newline at end of file
# Set your variables and rename to .env
NODE_ENV=development
NODE_PORT=4000
PGHOST=localhost
PGPORT=5432
......
......@@ -3,6 +3,7 @@ LABEL maintainer=francois.romain@beta.gouv.fr
ENV dir /api
ENV NODE_ENV production
ENV NODE_PORT 4000
WORKDIR $dir
# cache node_modules if no changes to package.json
......
......@@ -9,24 +9,56 @@ Plus d'infos sur le projet [ici](http://camino.beta.gouv.fr/).
## Npm scripts
```bash
# Install dependencies.
# Installe les dépendances
npm install
# Start server with nodemon
# Démarre le serveur avec nodemon
npm run dev
# Start server with node
# Démarre le serveur avec node
npm start
```
---
## docker compose
## Docker
### Pour du dévelopement local
```bash
# Démarre l'application et la base de donnée dans des conteneurs Docker
# en mode `development`
# écoute sur http://localhost:4000
docker-compose -f ./docker-compose.local.yml up --build
```
### Pour du tester l'application en local dans un environement de production
requiert:
* une installation locale et active de https://github.com/jwilder/nginx-proxy
* un certificat ssl auto-signé
[instructions](https://medium.com/@francoisromain/set-a-local-web-development-environment-with-custom-urls-and-https-3fbe91d2eaf0)
```bash
# Démarre l'application dans un container Docker
# en mode `production`
# écoute sur https://api.camino.local
docker-compose -f ./docker-compose.local.yml up --build
```
### Version de production
[instructions](https://medium.com/@francoisromain/host-multiple-websites-with-https-inside-docker-containers-on-a-single-server-18467484ab95)
```bash
# Démarre l'application dans un container Docker
# en mode `production`
# écoute sur http://api.camino.pw
docker-compose up -d --build
```
---
## postgres
......
......@@ -4,15 +4,12 @@
const virtualHost = process.env.VIRTUAL_HOST
const protocol = virtualHost ? 'https' : 'http'
const dir = ''
const port = 4000
const host = virtualHost ? '0.0.0.0' : 'localhost'
const port = Number(process.env.NODE_PORT)
const url = virtualHost
? `${protocol}://${virtualHost}/${dir}`
: `${protocol}://${host}:${port}/${dir}`
? `${protocol}://${virtualHost}/`
: `${protocol}://localhost:${port}/`
module.exports = {
port,
host,
url
}
require('dotenv').config({ path: '../.env' })
module.exports = {
client: 'pg',
connection: {
host: process.env.PGHOST,
port: process.env.PGPORT,
database: process.env.PGDATABASE,
user: process.env.PGUSER
development: {
client: 'pg',
connection: {
host: process.env.PGHOST,
port: process.env.PGPORT,
database: process.env.PGDATABASE,
user: process.env.PGUSER
},
debug: true,
migrations: {
directory: '../_tools/knex/migrations'
},
seeds: {
directory: '../_tools/knex/seeds'
}
},
debug: true,
migrations: {
directory: '../_tools/knex/migrations'
},
seeds: {
directory: '../_tools/knex/seeds'
production: {
client: 'pg',
connection: {
host: process.env.PGHOST,
port: process.env.PGPORT,
database: process.env.PGDATABASE,
user: process.env.PGUSER
}
}
}
......@@ -11,6 +11,7 @@ services:
- postgres
environment:
NODE_ENV: development
NODE_PORT: 4000
PGHOST: postgres
PGPORT: 5432
PGDATABASE: camino
......@@ -21,6 +22,10 @@ services:
postgres:
image: postgres:alpine
environment:
PGUSER: postgres
expose:
- 5432
volumes:
- data:/var/lib/postgresql/data
......
......@@ -3,7 +3,7 @@ require('./postgres')
const chalk = require('chalk')
const express = require('express')
var graphqlHTTP = require('express-graphql')
const { port, host, url } = require('./conf')
const { port, url } = require('./conf')
const schema = require('./graphql/schemas')
const resolvers = require('./graphql/resolvers')
......@@ -18,6 +18,6 @@ app.use(
})
)
app.listen(port, host, () => {
console.log(chalk.bgWhiteBright.black.bold('Server:' + url))
app.listen(port, () => {
console.log(chalk.bgWhiteBright.black.bold('Server: ' + url))
})
const Knex = require('knex')
const knexConf = require('../conf/knex')
const knexConf = require('../conf/knex')[process.env.NODE_ENV]
const { Model } = require('objection')
const knex = Knex(knexConf)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment