docker implementation of the migrations service "database"

This commit is contained in:
Ulf Gebhardt 2021-08-23 12:33:09 +02:00
parent 160e0bb6c6
commit 9e29613206
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
3 changed files with 185 additions and 0 deletions

132
database/Dockerfile Normal file
View File

@ -0,0 +1,132 @@
##################################################################################
# BASE ###########################################################################
##################################################################################
FROM node:12.19.0-alpine3.10 as base
# ENVs (available in production aswell, can be overwritten by commandline or env file)
## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame
ENV DOCKER_WORKDIR="/app"
## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0
ENV BUILD_DATE="1970-01-01T00:00:00.00Z"
## We cannot do $(npm run version).${BUILD_NUMBER} here so we default to 0.0.0.0
ENV BUILD_VERSION="0.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 relevant Envs
#ENV PORT="4000"
# Labels
LABEL org.label-schema.build-date="${BUILD_DATE}"
LABEL org.label-schema.name="gradido:database"
LABEL org.label-schema.description="Gradido GraphQL Backend"
LABEL org.label-schema.usage="https://github.com/gradido/gradido/blob/master/README.md"
LABEL org.label-schema.url="https://gradido.net"
LABEL org.label-schema.vcs-url="https://github.com/gradido/gradido/tree/master/database"
LABEL org.label-schema.vcs-ref="${BUILD_COMMIT}"
LABEL org.label-schema.vendor="Gradido Community"
LABEL org.label-schema.version="${BUILD_VERSION}"
LABEL org.label-schema.schema-version="1.0"
LABEL maintainer="support@gradido.net"
# Install Additional Software
## install: git
#RUN apk --no-cache add git
# Settings
## Expose Container Port
# EXPOSE ${PORT}
## Workdir
RUN mkdir -p ${DOCKER_WORKDIR}
WORKDIR ${DOCKER_WORKDIR}
##################################################################################
# DEVELOPMENT (Connected to the local environment, to reload on demand) ##########
##################################################################################
FROM base as development
# We don't need to copy or build anything since we gonna bind to the
# local filesystem which will need a rebuild anyway
# Run command
# (for development we need to execute npm install since the
# node_modules are on another volume and need updating)
CMD /bin/sh -c "yarn install"
##################################################################################
# BUILD (Does contain all files and is therefore bloated) ########################
##################################################################################
FROM base as build
# Copy everything
COPY . .
# npm install
RUN yarn install --production=false --frozen-lockfile --non-interactive
# npm build
RUN yarn run build
##################################################################################
# TEST UP ########################################################################
##################################################################################
FROM build as test_up
# Run command
CMD /bin/sh -c "yarn run dev_up"
##################################################################################
# TEST RESET #####################################################################
##################################################################################
FROM build as test_reset
# Run command
CMD /bin/sh -c "yarn run dev_reset"
##################################################################################
# TEST DOWN ######################################################################
##################################################################################
FROM build as test_down
# Run command
CMD /bin/sh -c "yarn run dev_down"
##################################################################################
# PRODUCTION (Does contain only "binary"- and static-files to reduce image size) #
##################################################################################
FROM base as production
# Copy "binary"-files from build image
COPY --from=build ${DOCKER_WORKDIR}/build ./build
# We also copy the node_modules express and serve-static for the run script
# COPY --from=build ${DOCKER_WORKDIR}/node_modules ./node_modules
# Copy static files
# COPY --from=build ${DOCKER_WORKDIR}/public ./public
# Copy package.json for script definitions (lock file should not be needed)
COPY --from=build ${DOCKER_WORKDIR}/package.json ./package.json
# Copy run scripts run/
# COPY --from=build ${DOCKER_WORKDIR}/run ./run
##################################################################################
# PRODUCTION UP ##################################################################
##################################################################################
FROM production as production_up
# Run command
CMD /bin/sh -c "yarn run up"
##################################################################################
# PRODUCTION RESET ###############################################################
##################################################################################
FROM production as production_reset
# Run command
CMD /bin/sh -c "yarn run reset"
##################################################################################
# PRODUCTION DOWN ################################################################
##################################################################################
FROM production as production_down
# Run command
CMD /bin/sh -c "yarn run down"

View File

@ -1,6 +1,10 @@
version: "3.4"
services:
mariadb:
networks:
- internal-net
- external-net
########################################################
# FRONTEND #############################################
########################################################
@ -40,6 +44,27 @@ services:
# bind the local folder to the docker to allow live reload
- ./backend:/app
########################################################
# DATABASE ##############################################
########################################################
database:
# we always run on prouction here since else the service lingers
# feel free to change this behaviour if it seems useful
#image: gradido/database:test_up
#build:
# target: test_up
#networks:
# - external-net
# - internal-net
environment:
- NODE_ENV="development"
volumes:
# 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
- database_node_modules:/app/node_modules
# bind the local folder to the docker to allow live reload
- ./database:/app
#########################################################
## LOGIN SERVER #########################################
#########################################################
@ -127,4 +152,5 @@ services:
volumes:
frontend_node_modules:
backend_node_modules:
database_node_modules:
login_build_ubuntu_3.1:

View File

@ -73,6 +73,33 @@ services:
#env_file:
# - ./frontend/.env
########################################################
# DATABASE #############################################
########################################################
database:
image: gradido/database:production_up
build:
context: ./database
target: production_up
depends_on:
- mariadb
networks:
- internal-net
#ports:
# - 4000:4000
environment:
# Envs used in Dockerfile
# - DOCKER_WORKDIR="/app"
# - PORT=4000
- BUILD_DATE
- BUILD_VERSION
- BUILD_COMMIT
- NODE_ENV="production"
- DB_HOST=mariadb
# Application only envs
#env_file:
# - ./frontend/.env
#########################################################
## LOGIN SERVER #########################################
#########################################################