From b4654a4bf34cf8140c8fc7ebc4963386dbdb2c06 Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:00:05 +0200 Subject: [PATCH 1/2] fix: use docker buildx on ci to support multiple platforms Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- .github/workflows/docker.yml | 99 ++++++++++++++++++------------------ Dockerfile | 1 + 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f2d1896a61c..fe0c068fbc2 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,69 +14,70 @@ concurrency: cancel-in-progress: true jobs: - build-push: + build-main: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Build main Docker image - env: - owner: ${{ github.repository_owner }} - reponame: ${{ github.event.repository.name }} - run: | - docker build -t ghcr.io/${owner}/${reponame} . - docker tag ghcr.io/${owner}/${reponame}:latest ghcr.io/${owner}/${reponame}:${GITHUB_SHA::8} + - name: Get commit SHA + id: commit + run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT" - - name: Build slim Docker images - env: - owner: ${{ github.repository_owner }} - reponame: ${{ github.event.repository.name }} - run: | - docker build --target=gnoland-slim -t ghcr.io/${owner}/${reponame}/gnoland-slim . - docker build --target=gnokey-slim -t ghcr.io/${owner}/${reponame}/gnokey-slim . - docker build --target=gno-slim -t ghcr.io/${owner}/${reponame}/gno-slim . - docker build --target=gnofaucet-slim -t ghcr.io/${owner}/${reponame}/gnofaucet-slim . - docker build --target=gnoweb-slim -t ghcr.io/${owner}/${reponame}/gnoweb-slim . + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - docker tag ghcr.io/${owner}/${reponame}/gnoland-slim:latest ghcr.io/${owner}/${reponame}/gnoland-slim:${GITHUB_SHA::8} - docker tag ghcr.io/${owner}/${reponame}/gnokey-slim:latest ghcr.io/${owner}/${reponame}/gnokey-slim:${GITHUB_SHA::8} - docker tag ghcr.io/${owner}/${reponame}/gno-slim:latest ghcr.io/${owner}/${reponame}/gno-slim:${GITHUB_SHA::8} - docker tag ghcr.io/${owner}/${reponame}/gnofaucet-slim:latest ghcr.io/${owner}/${reponame}/gnofaucet-slim:${GITHUB_SHA::8} - docker tag ghcr.io/${owner}/${reponame}/gnoweb-slim:latest ghcr.io/${owner}/${reponame}/gnoweb-slim:${GITHUB_SHA::8} - - - name: List docker images - run: | - docker images | grep ghcr - - - name: Log in to GitHub Container Registry - if: (github.event_name != 'pull_request') + - name: Login to GitHub Container Registry uses: docker/login-action@v3 + if: (github.event_name != 'pull_request') with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: | + ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest + ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.commit.outputs.sha }} - - name: Publish images - if: (github.event_name != 'pull_request') - env: - owner: ${{ github.repository_owner }} - reponame: ${{ github.event.repository.name }} - run: | - docker push ghcr.io/${owner}/${reponame}:latest - docker push ghcr.io/${owner}/${reponame}:${GITHUB_SHA::8} - - docker push ghcr.io/${owner}/${reponame}/gnoland-slim:latest - docker push ghcr.io/${owner}/${reponame}/gnoland-slim:${GITHUB_SHA::8} + build-slim: + runs-on: ubuntu-latest + strategy: + matrix: + target: [gnoland, gnoland-slim, gnokey-slim, gno-slim, gnofaucet-slim, gnoweb-slim] + steps: + - name: Checkout + uses: actions/checkout@v4 - docker push ghcr.io/${owner}/${reponame}/gnokey-slim:latest - docker push ghcr.io/${owner}/${reponame}/gnokey-slim:${GITHUB_SHA::8} + - name: Get commit SHA + id: commit + run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT" - docker push ghcr.io/${owner}/${reponame}/gno-slim:latest - docker push ghcr.io/${owner}/${reponame}/gno-slim:${GITHUB_SHA::8} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - docker push ghcr.io/${owner}/${reponame}/gnofaucet-slim:latest - docker push ghcr.io/${owner}/${reponame}/gnofaucet-slim:${GITHUB_SHA::8} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - docker push ghcr.io/${owner}/${reponame}/gnoweb-slim:latest - docker push ghcr.io/${owner}/${reponame}/gnoweb-slim:${GITHUB_SHA::8} + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + if: (github.event_name != 'pull_request') + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: | + ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.target }}:latest + ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.target }}:${{ steps.commit.outputs.sha }} diff --git a/Dockerfile b/Dockerfile index d55771e904d..2bd156e305b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ WORKDIR /opt/build ADD go.mod go.sum ./ RUN go mod download ADD . ./ +ENV CGO_ENABLED=0 RUN go build -o ./build/gnoland ./gno.land/cmd/gnoland RUN go build -o ./build/gnokey ./gno.land/cmd/gnokey RUN go build -o ./build/gnofaucet ./gno.land/cmd/gnofaucet From 3461319a459dc442390af9c57447a5bfb449e9f4 Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:15:27 +0200 Subject: [PATCH 2/2] chore: remove useless CGO_ENABLED env Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2bd156e305b..d55771e904d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ WORKDIR /opt/build ADD go.mod go.sum ./ RUN go mod download ADD . ./ -ENV CGO_ENABLED=0 RUN go build -o ./build/gnoland ./gno.land/cmd/gnoland RUN go build -o ./build/gnokey ./gno.land/cmd/gnokey RUN go build -o ./build/gnofaucet ./gno.land/cmd/gnofaucet