properly bind database volumes, make database directories in container and copy required node_modules folders for production

This commit is contained in:
Ulf Gebhardt 2021-10-12 01:28:32 +02:00
parent b68ab27ed1
commit d8e3db5b0f
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
2 changed files with 10 additions and 3 deletions

View File

@ -42,6 +42,8 @@ EXPOSE ${PORT}
RUN mkdir -p ${DOCKER_WORKDIR} RUN mkdir -p ${DOCKER_WORKDIR}
WORKDIR ${DOCKER_WORKDIR} WORKDIR ${DOCKER_WORKDIR}
RUN mkdir -p /database
################################################################################## ##################################################################################
# DEVELOPMENT (Connected to the local environment, to reload on demand) ########## # DEVELOPMENT (Connected to the local environment, to reload on demand) ##########
################################################################################## ##################################################################################
@ -51,9 +53,9 @@ FROM base as development
# local filesystem which will need a rebuild anyway # local filesystem which will need a rebuild anyway
# Run command # Run command
# (for development we need to execute npm install since the # (for development we need to execute yarn install since the
# node_modules are on another volume and need updating) # node_modules are on another volume and need updating)
CMD /bin/sh -c "yarn install && yarn run dev" CMD /bin/sh -c "cd /database && yarn install && cd /app && yarn install && yarn run dev"
################################################################################## ##################################################################################
# BUILD (Does contain all files and is therefore bloated) ######################## # BUILD (Does contain all files and is therefore bloated) ########################
@ -89,8 +91,10 @@ FROM base as production
# Copy "binary"-files from build image # Copy "binary"-files from build image
COPY --from=build ${DOCKER_WORKDIR}/build ./build COPY --from=build ${DOCKER_WORKDIR}/build ./build
COPY --from=build ${DOCKER_WORKDIR}/../database/build ../database/build
# We also copy the node_modules express and serve-static for the run script # We also copy the node_modules express and serve-static for the run script
# COPY --from=build ${DOCKER_WORKDIR}/node_modules ./node_modules COPY --from=build ${DOCKER_WORKDIR}/node_modules ./node_modules
COPY --from=build ${DOCKER_WORKDIR}/../database/node_modules ../database/node_modules
# Copy static files # Copy static files
# COPY --from=build ${DOCKER_WORKDIR}/public ./public # COPY --from=build ${DOCKER_WORKDIR}/public ./public
# Copy package.json for script definitions (lock file should not be needed) # Copy package.json for script definitions (lock file should not be needed)

View File

@ -36,8 +36,10 @@ services:
# This makes sure the docker container has its own node modules. # 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 # 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
- backend_database_node_modules:/database/node_modules
# bind the local folder to the docker to allow live reload # bind the local folder to the docker to allow live reload
- ./backend:/app - ./backend:/app
- ./database:/database
######################################################## ########################################################
# DATABASE ############################################## # DATABASE ##############################################
@ -152,6 +154,7 @@ services:
volumes: volumes:
frontend_node_modules: frontend_node_modules:
backend_node_modules: backend_node_modules:
backend_database_node_modules:
database_node_modules: database_node_modules:
database_build: database_build:
login_build_ubuntu_3.1: login_build_ubuntu_3.1: