Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-platform #385

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 76 additions & 26 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pyvmomi>=6.5
twisted>=14.0.2
pyyaml>=5.1
service-identity
requests