diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 3d0bf4c..b6b3b8f 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -1,36 +1,86 @@ name: Build and Push Image + on: + workflow_dispatch: release: 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: - - uses: actions/checkout@v2 - - - 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 - - # 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: Print image url - run: echo "Image pushed to ${{ steps.push-to-dhub.outputs.registry-paths }}" + - name: Checkout Code + 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: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to DockerHub + if: ${{ needs.prepare.outputs.is_dockerhub_set == 'true' }} + 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: + 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: Docker Metadata DockerHub + id: meta_dockerhub + if: ${{ needs.prepare.outputs.is_dockerhub_set == 'true' }} + 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 }} + ${{ needs.prepare.outputs.is_dockerhub_set == 'true' && steps.meta_dockerhub.outputs.tags || '' }} + cache-from: type=gha + cache-to: type=gha,mode=max 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