DSMR: Build Docker images #186
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: "DSMR: Build Docker images" | |
on: | |
# push: | |
# branches: | |
# - develop | |
# - main | |
# paths-ignore: | |
# - "**.md" | |
# pull_request: | |
# branches: | |
# - develop | |
# - main | |
# types: | |
# - closed | |
# paths-ignore: | |
# - "**.md" | |
workflow_dispatch: | |
concurrency: | |
group: docker-build | |
cancel-in-progress: true | |
env: | |
DOCKER_TARGET_REPO: xirixiz/dsmr-reader-docker | |
DOCKERFILE: Dockerfile | |
DOCKER_TARGET_RELEASE: 2024.02.03 | |
jobs: | |
################################################ | |
## JOB: BUILD_RELEASE | |
################################################ | |
build_release: | |
runs-on: ubuntu-latest | |
steps: | |
################################################ | |
## GENERAL | |
################################################ | |
- name: "π GitHub - Checkout repository" | |
uses: actions/checkout@v4 | |
- name: "π GitHub - Get Branch / Tag Name" | |
id: get_branch | |
run: | | |
export RELEASE_NAME=$(if [[ "${GITHUB_REF}" =~ "refs/tags/" ]]; \ | |
then echo ${GITHUB_REF/refs\/tags\//}; \ | |
else echo ${GITHUB_REF/refs\/heads\//}; fi) | |
echo "${RELEASE_NAME}" | |
echo "NAME=${RELEASE_NAME}" >>$GITHUB_OUTPUT | |
- name: "π GitHub - Get Tag" | |
id: get_tag | |
run: | | |
export TARGET_IMAGE_TAG=$(if [ "${{ steps.get_branch.outputs.name }}" = "main" ]; \ | |
then echo "${{ matrix.DOCKER_TAG_SUFFIX }}"; \ | |
else echo "${{ matrix.DOCKER_TAG_SUFFIX }}-${{ steps.get_branch.outputs.name }}"; \ | |
fi;) | |
echo "${TARGET_IMAGE_TAG}" | |
echo "NAME=${TARGET_IMAGE_TAG}" >>$GITHUB_OUTPUT | |
################################################ | |
## QEMU | |
################################################ | |
- name: "βοΈ QEMU - Set up QEMU" | |
uses: docker/setup-qemu-action@v3 | |
################################################ | |
## DSMR | |
################################################ | |
- name: "βοΈ DSMR - Determine version" | |
id: dsmr_version | |
shell: bash | |
run: | | |
URL='https://api.github.com/repos/dsmrreader/dsmr-reader/releases/latest' | |
VERSION=$(curl -SskLf "${URL}" | jq -r '.tag_name') | |
DOWNLOAD_URL=$(curl -SskLf "${URL}" | jq -r '.tarball_url') | |
# VERSION="5.0.0" | |
VERSION=${VERSION#"v"} | |
echo "version=${VERSION}" >>$GITHUB_OUTPUT | |
################################################ | |
## Docker | |
################################################ | |
- name: "βοΈ Docker - Set up Docker Buildx" | |
uses: docker/setup-buildx-action@v3 | |
- name: "π Docker - Login" | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: "π Docker - Login to GHCR" | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: "βοΈ Docker - Set up metadata" | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
tags: | | |
type=raw,value=${{ steps.dsmr_version.outputs.version }}-${{ env.DOCKER_TARGET_RELEASE }},enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
type=raw,value=development,enable=${{ github.ref != format('refs/heads/{0}', 'main') }} | |
images: | | |
${{ env.DOCKER_TARGET_REPO }} | |
ghcr.io/${{ env.DOCKER_TARGET_REPO }} | |
- name: "π Docker - Build" | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: |- | |
DSMR_VERSION=${{ steps.dsmr_version.outputs.version }} | |
DOCKER_TARGET_RELEASE=${{ env.DOCKER_TARGET_RELEASE }} |