From cd739f56f5bff92375f4c18ade24e919bd07b56c Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 21 Jan 2025 12:09:59 +0100 Subject: [PATCH] fix docker --- .dockerignore | 3 +++ .github/workflows/test_admin_interface.yml | 2 +- admin/Dockerfile | 15 ++++++++++++--- config/.gitignore | 14 ++++++++++++++ docker-compose.test.yml | 14 +++++++------- docker-compose.yml | 6 ++++-- frontend/Dockerfile | 15 +++++++++++++-- 7 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 .dockerignore create mode 100644 config/.gitignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..01c8b1b48 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +**/node_modules +**/build +**/coverage \ No newline at end of file diff --git a/.github/workflows/test_admin_interface.yml b/.github/workflows/test_admin_interface.yml index 160c819d2..9fc71be70 100644 --- a/.github/workflows/test_admin_interface.yml +++ b/.github/workflows/test_admin_interface.yml @@ -33,7 +33,7 @@ jobs: uses: actions/checkout@v3 - name: Admin Interface | Build 'test' image - run: docker build --target test -t "gradido/admin:test" admin/ --build-arg NODE_ENV="test" + run: docker compose -f docker-compose.yml -f docker-compose.test.yml up --no-deps admin unit_test: if: needs.files-changed.outputs.admin == 'true' diff --git a/admin/Dockerfile b/admin/Dockerfile index 2c90774bb..d0db3910c 100644 --- a/admin/Dockerfile +++ b/admin/Dockerfile @@ -42,6 +42,8 @@ EXPOSE ${PORT} RUN mkdir -p ${DOCKER_WORKDIR} WORKDIR ${DOCKER_WORKDIR} +RUN mkdir -p /config + ################################################################################## # DEVELOPMENT (Connected to the local environment, to reload on demand) ########## ################################################################################## @@ -53,7 +55,7 @@ FROM base as development # Run command # (for development we need to execute yarn install since the # node_modules are on another volume and need updating) -CMD /bin/sh -c "yarn install && yarn run dev" +CMD /bin/sh -c "cd /config && yarn install && yarn build && cd /app && yarn install && yarn run dev" ################################################################################## # BUILD (Does contain all files and is therefore bloated) ######################## @@ -61,9 +63,15 @@ CMD /bin/sh -c "yarn install && yarn run dev" FROM base as build # Copy everything -COPY . . -# yarn install +COPY ./admin/ . +# Copy everything from config +COPY ./config/ ../config/ + +# yarn install admin RUN yarn install --production=false --frozen-lockfile --non-interactive +# yarn install config +RUN cd ../config && yarn install --production=false --frozen-lockfile --non-interactive +RUN cd ../config && yarn build # yarn build RUN yarn run build @@ -85,6 +93,7 @@ FROM base as production # Copy "binary"-files from build image COPY --from=build ${DOCKER_WORKDIR}/build ./build +COPY --from=build ${DOCKER_WORKDIR}/../config/build ../config/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 diff --git a/config/.gitignore b/config/.gitignore new file mode 100644 index 000000000..ce6695205 --- /dev/null +++ b/config/.gitignore @@ -0,0 +1,14 @@ +node_modules/ +build/ +.cache/ +.yarn/install-state.gz + +/.env +/.env.bak + +# coverage folder +coverage/ + +# emacs +*~ + diff --git a/docker-compose.test.yml b/docker-compose.test.yml index fba2715bd..de631ed15 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -7,7 +7,7 @@ services: build: target: test environment: - - NODE_ENV="test" + - NODE_ENV=test ######################################################## # ADMIN INTERFACE ###################################### @@ -17,7 +17,7 @@ services: build: target: test environment: - - NODE_ENV="test" + - NODE_ENV=test ######################################################## # BACKEND ############################################## @@ -31,7 +31,7 @@ services: - external-net - internal-net environment: - - NODE_ENV="test" + - NODE_ENV=test - DB_HOST=mariadb ######################################################## @@ -46,7 +46,7 @@ services: - external-net - internal-net environment: - - NODE_ENV="test" + - NODE_ENV="test - DB_HOST=mariadb ######################################################## @@ -61,7 +61,7 @@ services: - external-net - internal-net environment: - - NODE_ENV="test" + - NODE_ENV=test - DB_HOST=mariadb ######################################################## @@ -73,7 +73,7 @@ services: context: ./database target: test_up environment: - - NODE_ENV="test" + - NODE_ENV=test # restart: always # this is very dangerous, but worth a test for the delayed mariadb startup at first run ######################################################## @@ -85,7 +85,7 @@ services: context: ./dlt-database target: test_up environment: - - NODE_ENV="test" + - NODE_ENV=test # restart: always # this is very dangerous, but worth a test for the delayed mariadb startup at first run ######################################################### diff --git a/docker-compose.yml b/docker-compose.yml index e35ff1baf..372877bf1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,8 @@ services: # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there image: gradido/frontend:local-production build: - context: ./frontend + context: ./ + dockerfile: ./frontend/Dockerfile target: production networks: - external-net @@ -40,7 +41,8 @@ services: # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there image: gradido/admin:local-production build: - context: ./admin + context: ./ + dockerfile: ./admin/Dockerfile target: production networks: - external-net diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 04dceb6f5..e2d3239e6 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -42,6 +42,8 @@ EXPOSE ${PORT} RUN mkdir -p ${DOCKER_WORKDIR} WORKDIR ${DOCKER_WORKDIR} +RUN mkdir -p /config + ################################################################################## # DEVELOPMENT (Connected to the local environment, to reload on demand) ########## ################################################################################## @@ -53,7 +55,7 @@ FROM base as development # 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 && yarn run dev" +CMD /bin/sh -c "cd /config && yarn install && yarn build && cd /app && yarn install && yarn run dev" ################################################################################## # BUILD (Does contain all files and is therefore bloated) ######################## @@ -61,9 +63,17 @@ CMD /bin/sh -c "yarn install && yarn run dev" FROM base as build # Copy everything -COPY . . +COPY ./frontend ./ + +# Copy everything from config +COPY ./config/ ../config/ + # npm install RUN yarn global add node-gyp && yarn install --production=false --frozen-lockfile --non-interactive + +# install and build config +RUN cd ../config && yarn install --production=false --frozen-lockfile --non-interactive +RUN cd ../config && yarn build # npm build RUN yarn run build @@ -85,6 +95,7 @@ FROM base as production # Copy "binary"-files from build image COPY --from=build ${DOCKER_WORKDIR}/build ./build +COPY --from=build ${DOCKER_WORKDIR}/../config/build ../config/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