From df806e31d34bb342f6f1ffab6337d808047b070d Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 9 Oct 2023 15:26:42 +0200 Subject: [PATCH] Attempt to get docker builds going --- .github/workflows/docker.yml | 66 ++++++++++++++++++++++++++++++++++++ Dockerfile | 6 ++++ docker/get-docker-tags.sh | 0 3 files changed, 72 insertions(+) create mode 100644 .github/workflows/docker.yml mode change 100644 => 100755 docker/get-docker-tags.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..bf19b48 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,66 @@ +name: Create and publish a Docker image + +on: + push: + branches: ['main', 'docker-build-test'] + tags: ['v*'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Log in to the Container registry + uses: docker/login-action@v4 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Get tags + id: tags + run: | + echo "value<> $GITHUB_OUTPUT + ./docker/get-docker-tags.sh "$(date -u +%F)" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + shell: bash + - name: Build Docker image and publish to Docker Hub + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 + context: . + push: true + file: ./Dockerfile + tags: "${{ steps.tags.outputs.value }}" + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Move cache to limit growth + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/Dockerfile b/Dockerfile index 8616a2b..e16f426 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,10 @@ FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.20-bullseye AS builder + +LABEL org.opencontainers.image.source=https://github.com/ipfs/rainbow +LABEL org.opencontainers.image.description="A stand-alone IPFS Gateway" +LABEL org.opencontainers.image.licenses=MIT+APACHE_2.0 + + # This builds rainbow ARG TARGETPLATFORM TARGETOS TARGETARCH diff --git a/docker/get-docker-tags.sh b/docker/get-docker-tags.sh old mode 100644 new mode 100755