From 7d5b3cddccbb3eba86af2367d163664d2c8e8ba4 Mon Sep 17 00:00:00 2001 From: kunish Date: Wed, 30 Aug 2023 00:40:47 +0800 Subject: [PATCH] feat: publish docker image --- .dockerignore | 1 + .github/workflows/release.yml | 42 +++++++++++++++++++++++++++++++---- Caddyfile | 7 ++++++ Dockerfile | 19 ++++++++++++++++ 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Caddyfile create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8eae80b..20aac26 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} release-type: node - release: + release-assets: needs: release-please runs-on: ubuntu-latest if: ${{ needs.release-please.outputs.release_created }} @@ -45,13 +45,13 @@ jobs: - name: build for gh-pages run: pnpm build --base /metacubexd - - name: publish github pages + - name: publish gh-pages uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./dist - - name: build for release + - name: build for github release run: pnpm build - name: zip @@ -59,8 +59,42 @@ jobs: zip -r ../dist.zip . working-directory: dist - - name: attach release artifacts + - name: attach github release artifacts uses: softprops/action-gh-release@v1 with: files: dist.zip tag_name: ${{ needs.release-please.outputs.tag_name }} + + release-image: + needs: release-please + runs-on: ubuntu-latest + if: ${{ needs.release-please.outputs.release_created }} + 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 + id: buildx + + - name: login to ghrc.io + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: build and publish ghcr.io docker image + uses: docker/build-push-action@v4 + with: + context: . + builder: ${{ steps.buildx.outputs.name }} + file: Dockerfile + platforms: linux/amd64 + push: true + tags: | + ghcr.io/${{ github.repository }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..4351a05 --- /dev/null +++ b/Caddyfile @@ -0,0 +1,7 @@ +:80 { + file_server + + root * . + + try_files {path} /index.html +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e9dae2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM docker.io/node:alpine as builder + +WORKDIR /build + +COPY . . + +RUN corepack enable +RUN corepack prepare pnpm@latest --activate +RUN pnpm install +RUN pnpm build + +FROM docker.io/caddy:alpine + +WORKDIR /srv + +COPY --from=builder /build/dist/. . +COPY Caddyfile . + +CMD ["caddy", "run"]