Use lowercase image name when building docker image

This avoids issues with github forks that contain
uppercase characters. Also updated github actions
to avoid other warnings in builds.
This commit is contained in:
Philipp Grathwohl 2023-03-07 07:50:52 +01:00
parent abf4be7479
commit 947ee5616b

View file

@ -9,7 +9,7 @@ on:
pull_request: pull_request:
env: env:
image-name: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/craftbeerpi4
jobs: jobs:
build: build:
@ -55,8 +55,11 @@ jobs:
id: prep id: prep
run: | run: |
IMAGE_NAME_LOWERCASE=${IMAGE_NAME,,}
echo "Using image name $IMAGE_NAME_LOWERCASE"
PUBLISH_IMAGE=false PUBLISH_IMAGE=false
TAGS="${{ env.image-name }}:dev" TAGS="$IMAGE_NAME_LOWERCASE:dev"
# Define the image that will be used as a cached image # Define the image that will be used as a cached image
# to speed up the build process # to speed up the build process
@ -66,18 +69,21 @@ jobs:
# when building master/main use :latest tag and the version number # when building master/main use :latest tag and the version number
# from the cbpi/__init__.py file # from the cbpi/__init__.py file
VERSION=$(grep -o -E "(([0-9]{1,2}[.]?){2,3}[0-9]+)" cbpi/__init__.py) VERSION=$(grep -o -E "(([0-9]{1,2}[.]?){2,3}[0-9]+)" cbpi/__init__.py)
LATEST_IMAGE=${{ env.image-name }}:latest LATEST_IMAGE=$IMAGE_NAME_LOWERCASE:latest
BUILD_CACHE_IMAGE_NAME=${LATEST_IMAGE} BUILD_CACHE_IMAGE_NAME=${LATEST_IMAGE}
TAGS="${LATEST_IMAGE},${{ env.image-name }}:v${VERSION}" TAGS="${LATEST_IMAGE},$IMAGE_NAME_LOWERCASE:v${VERSION}"
PUBLISH_IMAGE=true PUBLISH_IMAGE="true"
elif [[ $GITHUB_REF_NAME == development ]]; then elif [[ $GITHUB_REF_NAME == development ]]; then
PUBLISH_IMAGE=true PUBLISH_IMAGE="true"
fi fi
# Set output parameters.
echo ::set-output name=tags::${TAGS} echo "tags: $TAGS"
echo ::set-output name=publish_image::${PUBLISH_IMAGE} echo "publish_image: $PUBLISH_IMAGE"
echo ::set-output name=build_cache_image_name::${BUILD_CACHE_IMAGE_NAME} echo "cache_name: $BUILD_CACHE_IMAGE_NAME"
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "publish_image=$PUBLISH_IMAGE" >> $GITHUB_OUTPUT
echo "cache_name=$BUILD_CACHE_IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@master uses: docker/setup-qemu-action@master
@ -89,23 +95,23 @@ jobs:
uses: docker/setup-buildx-action@master uses: docker/setup-buildx-action@master
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@v1 uses: docker/login-action@v2
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build - name: Build
uses: docker/build-push-action@v2 uses: docker/build-push-action@v4
with: with:
builder: ${{ steps.buildx.outputs.name }} builder: ${{ steps.buildx.outputs.name }}
context: . context: .
file: ./Dockerfile file: ./Dockerfile
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
target: deploy target: deploy
push: ${{ steps.prep.outputs.publish_image }} push: ${{ steps.prep.outputs.publish_image == 'true' }}
tags: ${{ steps.prep.outputs.tags }} tags: ${{ steps.prep.outputs.tags }}
cache-from: type=registry,ref=${{ steps.prep.outputs.build_cache_image_name }} cache-from: type=registry,ref=${{ steps.prep.outputs.cache_name }}
cache-to: type=inline cache-to: type=inline
labels: | labels: |
org.opencontainers.image.title=${{ github.event.repository.name }} org.opencontainers.image.title=${{ github.event.repository.name }}