From 79da40e7ac1cc6539b6a8415f17bf6411ff003e9 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sat, 16 Dec 2023 18:39:59 +0100 Subject: [PATCH] extend build actions to copy docker images to old dockerhub repository --- .github/workflows/_shared-docker-clone.yaml | 68 +++++++++++++++++++++ .github/workflows/build-master.yml | 12 ++++ .github/workflows/build-release.yml | 12 ++++ 3 files changed, 92 insertions(+) create mode 100644 .github/workflows/_shared-docker-clone.yaml diff --git a/.github/workflows/_shared-docker-clone.yaml b/.github/workflows/_shared-docker-clone.yaml new file mode 100644 index 00000000..964b6e61 --- /dev/null +++ b/.github/workflows/_shared-docker-clone.yaml @@ -0,0 +1,68 @@ + +name: Reusable docker clone workflow +on: + workflow_call: + inputs: + source_repository: + description: 'Source Docker Hub Repository' + default: '' + required: false + type: string + target_repository: + description: 'Target Docker Hub Repository' + default: '' + required: false + type: string + tags: + description: 'Docker Image Tags (JSON)' + default: '' + required: false + type: string + secrets: + DOCKERHUB_USERNAME: + description: 'Docker Hub Username' + required: false + DOCKERHUB_TOKEN: + description: 'Docker Hub Token' + required: false + +# shared build jobs +jobs: + clone_docker_images: + name: Clone docker images to ${{ inputs.target_repository }} + if: ${{ inputs.tags }} + runs-on: ubuntu-latest + strategy: + matrix: + tag: ${{ fromJSON(inputs.tags) }} + steps: + + # prepare docker + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Get tag names + id: tags + run: | + tagstr="${{ matrix.tag }}" + tagparts=(${tagstr//:/ }) + echo "source_tag=${tagparts[0]}" >> $GITHUB_OUTPUT + if [ -z "$tagparts[1]" ]; then + echo "target_tag=${tagparts[0]}" >> $GITHUB_OUTPUT + else + echo "target_tag=${tagparts[1]}" >> $GITHUB_OUTPUT + fi + + # build multiarch image + - name: "Build docker manifest: ${{ steps.tags.outputs.target_tag }}" + run: | + docker manifest create ${{ inputs.target_repository }}:${{ steps.tags.outputs.target_tag }} \ + --amend ${{ inputs.source_repository }}:${{ steps.tags.outputs.source_tag }}-amd64 \ + --amend ${{ inputs.source_repository }}:${{ steps.tags.outputs.source_tag }}-arm64 + + - name: "Push docker manifest: ${{ steps.tags.outputs.target_tag }}" + run: | + docker manifest push ${{ inputs.target_repository }}:${{ steps.tags.outputs.target_tag }} diff --git a/.github/workflows/build-master.yml b/.github/workflows/build-master.yml index e1227840..fb647d04 100644 --- a/.github/workflows/build-master.yml +++ b/.github/workflows/build-master.yml @@ -32,6 +32,18 @@ jobs: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + clone_docker_images: + name: "Copy docker images" + needs: [build_binaries] + uses: ./.github/workflows/_shared-docker-clone.yaml + with: + source_repository: "ethpandaops/dora" + target_repository: "pk910/dora-the-explorer" + tags: "['master:unstable']" + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_PK_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_PK_TOKEN }} + create_snapshot_release: name: Create snapshot release needs: [build_binaries] diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 01d847e3..4a8c3907 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -22,6 +22,18 @@ jobs: secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + + clone_docker_images: + name: "Copy docker images" + needs: [build_binaries] + uses: ./.github/workflows/_shared-docker-clone.yaml + with: + source_repository: "ethpandaops/dora" + target_repository: "pk910/dora-the-explorer" + tags: "['v${{ inputs.version }}','v${{ inputs.version }}:latest']" + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_PK_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_PK_TOKEN }} create_release: name: Create Release