From 72ffadc17807e78a8cdc0f8f1b9455f8d3529cb3 Mon Sep 17 00:00:00 2001 From: Takahiro Miyoshi Date: Wed, 6 Nov 2024 16:04:05 +0900 Subject: [PATCH] Enable to build and push clover-ui image --- .github/workflows/client-ui.yml | 49 +++++++++++++++++++++++++++++++++ client-ui/Dockerfile | 33 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 client-ui/Dockerfile diff --git a/.github/workflows/client-ui.yml b/.github/workflows/client-ui.yml index b91cb45..9cee1b8 100644 --- a/.github/workflows/client-ui.yml +++ b/.github/workflows/client-ui.yml @@ -58,3 +58,52 @@ jobs: - run: pnpm install - run: pnpm run typecheck + + build: + name: build {{ github.ref_name == 'main' && 'and push' || '' }} + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + attestations: write + id-token: write + + env: + REGISTRY: ghcr.io + IMAGE_NAME: arkedge/clover-ui + + steps: + - uses: actions/checkout@v4.2.2 + + - uses: docker/setup-buildx-action@v3.7.1 + + - uses: docker/login-action@v3.3.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/metadata-action@v5.5.1 + id: meta + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + tags: | + type=sha + type=raw,value=latest + + - uses: docker/build-push-action@v6.9.0 + id: push + with: + context: ./client-ui + push: ${{ github.ref_name == 'main' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - uses: actions/attest-build-provenance@v1.4.4 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: ${{ github.ref_name == 'main' }} diff --git a/client-ui/Dockerfile b/client-ui/Dockerfile new file mode 100644 index 0000000..57176c9 --- /dev/null +++ b/client-ui/Dockerfile @@ -0,0 +1,33 @@ +FROM node:22-bullseye-slim AS base + +ENV NODE_ENV=production + +RUN corepack enable + +# build stage + +FROM base AS build + +WORKDIR /app + +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile --prod=false + +COPY . . +RUN pnpm run build +RUN pnpm prune --prod + +# runtime stage + +FROM base + +WORKDIR /app + +COPY package.json . +COPY --from=build /app/node_modules /app/node_modules +COPY --from=build /app/build/client /app/build/client +COPY --from=build /app/build/server /app/build/server + +RUN corepack install + +CMD ["pnpm", "start"]