From 11a9d945c27433e55cec68fb91f99ea94ed7e43b Mon Sep 17 00:00:00 2001 From: H1ghBre4k3r Date: Sat, 2 Nov 2024 14:34:28 +0100 Subject: [PATCH] chore: add docker configuration and workflow --- .dockerignore | 34 ++++++++++++++++++++++++++++++ .github/workflows/build.yml | 5 +++++ .github/workflows/image.yml | 42 +++++++++++++++++++++++++++++++++++++ Dockerfile | 29 +++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/image.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fd00eaa --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +**/build +**/dist +LICENSE +README.md diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9f00de8..8c8b222 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,3 +27,8 @@ jobs: run: npm run build - name: Lint the project run: npm run lint + + image: + needs: build + uses: ./.github/workflows/image.yml + secrets: inherit diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml new file mode 100644 index 0000000..2cc099f --- /dev/null +++ b/.github/workflows/image.yml @@ -0,0 +1,42 @@ +name: Image + +on: + workflow_call: + +jobs: + publish-docker-image: + name: Build & Publish Docker Image + runs-on: self-hosted + + steps: + - uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + if: ${{ github.ref_name == 'main' }} + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GH_PAT }} + + - name: Set lower case owner name + run: | + echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV} + env: + OWNER: "${{ github.repository_owner }}" + + - name: Build and Push Docker Image + uses: docker/build-push-action@v3 + with: + platforms: linux/amd64,linux/arm64/v8 + context: . + push: ${{ github.ref_name == 'main' }} + tags: | + ghcr.io/${{ env.OWNER_LC }}/kneipolympics:latest + ghcr.io/${{ env.OWNER_LC }}/kneipolympics:${{ github.sha }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5299acc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +ARG NODE_VERSION=20.16.0 + +FROM node:${NODE_VERSION}-alpine as base + +WORKDIR /usr/src/app + +FROM base as deps + +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=package-lock.json,target=package-lock.json \ + --mount=type=cache,target=/root/.npm \ + npm ci --omit=dev + +FROM deps as build + +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=package-lock.json,target=package-lock.json \ + --mount=type=cache,target=/root/.npm \ + npm ci + +COPY . . + +RUN npm run build + +FROM nginx:1.27 as final + +LABEL org.opencontainers.image.source="https://github.com/pesca-dev/kneipolympics" + +COPY --from=build /usr/src/app/dist /usr/share/nginx/html