From a410e6c2e72a28fe96cf22428221f78645ba8026 Mon Sep 17 00:00:00 2001 From: Simon Ding Date: Mon, 22 Jul 2024 15:18:54 +0800 Subject: [PATCH] feat: seprate ci build --- .github/workflows/go.yml | 8 ++--- .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++++++ Dockerfile | 2 +- 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cddddbe..4e65c2e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,8 +5,6 @@ on: push: branches: - 'main' - tags: - - 'v*' pull_request: branches: - 'main' @@ -42,14 +40,12 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: context: . file: Dockerfile push: true - platforms: | - linux/amd64 - linux/arm64 + platforms: linux/amd64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a16e526 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: build + +on: + workflow_dispatch: + push: + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + + build-and-push-image: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set Up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set Up Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to image repository + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GHCR_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + push: true + platforms: | + linux/amd64 + linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/Dockerfile b/Dockerfile index 848dc0d..7732c28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ COPY . . COPY --from=flutter /app/build/web ./ui/build/web/ # 指定OS等,并go build -RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o polaris ./cmd/ +RUN CGO_ENABLED=1 go build -o polaris ./cmd/ FROM debian:12