Merge pull request #1 from controllan/feature/improve-ci-pipeline #7
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: Docker | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
on: | |
push: | |
branches: [ main ] | |
# Publish semver tags as releases. | |
tags: [ 'v*.*.*' ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
inputs: | |
dry_run: | |
type: boolean | |
default: false | |
description: "Parameter to enable a dry-run (run without changes)" | |
required: false | |
tags: | |
type: string | |
default: "" | |
description: "The list of tags to be added to the image" | |
required: false | |
labels: | |
type: string | |
default: "" | |
description: "The list of labels to be added to the image" | |
required: false | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
IMAGE_NAME: pat-git/docker-state-exporter | |
jobs: | |
build: | |
strategy: | |
matrix: | |
os: [ ARM64, X64 ] | |
runs-on: [ self-hosted, ubuntu-latest, '${{ matrix.os }}' ] | |
name: "Build docker image for ${{ matrix.os }} [dry_run=${{ inputs.dry_run }}]" | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push Docker image [${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}] | |
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' && inputs.dry_run == false }} | |
tags: ${{ steps.meta.outputs.tags || inputs.tags }} | |
labels: ${{ steps.meta.outputs.labels || inputs.labels }} |