From cf9f07cf9aca42022142ccf33214a8551b992e7c Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sun, 22 Jan 2023 00:29:42 +0800 Subject: [PATCH 1/4] Feat: docker support --- .github/workflows/docker.yml | 69 ++++++++++++++++++++++++++++++++++++ Dockerfile | 29 +++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..7e42259 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,69 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + push: + branches: [ "main" ] + tags: [ 'v*.*.*', 'beta-*.*', 'alpha-*.*', 'v*.*.*-rc*' ] + pull_request: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + 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 new file mode 100644 index 0000000..4d795cf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM node:lts AS deps +WORKDIR ~/app + +# Install dependencies +RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm +COPY package.json package-lock.json ./ +RUN pnpm install --frozen-lockfile + +FROM node:lts AS builder +WORKDIR ~/app + +# Copy dependencies +COPY --from=deps ~/app/node_modules ./node_modules +COPY . . + +# Build +RUN pnpm run build + +FROM nginx:stable-alpine AS runner +WORKDIR ~/app + +# Copy dist +COPY --from=builder ~/app/dist /usr/share/nginx/html + +EXPOSE 80 + +STOPSIGNAL SIGTERM + +CMD ["nginx", "-g", "daemon off;"] From 2c80a0a9f90188de1c2765733ed798a71d0e93d4 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sun, 22 Jan 2023 00:31:23 +0800 Subject: [PATCH 2/4] Able to use workflow dispatch --- .github/workflows/docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7e42259..ac2570b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,6 +11,7 @@ on: tags: [ 'v*.*.*', 'beta-*.*', 'alpha-*.*', 'v*.*.*-rc*' ] pull_request: branches: [ "main" ] + workflow_dispatch: env: # Use docker.io for Docker Hub if empty From e6f6748034a79570b6d0117537ad5de722c89a81 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sun, 22 Jan 2023 00:36:48 +0800 Subject: [PATCH 3/4] Fix: `pnpm-lock.yaml` instead of `package-lock.json` --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4d795cf..2973180 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ WORKDIR ~/app # Install dependencies RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm -COPY package.json package-lock.json ./ +COPY package.json pnpm-lock.yaml ./ RUN pnpm install --frozen-lockfile FROM node:lts AS builder From a4685400e7d3ffa951b8956fffe8423d9e7edba5 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sun, 22 Jan 2023 00:43:05 +0800 Subject: [PATCH 4/4] Fix: download pnpm in builder step --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 2973180..4ad0710 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,7 @@ COPY --from=deps ~/app/node_modules ./node_modules COPY . . # Build +RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm RUN pnpm run build FROM nginx:stable-alpine AS runner