backend dockerfile and compose seem to be pretty solid now

This commit is contained in:
Ulf Gebhardt 2021-01-19 14:26:17 +01:00
parent 0523c88bb8
commit 269e38b56e
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
4 changed files with 62 additions and 40 deletions

View File

@ -14,8 +14,8 @@ ENV BUILD_VERSION="0.0.0"
## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000
ENV BUILD_COMMIT="0000000" ENV BUILD_COMMIT="0000000"
## SET NODE_ENV ## SET NODE_ENV
ENV NODE_ENV=production ENV NODE_ENV="production"
## App Envs ## App relevant Envs
ENV PORT="4000" ENV PORT="4000"
# Labels # Labels
@ -31,20 +31,16 @@ LABEL org.label-schema.version="${VERSION}"
LABEL org.label-schema.schema-version="1.0" LABEL org.label-schema.schema-version="1.0"
LABEL maintainer="devops@ocelot.social" LABEL maintainer="devops@ocelot.social"
# Install Additional Software
## install: git
RUN apk --no-cache add git
# Settings # Settings
EXPOSE ${PORT} EXPOSE ${PORT}
WORKDIR ${DOCKER_WORKDIR}
## Make Workdir ## Make Workdir
RUN mkdir -p ${DOCKER_WORKDIR} RUN mkdir -p ${DOCKER_WORKDIR}
## Additional Software WORKDIR ${DOCKER_WORKDIR}
RUN apk --no-cache add git
## Copy package.json, yarn.lock, .env
COPY package.json yarn.lock ./
COPY .env.template .env
# Run command
CMD ["yarn", "run", "start"]
################################################################################## ##################################################################################
# DEVELOPMENT (Connected to the local environment, to reload on demand) ########## # DEVELOPMENT (Connected to the local environment, to reload on demand) ##########
@ -57,6 +53,12 @@ FROM base as development
# Define Volume for workdir folder on development # Define Volume for workdir folder on development
# VOLUME ${DOCKER_WORKDIR} # VOLUME ${DOCKER_WORKDIR}
# Copy .env template
# COPY .env.template .env
# Run command
CMD ["yarn", "run", "dev"]
################################################################################## ##################################################################################
# BUILD (Does contain all files and is therefore bloated) ######################## # BUILD (Does contain all files and is therefore bloated) ########################
################################################################################## ##################################################################################
@ -69,6 +71,9 @@ RUN yarn install --production=false --frozen-lockfile --non-interactive
# yarn build # yarn build
RUN yarn run build RUN yarn run build
# Copy package.json, yarn.lock
# COPY package.json yarn.lock ./
################################################################################## ##################################################################################
# PRODUCTION (Does contain only "binary"- and static-files to reduce image size) # # PRODUCTION (Does contain only "binary"- and static-files to reduce image size) #
################################################################################## ##################################################################################
@ -81,4 +86,7 @@ COPY --from=build ${DOCKER_WORKDIR}/dist ./dist
COPY ./public/img/ ./public/img/ COPY ./public/img/ ./public/img/
COPY ./public/providers.json ./public/providers.json COPY ./public/providers.json ./public/providers.json
# yarn install # yarn install
RUN yarn install --production=true --frozen-lockfile --non-interactive --no-cache RUN yarn install --production=true --frozen-lockfile --non-interactive --no-cache
# Run command
CMD ["yarn", "run", "start"]

View File

@ -16,22 +16,15 @@ services:
backend: backend:
image: ocelotsocialnetwork/develop-backend:development image: ocelotsocialnetwork/develop-backend:development
build: build:
context: ./backend
target: development target: development
command: yarn run dev
environment: environment:
- SMTP_HOST=mailserver - NODE_ENV="development"
- SMTP_PORT=25 - DEBUG=true
- SMTP_IGNORE_TLS=true
- "DEBUG=${DEBUG}"
- PUBLIC_REGISTRATION=false
volumes: volumes:
- ./backend:/app - ./backend:/app
- backend_node_modules:/app/node_modules #neo4j:
- uploads:/app/public/uploads # volumes:
neo4j: # - neo4j_data:/data
volumes:
- neo4j_data:/data
maintenance: maintenance:
image: ocelotsocialnetwork/develop-maintenance:latest image: ocelotsocialnetwork/develop-maintenance:latest
build: build:

View File

@ -8,8 +8,9 @@ services:
args: args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}" - "BUILD_COMMIT=${TRAVIS_COMMIT}"
backend: backend:
image: ocelotsocialnetwork/backend:latest
build: build:
context: backend context: ./backend
target: production target: production
args: args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}" - "BUILD_COMMIT=${TRAVIS_COMMIT}"

View File

@ -1,6 +1,14 @@
# This file defines the production settings. It is overwritten by docker-compose.override.yml,
# which defines the development settings. The override.yml is loaded by default. Therefore it
# is required to explicitly define if you want an production build:
# > docker-compose -f docker-compose.yml up
version: "3.4" version: "3.4"
services: services:
########################################################
# FRONTEND #############################################
########################################################
webapp: webapp:
image: ocelotsocialnetwork/develop-webapp:latest image: ocelotsocialnetwork/develop-webapp:latest
build: build:
@ -22,13 +30,15 @@ services:
- HOST=0.0.0.0 - HOST=0.0.0.0
- GRAPHQL_URI=http://backend:4000 - GRAPHQL_URI=http://backend:4000
- MAPBOX_TOKEN="pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g" - MAPBOX_TOKEN="pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g"
########################################################
# BACKEND ##############################################
########################################################
backend: backend:
image: ocelotsocialnetwork/develop-backend:latest image: ocelotsocialnetwork/backend:latest
build: build:
context: backend context: ./backend
target: production target: production
args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}"
networks: networks:
- hc-network - hc-network
depends_on: depends_on:
@ -36,24 +46,34 @@ services:
ports: ports:
- 4000:4000 - 4000:4000
volumes: volumes:
- ./backend:/app # This makes sure the docker container has its own node modules.
# Therefore it is possible to have a different node version on the host machine
- backend_node_modules:/app/node_modules - backend_node_modules:/app/node_modules
- uploads:/app/public/uploads - uploads:/app/public/uploads
environment: environment:
# Envs used in Dockerfile
# - DOCKER_WORKDIR="/app"
- BUILD_DATE
- BUILD_VERSION
- BUILD_COMMIT
- NODE_ENV="development"
- PORT
# Application only envs
- DEBUG=false
- NEO4J_URI=bolt://neo4j:7687 - NEO4J_URI=bolt://neo4j:7687
- GRAPHQL_URI=http://localhost:4000 - GRAPHQL_URI=http://backend:4000
- CLIENT_URI=http://localhost:3000 - CLIENT_URI=http://webapp:3000
- JWT_SECRET=b/&&7b78BF&fv/Vd env_file:
- MAPBOX_TOKEN=pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g - ./backend/.env
- PRIVATE_KEY_PASSPHRASE=a7dsf78sadg87ad87sfagsadg78
- "DEBUG=${DEBUG}" ########################################################
- EMAIL_DEFAULT_SENDER=devops@ocelot.social # Neo4J ################################################
########################################################
neo4j: neo4j:
image: ocelotsocialnetwork/develop-neo4j:latest image: ocelotsocialnetwork/develop-neo4j:latest
build: build:
context: neo4j context: ./neo4j
args:
- "BUILD_COMMIT=${TRAVIS_COMMIT}"
networks: networks:
- hc-network - hc-network
environment: environment: