Feat: push container image to Github Registry #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: push-latest | |
# | |
on: | |
# Allow manual trigger on default branch | |
workflow_dispatch: | |
# DELETE ME TEST ONLY Trigger selected on PR events | |
pull_request: | |
types: [synchronize, opened, reopened, ready_for_review] | |
# Trigger on push to master only on Dockerfile related modifications | |
push: | |
branches: | |
- "master" | |
paths: | |
- "Dockerfile" | |
- "supported_versions.json" | |
- "hashicorp.asc" | |
- "tests/**" | |
- ".dockerignore" | |
- ".github/workflows/push-latest.yml" | |
env: | |
IMAGE_NAME: "zenika/terraform-azure-cli" | |
REGISTRY: ghcr.io | |
jobs: | |
build_push_latest: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- name: Retrieve latest suported versions | |
run: | | |
echo "AZ_VERSION=$(jq -r '.azcli_version | sort | .[-1]' supported_versions.json)" >> $GITHUB_ENV | |
echo "TF_VERSION=$(jq -r '.tf_version | sort | .[-1]' supported_versions.json)" >> $GITHUB_ENV | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
flavor: | | |
latest=auto | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push container images | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386 | |
build-args: | | |
TERRAFORM_VERSION=${{ env.TF_VERSION }} | |
AZ_VERSION=${{ env.AZ_VERSION }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |