diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 17b47e856255..dfb6ed3b5d7b 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: @@ -23,43 +30,34 @@ jobs: with: fetch-depth: 0 - - name: Prepare - id: prep - run: | - DOCKER_IMAGE=interchainio/simapp - 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 ::set-output name=version::${VERSION} - echo ::set-output name=tags::${TAGS} - echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + - 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=latest-{{major}}.{{minor}} + flavor: | + latest=false - 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 }} + tags: ${{ steps.meta.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max 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