From 746eada6607050f0fa20732ec032063e87dcc8ae Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 16:55:14 +1100 Subject: [PATCH 1/9] Update docker-push.yml --- .github/workflows/docker-push.yml | 45 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 3d0bf4c..da5e1b2 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -1,4 +1,5 @@ name: Build and Push Image + on: release: types: [released] @@ -7,30 +8,28 @@ jobs: build: name: Build and push image runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 - - name: Build Image - id: build-image - uses: redhat-actions/buildah-build@v2 - with: - image: pryorda/vmware_exporter - tags: latest ${{ github.sha }} ${{ github.event.release.tag_name }} - dockerfiles: | - ./Dockerfile + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 - # Podman Login action (https://github.com/redhat-actions/podman-login) also be used to log in, - # in which case 'username' and 'password' can be omitted. - - name: Push To dhub - id: push-to-dhub - uses: redhat-actions/push-to-registry@v2 - with: - image: ${{ steps.build-image.outputs.image }} - tags: ${{ steps.build-image.outputs.tags }} - registry: docker.io - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Login to GitHub Container Registry + uses: docker/login-action + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Print image url - run: echo "Image pushed to ${{ steps.push-to-dhub.outputs.registry-paths }}" + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ github.sha }},ghcr.io/${{ github.repository }}:${{ github.event.release.tag_name }} From 86077cef5503cfc40de77ca84c1f27e21b123ba1 Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 17:10:28 +1100 Subject: [PATCH 2/9] Update docker-push.yml --- .github/workflows/docker-push.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index da5e1b2..65f3263 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -26,6 +26,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push + if: github.event_name == 'release' uses: docker/build-push-action@v2 with: context: . @@ -33,3 +34,15 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ github.sha }},ghcr.io/${{ github.repository }}:${{ github.event.release.tag_name }} + + - name: Build and push + if: github.event_name == 'workflow_dispatch' + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: | + ghcr.io/${{ github.repository }}:${{ github.sha }} + ghcr.io/${{ github.repository }}:$(date +%s) From 7000a1325ae240a11de2e8dc16ebebbf49754ecd Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 17:31:45 +1100 Subject: [PATCH 3/9] Update docker-push.yml --- .github/workflows/docker-push.yml | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 65f3263..278a8a9 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -1,6 +1,7 @@ name: Build and Push Image on: + workflow_dispatch: release: types: [released] @@ -10,39 +11,38 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry - uses: docker/login-action + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - if: github.event_name == 'release' - uses: docker/build-push-action@v2 + - name: Docker Metadata + id: docker_meta + uses: docker/metadata-action@v5 with: - context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: true - tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ github.sha }},ghcr.io/${{ github.repository }}:${{ github.event.release.tag_name }} + images: ghcr.io/${{ github.repository }} + flavor: | + ${{ github.event_name == 'release' && 'latest=true' }} + tags: | + type=sha + type=ref,event=branch + ${{ github.event_name == 'release' && 'type=semver,pattern={{version}}' }} - name: Build and push - if: github.event_name == 'workflow_dispatch' - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: | - ghcr.io/${{ github.repository }}:${{ github.sha }} - ghcr.io/${{ github.repository }}:$(date +%s) + tags: ${{ steps.docker_meta.outputs.tags }} From a4da1bc49a4716d401fe19b83445b899f3001c5d Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 17:37:47 +1100 Subject: [PATCH 4/9] Update docker-push.yml --- .github/workflows/docker-push.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 278a8a9..580c6f5 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -31,8 +31,7 @@ jobs: uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }} - flavor: | - ${{ github.event_name == 'release' && 'latest=true' }} + flavor: ${{ github.event_name == 'release' && 'latest=true' || '' }} tags: | type=sha type=ref,event=branch From d3e7dd494fac16517f2c79f17f720e9b5ea82348 Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 18:04:44 +1100 Subject: [PATCH 5/9] Adding requests --- .github/workflows/docker-push.yml | 2 +- requirements.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 580c6f5..0e53b6b 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -35,7 +35,7 @@ jobs: tags: | type=sha type=ref,event=branch - ${{ github.event_name == 'release' && 'type=semver,pattern={{version}}' }} + ${{ github.event_name == 'release' && 'type=semver,pattern={{version}}' || '' }} - name: Build and push uses: docker/build-push-action@v5 diff --git a/requirements.txt b/requirements.txt index d924920..5a03fbf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ pyvmomi>=6.5 twisted>=14.0.2 pyyaml>=5.1 service-identity +requests \ No newline at end of file From 68991cfee502c81afdb8138e9ea4ccd88630347b Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 18:19:05 +1100 Subject: [PATCH 6/9] Update docker-push.yml --- .github/workflows/docker-push.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 0e53b6b..1beaa0f 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -45,3 +45,5 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ${{ steps.docker_meta.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max From 1a614bb1e2e615c9e1e94513665377e97f324882 Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 19:57:50 +1100 Subject: [PATCH 7/9] Update docker-push.yml --- .github/workflows/docker-push.yml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 1beaa0f..699c3c2 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -26,7 +26,15 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Docker Metadata + - name: Login to DockerHub + if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_PASSWORD }} + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Docker Metadata GHCR id: docker_meta uses: docker/metadata-action@v5 with: @@ -37,13 +45,27 @@ jobs: type=ref,event=branch ${{ github.event_name == 'release' && 'type=semver,pattern={{version}}' || '' }} - - name: Build and push + - name: Docker Metadata DockerHub + id: meta_dockerhub + if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_PASSWORD }} + uses: docker/metadata-action@v5 + with: + images: docker.io/${{ github.repository }} + flavor: ${{ github.event_name == 'release' && 'latest=true' || '' }} + tags: | + type=sha + type=ref,event=branch + ${{ github.event_name == 'release' && 'type=semver,pattern={{version}}' || '' }} + + - name: Build and push image uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: ${{ steps.docker_meta.outputs.tags }} + tags: | + ${{ steps.docker_meta.outputs.tags }} + ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_PASSWORD && steps.meta_dockerhub.outputs.tags }} cache-from: type=gha cache-to: type=gha,mode=max From 00d11656b6eee3e18547ede909a956e087d477b2 Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 20:15:37 +1100 Subject: [PATCH 8/9] Update docker-push.yml --- .github/workflows/docker-push.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 699c3c2..d40c1a7 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -6,8 +6,23 @@ on: types: [released] jobs: + prepare: + runs-on: ubuntu-latest + outputs: + is_dockerhub_set: ${{ steps.check_secrets.outputs.is_set }} + steps: + - name: Check if DockerHub secrets are set + id: check_secrets + run: | + if [[ -n "${{ secrets.DOCKERHUB_USERNAME }}" && -n "${{ secrets.DOCKERHUB_PASSWORD }}" ]]; then + echo "::set-output name=is_set::true" + else + echo "::set-output name=is_set::false" + fi + build: name: Build and push image + needs: prepare runs-on: ubuntu-20.04 steps: - name: Checkout Code @@ -27,7 +42,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Login to DockerHub - if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_PASSWORD }} + if: ${{ needs.prepare.outputs.is_dockerhub_set }} uses: docker/login-action@v3 with: registry: docker.io @@ -47,7 +62,7 @@ jobs: - name: Docker Metadata DockerHub id: meta_dockerhub - if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_PASSWORD }} + if: ${{ needs.prepare.outputs.is_dockerhub_set }} uses: docker/metadata-action@v5 with: images: docker.io/${{ github.repository }} @@ -66,6 +81,6 @@ jobs: push: true tags: | ${{ steps.docker_meta.outputs.tags }} - ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_PASSWORD && steps.meta_dockerhub.outputs.tags }} + ${{ needs.prepare.outputs.is_dockerhub_set == 'true' && steps.meta_dockerhub.outputs.tags || '' }} cache-from: type=gha cache-to: type=gha,mode=max From f82ee155f114d380eae6758ad1d3bf035e76ae10 Mon Sep 17 00:00:00 2001 From: Troy Kelly Date: Sun, 29 Oct 2023 20:21:55 +1100 Subject: [PATCH 9/9] Update docker-push.yml --- .github/workflows/docker-push.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index d40c1a7..b6b3b8f 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -15,9 +15,9 @@ jobs: id: check_secrets run: | if [[ -n "${{ secrets.DOCKERHUB_USERNAME }}" && -n "${{ secrets.DOCKERHUB_PASSWORD }}" ]]; then - echo "::set-output name=is_set::true" + echo "::set-output name=is_set::'true'" else - echo "::set-output name=is_set::false" + echo "::set-output name=is_set::'false'" fi build: @@ -42,7 +42,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Login to DockerHub - if: ${{ needs.prepare.outputs.is_dockerhub_set }} + if: ${{ needs.prepare.outputs.is_dockerhub_set == 'true' }} uses: docker/login-action@v3 with: registry: docker.io @@ -62,7 +62,7 @@ jobs: - name: Docker Metadata DockerHub id: meta_dockerhub - if: ${{ needs.prepare.outputs.is_dockerhub_set }} + if: ${{ needs.prepare.outputs.is_dockerhub_set == 'true' }} uses: docker/metadata-action@v5 with: images: docker.io/${{ github.repository }}