Build and Publish Docker Image #12
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: Build and Publish Docker Image | |
on: | |
release: | |
types: [created] | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Docker Image Tag' | |
required: true | |
default: latest | |
permissions: | |
contents: read | |
packages: write | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: flavio-fernandes/mqtt2kasa | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
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: Log in to the GH Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate git-info to write to image | |
run: | | |
BRANCH=$(git rev-parse --short "$GITHUB_SHA") | |
COMMIT=$(git rev-parse HEAD) | |
pushd ./mqtt2kasa | |
echo pwd: ${PWD} ref: ${BRANCH} commit: ${COMMIT} tag: ${{ github.event.inputs.tag || github.event.release.tag_name }} | |
echo ref: ${BRANCH} commit: ${COMMIT} tag: ${{ github.event.inputs.tag || github.event.release.tag_name }} > git_info | |
ls | |
popd | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.tag || github.event.release.tag_name }} | |
platforms: linux/amd64,linux/arm64 | |
context: . | |
- name: Log out from the GH Container registry | |
run: docker logout ${{ env.REGISTRY }} |