From 26bd4ff33c312a1e932af38bf85d2c566936d967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolas=20G=C3=B6rlitz?= Date: Thu, 11 Apr 2024 15:27:04 +0200 Subject: [PATCH] split into two packages --- .docker/default.conf | 6 +----- .docker/entry.sh | 4 +--- .github/workflows/dev.yml | 28 +++++++++++++++++++++++++--- Dockerfile => backend.Dockerfile | 8 +++----- frontend.Dockerfile | 26 ++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 16 deletions(-) rename Dockerfile => backend.Dockerfile (74%) create mode 100644 frontend.Dockerfile diff --git a/.docker/default.conf b/.docker/default.conf index a9b06d0..5ab3c4e 100644 --- a/.docker/default.conf +++ b/.docker/default.conf @@ -7,11 +7,7 @@ server { gzip_proxied no-cache no-store private expired auth; gzip_types text/plain text/css application/javascript; - location /api/v1 { - proxy_pass http://localhost:8001; - } - - root /opt/frontend; + root /opt; location / { try_files $uri $uri/ /index.html; } diff --git a/.docker/entry.sh b/.docker/entry.sh index 0cf10cb..4c0e114 100644 --- a/.docker/entry.sh +++ b/.docker/entry.sh @@ -1,6 +1,4 @@ #!/bin/sh -nginx - # Run Node -cd /opt/backend && node src/Application.js \ No newline at end of file +cd /opt && node src/Application.js \ No newline at end of file diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 7c75623..a6d90c5 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -9,7 +9,7 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build-and-push-image: + build-backend: runs-on: ubuntu-latest permissions: contents: read @@ -28,5 +28,27 @@ jobs: - name: Build and push Docker image run: | - docker build --pull -t ${{ env.REGISTRY }}/${{ github.repository }}:latest . - docker push ${{ env.REGISTRY }}/${{ github.repository }}:latest \ No newline at end of file + docker build --pull -t ${{ env.REGISTRY }}/${{ github.repository }}-backend:latest -f backend.Dockerfile . + docker push ${{ env.REGISTRY }}/${{ github.repository }}-backend:latest + + build-frontend: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + run: | + docker build --pull -t ${{ env.REGISTRY }}/${{ github.repository }}-frontend:latest -f frontend.Dockerfile . + docker push ${{ env.REGISTRY }}/${{ github.repository }}-frontend:latest \ No newline at end of file diff --git a/Dockerfile b/backend.Dockerfile similarity index 74% rename from Dockerfile rename to backend.Dockerfile index 1ca937e..ea2e89e 100644 --- a/Dockerfile +++ b/backend.Dockerfile @@ -4,10 +4,10 @@ WORKDIR /build COPY package*.json ./ RUN npm install && npm install typescript -g COPY . . -RUN npm run all:build +RUN npm run backend:build -FROM nginx:alpine +FROM node:alpine WORKDIR /opt @@ -16,9 +16,7 @@ COPY package*.json ./ RUN apk update && apk add --update nodejs npm RUN npm install --quiet --unsafe-perm --no-progress --no-audit -COPY --from=build /build/_build/ /opt/ - -COPY .docker/default.conf /etc/nginx/conf.d/default.conf +COPY --from=build /build/_build/backend /opt/ # Init cron ADD .docker/entry.sh /entry.sh diff --git a/frontend.Dockerfile b/frontend.Dockerfile new file mode 100644 index 0000000..fa61e71 --- /dev/null +++ b/frontend.Dockerfile @@ -0,0 +1,26 @@ +FROM node:alpine as build + +WORKDIR /build +COPY package*.json ./ +RUN npm install && npm install typescript -g +COPY . . +RUN npm run frontend:build + + +FROM nginx:alpine + +WORKDIR /opt + +COPY package*.json ./ + +RUN apk update && apk add --update nodejs npm +RUN npm install --quiet --unsafe-perm --no-progress --no-audit + +COPY --from=build /build/_build/frontend /opt/ + +COPY .docker/default.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 +STOPSIGNAL SIGQUIT + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file