Skip to content
Snippets Groups Projects
Commit 47cfcdb7 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

docker compose for production

parent ff164780
No related branches found
No related tags found
No related merge requests found
# IMAGE FOR BUILDING
FROM node:12.20-alpine as build
RUN apk add --no-cache git python make g++
WORKDIR /home/node/app
COPY package.json .
COPY yarn.lock .
# Install production node modules for server use
RUN yarn install --frozen-lockfile --production=true
# Copy to another folder for later use
RUN mv node_modules production_node_modules
# Install development node modules for building webpack bundle
RUN yarn install --frozen-lockfile --production=false
COPY . .
ARG node_env
ARG server_protocol
ARG server_host
ARG server_port
ENV NODE_ENV=$node_env
ENV SERVER_PROTOCOL=$server_protocol
ENV SERVER_HOST=$server_host
ENV SERVER_PORT=$server_port
RUN yarn pubsweet build
# IMAGE FOR RUNNING
FROM node:12.20-alpine as server
WORKDIR /home/node/app
RUN chown -R node:node .
USER node
COPY --chown=node:node ./config ./config
COPY --chown=node:node ./public ./public
COPY --chown=node:node ./scripts ./scripts
COPY --chown=node:node ./server ./server
COPY --chown=node:node ./startServer.js .
COPY --from=build /home/node/app/_build/assets ./_build
COPY --from=build /home/node/app/production_node_modules ./node_modules
ENTRYPOINT ["sh", "./scripts/setupProdServer.sh"]
CMD ["node", "./startServer.js"]
...@@ -8,11 +8,11 @@ module.exports = { ...@@ -8,11 +8,11 @@ module.exports = {
port: 'SERVER_PORT', port: 'SERVER_PORT',
secret: 'PUBSWEET_SECRET', secret: 'PUBSWEET_SECRET',
db: { db: {
user: 'POSTGRES_USER',
password: 'POSTGRES_PASSWORD',
host: 'POSTGRES_HOST', host: 'POSTGRES_HOST',
database: 'POSTGRES_DB',
port: 'POSTGRES_PORT', port: 'POSTGRES_PORT',
database: 'POSTGRES_DB',
user: 'POSTGRES_USER',
password: 'POSTGRES_PASSWORD',
}, },
}, },
} }
const path = require('path') const path = require('path')
const components = require('./components.json') const components = require('./components.json')
const logger = require('winston') const logger = require('winston')
const { deferConfig } = require('config/defer')
module.exports = { module.exports = {
teams: { teams: {
...@@ -40,6 +41,10 @@ module.exports = { ...@@ -40,6 +41,10 @@ module.exports = {
port: 3000, port: 3000,
logger, logger,
uploads: 'uploads', uploads: 'uploads',
baseUrl: deferConfig(
cfg =>
`['pubsweet-server'].protocol:://['pubsweet-server'].host:${cfg['pubsweet-server'].port}`,
),
typeDefs: ` typeDefs: `
extend type User { extend type User {
name: String name: String
......
module.exports = {}
version: '3'
services:
server:
build:
context: .
dockerfile: ./Dockerfile-production
target: server
args:
- node_env=${NODE_ENV:-production}
- server_protocol=${SERVER_PROTOCOL}
- server_host=${SERVER_HOST}
- server_port=${SERVER_PORT}
ports:
- ${SERVER_PORT:-3000}:${SERVER_PORT:-3000}
environment:
- NODE_ENV=${NODE_ENV:-production}
- POSTGRES_HOST=${POSTGRES_HOST}
- POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- PUBSWEET_SECRET=${PUBSWEET_SECRET}
- SERVER_PROTOCOL=${SERVER_PROTOCOL}
- SERVER_HOST=${SERVER_HOST}
- SERVER_PORT=${SERVER_PORT}
- ORCID_CLIENT_ID=${ORCID_CLIENT_ID}
- ORCID_CLIENT_SECRET=${ORCID_CLIENT_SECRET}
job-xsweet:
image: pubsweet/job-xsweet
depends_on:
- server
command:
[
'bash',
'./scripts/wait-for-it.sh',
'server:${SERVER_PORT}',
--,
'node',
'src/xsweet.js',
]
environment:
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
volumes:
- ./scripts/wait-for-it.sh:/home/node/scripts/wait-for-it.sh
#!/bin/sh
set -x
# This is run through docker. Its CWD will be the root folder.
node_modules/.bin/pubsweet migrate
exec "$@"
...@@ -90,6 +90,10 @@ const configureApp = app => { ...@@ -90,6 +90,10 @@ const configureApp = app => {
// app.use('/', index) // app.use('/', index)
app.use('/healthcheck', (req, res) => res.send('All good!')) app.use('/healthcheck', (req, res) => res.send('All good!'))
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '..', '_build', 'index.html'))
})
app.use((err, req, res, next) => { app.use((err, req, res, next) => {
// development error handler, will print stacktrace // development error handler, will print stacktrace
if (app.get('env') === 'development' || app.get('env') === 'test') { if (app.get('env') === 'development' || app.get('env') === 'test') {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment