docker: Add docker support for express and redis services
This commit is contained in:
parent
0498ea8541
commit
232c69bdde
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
node_modules
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
docker
|
10
app.js
10
app.js
@ -7,13 +7,6 @@ const path = require('path');
|
|||||||
const cookieParser = require('cookie-parser');
|
const cookieParser = require('cookie-parser');
|
||||||
const logger = require('morgan');
|
const logger = require('morgan');
|
||||||
const i18n = require('i18n-2');
|
const i18n = require('i18n-2');
|
||||||
const redis = require('redis');
|
|
||||||
|
|
||||||
const [redisHost, redisPort] = [process.env.REDIS_HOST, process.env.REDIS_PORT];
|
|
||||||
const redisClient = redis.createClient(redisPort, redisHost);
|
|
||||||
redisClient.on('error', (error) => {
|
|
||||||
console.error('Redis error:', error);
|
|
||||||
});
|
|
||||||
|
|
||||||
const indexRouter = require('./routes/index');
|
const indexRouter = require('./routes/index');
|
||||||
const apiRouter = require('./routes/api');
|
const apiRouter = require('./routes/api');
|
||||||
@ -34,7 +27,8 @@ app.use(express.static(path.join(__dirname, 'public')));
|
|||||||
const sess = {
|
const sess = {
|
||||||
secret: 'keyboard cat',
|
secret: 'keyboard cat',
|
||||||
resave: true,
|
resave: true,
|
||||||
saveUninitialized: true
|
saveUninitialized: true,
|
||||||
|
cookie: { secure: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.get('env') === 'production') {
|
if (app.get('env') === 'production') {
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const debug = require('debug')('soundbirder:cache');
|
const debug = require('debug')('soundbirder:cache');
|
||||||
const redis = require('redis');
|
const redis = require('redis');
|
||||||
[redisHost, redisPort] = [process.env.REDIS_HOST, process.env.REDIS_PORT];
|
const host = process.env.REDIS_HOST ? process.env.REDIS_HOST : 'localhost';
|
||||||
const redisClient = redis.createClient(redisPort, redisHost);
|
const port = process.env.REDIS_PORT ? process.env.REDIS_PORT : 6379;
|
||||||
|
const url = `redis://${host}:${port}`;
|
||||||
|
const redisClient = redis.createClient({
|
||||||
|
url
|
||||||
|
});
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
redisClient.connect();
|
redisClient.connect();
|
||||||
})();
|
})();0
|
||||||
|
|
||||||
function cacheResponse(request, response) {
|
function cacheResponse(request, response) {
|
||||||
debug("Caching response", request);
|
debug("Caching response", request);
|
||||||
|
28
docker-compose.yml
Normal file
28
docker-compose.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
version: '3.9'
|
||||||
|
|
||||||
|
services:
|
||||||
|
express:
|
||||||
|
container_name: soundbirder_express
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./docker/express/Dockerfile
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
- REDIS_HOST=${REDIS_HOST:-soundbirder_redis}
|
||||||
|
- REDIS_PORT=${REDIS_PORT:-6379}
|
||||||
|
ports:
|
||||||
|
- "${EXPRESS_PORT:-3000}:3000"
|
||||||
|
networks:
|
||||||
|
- soundbirder_network
|
||||||
|
depends_on:
|
||||||
|
- redis
|
||||||
|
|
||||||
|
redis:
|
||||||
|
container_name: soundbirder_redis
|
||||||
|
image: redis
|
||||||
|
networks:
|
||||||
|
- soundbirder_network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
soundbirder_network:
|
||||||
|
driver: bridge
|
13
docker/express/Dockerfile
Normal file
13
docker/express/Dockerfile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
FROM node:16.17.0
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
COPY package*.json .
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
RUN npm ci --only=production
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
CMD [ "./bin/www" ]
|
@ -2,7 +2,7 @@
|
|||||||
"Game": "Jeu",
|
"Game": "Jeu",
|
||||||
"About": "À propos",
|
"About": "À propos",
|
||||||
"Contact": "Contact",
|
"Contact": "Contact",
|
||||||
"SoundBirder is an open-source web application to learn bird song identification. It is based on bird records from Xeno-Canto and data from eBird": "SoundBirder est une application web open-source qui permet d'apprendre à reconnaitre les chants d'oiseaux. Elle se base sur les enregistrements audio de Xeno-Canto est sur les données de répartitions d'eBird",
|
"SoundBirder is an open-source web application to learn bird song identification. It is based on bird records from Xeno-Canto and data from eBird": "SoundBirder est une application web open-source qui permet d'apprendre à reconnaitre les chants d'oiseaux. Elle se base sur des enregistrements audios de Xeno-Canto et sur les données de répartitions d'eBird",
|
||||||
"Author": "Auteur",
|
"Author": "Auteur",
|
||||||
"The project is made with ♥ by Samuel ORTION": "Ce projet est fait avec ♥ par Samuel ORTION"
|
"The project is made with ♥ by Samuel ORTION": "Ce projet est fait avec ♥ par Samuel ORTION"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user