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 node_modules
npm-debug.log \ No newline at end of file
\ No newline at end of file
# Set your variables and rename to .env # Set your variables and rename to .env
NODE_ENV=development NODE_ENV=development
NODE_PORT=4000
PGHOST=localhost PGHOST=localhost
PGPORT=5432 PGPORT=5432
......
...@@ -3,6 +3,7 @@ LABEL maintainer=francois.romain@beta.gouv.fr ...@@ -3,6 +3,7 @@ LABEL maintainer=francois.romain@beta.gouv.fr
ENV dir /api ENV dir /api
ENV NODE_ENV production ENV NODE_ENV production
ENV NODE_PORT 4000
WORKDIR $dir WORKDIR $dir
# cache node_modules if no changes to package.json # 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/). ...@@ -9,24 +9,56 @@ Plus d'infos sur le projet [ici](http://camino.beta.gouv.fr/).
## Npm scripts ## Npm scripts
```bash ```bash
# Install dependencies. # Installe les dépendances
npm install npm install
# Start server with nodemon # Démarre le serveur avec nodemon
npm run dev npm run dev
# Start server with node # Démarre le serveur avec node
npm start 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 ```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 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 ## postgres
......
...@@ -4,15 +4,12 @@ ...@@ -4,15 +4,12 @@
const virtualHost = process.env.VIRTUAL_HOST const virtualHost = process.env.VIRTUAL_HOST
const protocol = virtualHost ? 'https' : 'http' const protocol = virtualHost ? 'https' : 'http'
const dir = '' const port = Number(process.env.NODE_PORT)
const port = 4000
const host = virtualHost ? '0.0.0.0' : 'localhost'
const url = virtualHost const url = virtualHost
? `${protocol}://${virtualHost}/${dir}` ? `${protocol}://${virtualHost}/`
: `${protocol}://${host}:${port}/${dir}` : `${protocol}://localhost:${port}/`
module.exports = { module.exports = {
port, port,
host,
url url
} }
require('dotenv').config({ path: '../.env' }) require('dotenv').config({ path: '../.env' })
module.exports = { module.exports = {
client: 'pg', development: {
connection: { client: 'pg',
host: process.env.PGHOST, connection: {
port: process.env.PGPORT, host: process.env.PGHOST,
database: process.env.PGDATABASE, port: process.env.PGPORT,
user: process.env.PGUSER database: process.env.PGDATABASE,
user: process.env.PGUSER
},
debug: true,
migrations: {
directory: '../_tools/knex/migrations'
},
seeds: {
directory: '../_tools/knex/seeds'
}
}, },
debug: true, production: {
migrations: { client: 'pg',
directory: '../_tools/knex/migrations' connection: {
}, host: process.env.PGHOST,
seeds: { port: process.env.PGPORT,
directory: '../_tools/knex/seeds' database: process.env.PGDATABASE,
user: process.env.PGUSER
}
} }
} }
...@@ -11,6 +11,7 @@ services: ...@@ -11,6 +11,7 @@ services:
- postgres - postgres
environment: environment:
NODE_ENV: development NODE_ENV: development
NODE_PORT: 4000
PGHOST: postgres PGHOST: postgres
PGPORT: 5432 PGPORT: 5432
PGDATABASE: camino PGDATABASE: camino
...@@ -21,6 +22,10 @@ services: ...@@ -21,6 +22,10 @@ services:
postgres: postgres:
image: postgres:alpine image: postgres:alpine
environment:
PGUSER: postgres
expose:
- 5432
volumes: volumes:
- data:/var/lib/postgresql/data - data:/var/lib/postgresql/data
......
...@@ -3,7 +3,7 @@ require('./postgres') ...@@ -3,7 +3,7 @@ require('./postgres')
const chalk = require('chalk') const chalk = require('chalk')
const express = require('express') const express = require('express')
var graphqlHTTP = require('express-graphql') var graphqlHTTP = require('express-graphql')
const { port, host, url } = require('./conf') const { port, url } = require('./conf')
const schema = require('./graphql/schemas') const schema = require('./graphql/schemas')
const resolvers = require('./graphql/resolvers') const resolvers = require('./graphql/resolvers')
...@@ -18,6 +18,6 @@ app.use( ...@@ -18,6 +18,6 @@ app.use(
}) })
) )
app.listen(port, host, () => { app.listen(port, () => {
console.log(chalk.bgWhiteBright.black.bold('Server:' + url)) console.log(chalk.bgWhiteBright.black.bold('Server: ' + url))
}) })
const Knex = require('knex') const Knex = require('knex')
const knexConf = require('../conf/knex') const knexConf = require('../conf/knex')[process.env.NODE_ENV]
const { Model } = require('objection') const { Model } = require('objection')
const knex = Knex(knexConf) 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