Skip to content

Commit

Permalink
Merge pull request #1563 from serlo/dry-dockerfile
Browse files Browse the repository at this point in the history
refactor(docker): use just one Dockerfile building with params
  • Loading branch information
hugotiburtino authored Jun 10, 2024
2 parents dad3817 + ffa978f commit 8f89d33
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 37 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ jobs:
fail-fast: false
matrix:
image: [server, swr-queue-worker]
include:
- image: server
dockerfile: packages/server/docker/server/Dockerfile
- image: swr-queue-worker
dockerfile: packages/server/docker/swr-queue-worker/Dockerfile
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
Expand All @@ -24,7 +19,9 @@ jobs:
with:
push: false
load: true
file: ${{ matrix.dockerfile }}
file: packages/server/Dockerfile
build-args: |
image=${{ matrix.image }}
tags: api-${{ matrix.image }}-local-build:latest
- uses: serlo/configure-repositories/actions/setup-node@main
- name: Start containers
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"deploy:images:staging": "lerna run --stream deploy:image:staging --",
"deploy:images:production": "lerna run --stream deploy:image:production --",
"docker:build": "run-s \"docker:build:*\"",
"docker:build:server": "docker build -f packages/server/docker/server/Dockerfile -t api-server-local-build:latest .",
"docker:build:swr-queue-worker": "docker build -f packages/server/docker/swr-queue-worker/Dockerfile -t api-swr-queue-worker-local-build:latest .",
"docker:build:server": "docker build -f packages/server/Dockerfile -t api-server-local-build:latest --build-arg image=server .",
"docker:build:swr-queue-worker": "docker build -f packages/server/Dockerfile -t api-swr-queue-worker-local-build:latest --build-arg image=swr-queue-worker .",
"docker:rm": "run-p --continue-on-error --print-label \"docker:rm:*\" ",
"docker:rm:server": "docker image rm api-server-local-build",
"docker:rm:swr-queue-worker": "docker image rm api-swr-queue-worker-local-build",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM node:20 as base
ARG image
WORKDIR /usr/src/app
COPY .yarn .yarn
COPY .yarnrc.yml .
Expand All @@ -14,14 +15,16 @@ FROM base as build_dist
RUN yarn --immutable --immutable-cache --silent
COPY packages/authorization packages/authorization
COPY packages/server packages/server
RUN yarn build:server
RUN yarn build:${image}

FROM base as build_node_modules
RUN yarn workspaces focus @serlo/api.serlo.org --production

FROM node:20-alpine as release
ARG image
WORKDIR /usr/src/app
COPY --from=build_dist /usr/src/app/dist dist
COPY --from=build_node_modules /usr/src/app/node_modules node_modules
ENTRYPOINT ["node", "dist/server.cjs"]
RUN cp dist/${image}.cjs dist/entrypoint.cjs 2>/dev/null
ENTRYPOINT ["node", "dist/entrypoint.cjs"]
EXPOSE 3000
27 changes: 0 additions & 27 deletions packages/server/docker/swr-queue-worker/Dockerfile

This file was deleted.

0 comments on commit 8f89d33

Please sign in to comment.