From 47fab7dd2632a292ee0f571609b59c53a9aafab2 Mon Sep 17 00:00:00 2001 From: incubator4 Date: Thu, 1 Feb 2024 14:56:36 +0800 Subject: [PATCH] chore(docker): update multi-arch build image (#152) --- .github/workflows/docker-build.yaml | 59 +++++++++++++++++++++-------- Dockerfile | 15 ++++++-- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 238751db..8a9597bb 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -9,18 +9,47 @@ on: jobs: build: - uses: NaturalSelectionLabs/Daedalus/.github/workflows/docker-tpl.yaml@main - strategy: - fail-fast: false - matrix: - platform: - - linux/amd64 - - linux/arm64 - with: - images: rss3/node - context: . - dockerfile: ./Dockerfile - platforms: ${{ matrix.platform }} - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ secrets.DOCKERHUB_USERNAME }}/node + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + type=ref,event=branch + type=ref,event=pr + type=sha,prefix={{branch}}-,enable=${{ !startsWith(github.ref, 'refs/tags') }},event=branch + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm/v7,linux/arm64 + cache-from: type=gha,scope=docker-release + cache-to: type=gha,mode=max,scope=docker-release \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2339d53e..441c5ca9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,20 @@ -FROM golang:1.21.4-alpine AS builder +FROM golang:1.21.4-alpine AS base WORKDIR /root/node +RUN apk add --no-cache git make gcc libc-dev + +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,source=go.sum,target=go.sum \ + --mount=type=bind,source=go.mod,target=go.mod \ + go mod download -x COPY . . -RUN apk add --no-cache git make gcc libc-dev -RUN CGO_ENABLED=1 make build +FROM base AS builder + +ENV CGO_ENABLED=1 +RUN --mount=type=cache,target=/go/pkg/mod/ \ + make build FROM alpine:3.18.4 AS runner