diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..75b93ed --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,54 @@ +name: Release Container Image + +on: + pull_request: + branches: [main] + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + name: Build and push container image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=raw,value=latest,enable=${{ github.event_name == 'push' }} + type=raw,value=pr-${{ github.event.pull_request.number }},enable=${{ github.event_name == 'pull_request' }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 + + - name: Build and push + uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 #v7.0.0 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index aa62764..0c02284 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,14 @@ -# syntax=docker/dockerfile:1.7 +# syntax=docker/dockerfile:1 -FROM node:22-alpine AS builder +ARG DEBIAN_RELEASE_NAME=trixie + +ARG NGINX_VERSION=1.29 +ARG NGINX_IMAGE=nginx:${NGINX_VERSION}-${DEBIAN_RELEASE_NAME} + +ARG NODE_VERSION=22 +ARG NODE_IMAGE=node:${NODE_VERSION}-${DEBIAN_RELEASE_NAME}-slim + +FROM ${NODE_IMAGE} AS builder WORKDIR /app @@ -13,7 +21,10 @@ COPY src ./src RUN npm run build -FROM nginx:1.27-alpine AS runtime +FROM scratch AS static +COPY --from=builder /app/dist /app/dist + +FROM ${NGINX_IMAGE} AS runtime COPY nginx.conf /etc/nginx/conf.d/default.conf COPY env.template.js /usr/share/nginx/html/config.template.js