From 269e38b56ecad8e7e30fc6dbabcdc99e18d9d241 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 19 Jan 2021 14:26:17 +0100 Subject: [PATCH] backend dockerfile and compose seem to be pretty solid now --- backend/Dockerfile | 32 +++++++++++++--------- docker-compose.override.yml | 17 ++++-------- docker-compose.production.yml | 3 ++- docker-compose.yml | 50 ++++++++++++++++++++++++----------- 4 files changed, 62 insertions(+), 40 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 8640c3ff8..7097b7486 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -14,8 +14,8 @@ ENV BUILD_VERSION="0.0.0" ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 ENV BUILD_COMMIT="0000000" ## SET NODE_ENV -ENV NODE_ENV=production -## App Envs +ENV NODE_ENV="production" +## App relevant Envs ENV PORT="4000" # Labels @@ -31,20 +31,16 @@ LABEL org.label-schema.version="${VERSION}" LABEL org.label-schema.schema-version="1.0" LABEL maintainer="devops@ocelot.social" +# Install Additional Software +## install: git +RUN apk --no-cache add git + # Settings EXPOSE ${PORT} -WORKDIR ${DOCKER_WORKDIR} ## Make Workdir RUN mkdir -p ${DOCKER_WORKDIR} -## Additional Software -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"] +WORKDIR ${DOCKER_WORKDIR} ################################################################################## # 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 # 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) ######################## ################################################################################## @@ -69,6 +71,9 @@ RUN yarn install --production=false --frozen-lockfile --non-interactive # yarn 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) # ################################################################################## @@ -81,4 +86,7 @@ COPY --from=build ${DOCKER_WORKDIR}/dist ./dist COPY ./public/img/ ./public/img/ COPY ./public/providers.json ./public/providers.json # yarn install -RUN yarn install --production=true --frozen-lockfile --non-interactive --no-cache \ No newline at end of file +RUN yarn install --production=true --frozen-lockfile --non-interactive --no-cache + +# Run command +CMD ["yarn", "run", "start"] \ No newline at end of file diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 03ef42ee1..3289be2e8 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -16,22 +16,15 @@ services: backend: image: ocelotsocialnetwork/develop-backend:development build: - context: ./backend target: development - command: yarn run dev environment: - - SMTP_HOST=mailserver - - SMTP_PORT=25 - - SMTP_IGNORE_TLS=true - - "DEBUG=${DEBUG}" - - PUBLIC_REGISTRATION=false + - NODE_ENV="development" + - DEBUG=true volumes: - ./backend:/app - - backend_node_modules:/app/node_modules - - uploads:/app/public/uploads - neo4j: - volumes: - - neo4j_data:/data + #neo4j: + # volumes: + # - neo4j_data:/data maintenance: image: ocelotsocialnetwork/develop-maintenance:latest build: diff --git a/docker-compose.production.yml b/docker-compose.production.yml index 285e9f110..0eec3126c 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -8,8 +8,9 @@ services: args: - "BUILD_COMMIT=${TRAVIS_COMMIT}" backend: + image: ocelotsocialnetwork/backend:latest build: - context: backend + context: ./backend target: production args: - "BUILD_COMMIT=${TRAVIS_COMMIT}" diff --git a/docker-compose.yml b/docker-compose.yml index f90dadb0e..3812fdf7d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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" services: + ######################################################## + # FRONTEND ############################################# + ######################################################## webapp: image: ocelotsocialnetwork/develop-webapp:latest build: @@ -22,13 +30,15 @@ services: - HOST=0.0.0.0 - GRAPHQL_URI=http://backend:4000 - MAPBOX_TOKEN="pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g" + + ######################################################## + # BACKEND ############################################## + ######################################################## backend: - image: ocelotsocialnetwork/develop-backend:latest + image: ocelotsocialnetwork/backend:latest build: - context: backend + context: ./backend target: production - args: - - "BUILD_COMMIT=${TRAVIS_COMMIT}" networks: - hc-network depends_on: @@ -36,24 +46,34 @@ services: ports: - 4000:4000 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 - uploads:/app/public/uploads 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 - - GRAPHQL_URI=http://localhost:4000 - - CLIENT_URI=http://localhost:3000 - - JWT_SECRET=b/&&7b78BF&fv/Vd - - MAPBOX_TOKEN=pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g - - PRIVATE_KEY_PASSPHRASE=a7dsf78sadg87ad87sfagsadg78 - - "DEBUG=${DEBUG}" - - EMAIL_DEFAULT_SENDER=devops@ocelot.social + - GRAPHQL_URI=http://backend:4000 + - CLIENT_URI=http://webapp:3000 + env_file: + - ./backend/.env + + ######################################################## + # Neo4J ################################################ + ######################################################## neo4j: image: ocelotsocialnetwork/develop-neo4j:latest build: - context: neo4j - args: - - "BUILD_COMMIT=${TRAVIS_COMMIT}" + context: ./neo4j networks: - hc-network environment: