From 7006d5037b1131340fe4910e3400f848c81a284c Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Wed, 23 Nov 2022 16:17:30 +0100 Subject: [PATCH 1/6] publish to ghcr --- .github/workflows/docker.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 17b47e856255..291f69127911 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,6 +14,13 @@ on: permissions: contents: read + packages: write + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} jobs: build: @@ -47,19 +54,19 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Login to DockerHub + - name: Log into registry ${{ env.REGISTRY }} if: ${{ github.event_name != 'pull_request' }} uses: docker/login-action@v2 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Publish to Docker Hub + - name: Publish to GitHub Packages uses: docker/build-push-action@v3 with: platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.prep.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max From 90830d7e5978bd852f6204569001ee8e77db5632 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Wed, 23 Nov 2022 16:27:52 +0100 Subject: [PATCH 2/6] build for target os and arch --- Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 84a7393ea36d..fff99095d41a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ # > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys add foo # > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys list # TODO: demo connecting rest-server (or is this in server now?) -FROM golang:1.19-alpine AS build-env +FROM --platform=$BUILDPLATFORM golang:1.19-alpine AS build-env # Install minimum necessary dependencies ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 @@ -22,8 +22,12 @@ WORKDIR /go/src/github.com/cosmos/cosmos-sdk # Add source files COPY . . +# Dockerfile Cross-Compilation Guide +# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide +ARG TARGETOS TARGETARCH + # install simapp, remove packages -RUN make build +RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build # Final image From 36e2875793ed409ed2276fc9d80888ba7a583589 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Wed, 23 Nov 2022 16:23:06 +0100 Subject: [PATCH 3/6] replace deprecated set-output --- .github/workflows/docker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 291f69127911..5f679c2bb894 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -47,9 +47,9 @@ jobs: if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}" fi - echo ::set-output name=version::${VERSION} - echo ::set-output name=tags::${TAGS} - echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "tags=${TAGS}" >> $GITHUB_OUTPUT + echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 From fc7277b2bcad41467c9b8845e10fdfe539c84d96 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Wed, 23 Nov 2022 18:03:48 +0100 Subject: [PATCH 4/6] fix insufficient scope error --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5f679c2bb894..1ce93c202034 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -33,7 +33,7 @@ jobs: - name: Prepare id: prep run: | - DOCKER_IMAGE=interchainio/simapp + DOCKER_IMAGE=${REGISTRY}/${IMAGE_NAME} VERSION=noop if [[ $GITHUB_REF == refs/tags/* ]]; then VERSION=${GITHUB_REF#refs/tags/} From 2e4b256bd1df3887385b91267f3988275bf6e4a2 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Wed, 23 Nov 2022 18:38:14 +0100 Subject: [PATCH 5/6] replace old code with docker metadata action --- .github/workflows/docker.yml | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1ce93c202034..26023ac8bc49 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,26 +30,15 @@ jobs: with: fetch-depth: 0 - - name: Prepare - id: prep - run: | - DOCKER_IMAGE=${REGISTRY}/${IMAGE_NAME} - VERSION=noop - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION=${GITHUB_REF#refs/tags/} - elif [[ $GITHUB_REF == refs/heads/* ]]; then - VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') - if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then - VERSION=latest - fi - fi - TAGS="${DOCKER_IMAGE}:${VERSION}" - if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}" - fi - echo "version=${VERSION}" >> $GITHUB_OUTPUT - echo "tags=${TAGS}" >> $GITHUB_OUTPUT - echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -67,6 +56,6 @@ jobs: with: platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.prep.outputs.tags }} + tags: ${{ steps.meta.outputs.tags }} cache-from: type=gha cache-to: type=gha,mode=max From c1a6da0bd967e4104175ef9b01cb83f19f6093d3 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Wed, 23 Nov 2022 19:04:34 +0100 Subject: [PATCH 6/6] disable default latest --- .github/workflows/docker.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 26023ac8bc49..dfb6ed3b5d7b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -38,7 +38,9 @@ jobs: tags: | type=raw,value=latest,enable={{is_default_branch}} type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} + type=semver,pattern=latest-{{major}}.{{minor}} + flavor: | + latest=false - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2