mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-16 04:02:15 +00:00
Docker: improve tagging, distinguish main
and latest
* Use `latest` for the latest release * Use `main` (or the branch) for the latest dev builds against a branch * Tag releases with their version * Only push when building against `main` branch * Only build amd64 images on PRs for speedier builds * Separate main/PR caches
This commit is contained in:
parent
9dfc7318f9
commit
6a248a94d2
44
.github/workflows/docker.yaml
vendored
44
.github/workflows/docker.yaml
vendored
@ -29,7 +29,7 @@ env:
|
|||||||
DOCKER_BUILDKIT: 1
|
DOCKER_BUILDKIT: 1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
buildx:
|
docker-buildx:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@ -41,26 +41,48 @@ jobs:
|
|||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
- name: Log into Dockerhub registry
|
- name: Log into Dockerhub registry
|
||||||
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u $DOCKERHUB_ACCOUNT --password-stdin
|
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u $DOCKERHUB_ACCOUNT --password-stdin
|
||||||
- name: Build
|
- name: Build and push Docker image
|
||||||
|
env:
|
||||||
|
RELEASE: "${{ startsWith(github.ref, 'refs/tags/') && 'ON' || 'OFF' }}"
|
||||||
run: |
|
run: |
|
||||||
|
set -ex
|
||||||
|
|
||||||
DOCKERHUB_IMAGE_ID=$DOCKERHUB_ACCOUNT/$IMAGE_NAME
|
DOCKERHUB_IMAGE_ID=$DOCKERHUB_ACCOUNT/$IMAGE_NAME
|
||||||
|
|
||||||
# Change all uppercase to lowercase
|
# Change all uppercase to lowercase
|
||||||
DOCKERHUB_IMAGE_ID=$(echo $DOCKERHUB_IMAGE_ID | tr '[A-Z]' '[a-z]')
|
DOCKERHUB_IMAGE_ID=$(echo $DOCKERHUB_IMAGE_ID | tr '[A-Z]' '[a-z]')
|
||||||
|
|
||||||
|
image_tags=()
|
||||||
|
|
||||||
# Strip git ref prefix from version
|
# Strip git ref prefix from version
|
||||||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
VERSION_TAG=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
||||||
|
|
||||||
# Strip "v" prefix from tag name
|
# Strip "v" prefix from tag name
|
||||||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
|
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_TAG=$(echo $VERSION_TAG | sed -e 's/^v//')
|
||||||
|
|
||||||
# Use Docker `latest` tag convention
|
image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:$VERSION_TAG")
|
||||||
[ "$VERSION" == "main" ] && VERSION=latest
|
|
||||||
|
if [ "$RELEASE" == "ON" ]; then
|
||||||
|
# tag as latest on releases
|
||||||
|
image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:latest")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Only build amd64 on PRs, build all platforms on main. The arm builds
|
||||||
|
# take far too long.
|
||||||
|
image_platforms="--platform linux/amd64"
|
||||||
|
push_image=""
|
||||||
|
cache_tag="pr-cache"
|
||||||
|
if [ "${{ github.ref }}" == "refs/head/main" ]; then
|
||||||
|
# Only push on main
|
||||||
|
push_image="--push"
|
||||||
|
image_platforms="--platform linux/arm/v7,linux/arm64/v8,linux/amd64"
|
||||||
|
cache_tag="main-cache"
|
||||||
|
fi
|
||||||
|
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--push \
|
${push_image} \
|
||||||
--platform linux/arm/v7,linux/arm64/v8,linux/amd64 \
|
${image_platforms} \
|
||||||
--cache-from=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:buildcache \
|
--cache-from=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:$cache_tag \
|
||||||
--cache-to=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:buildcache,mode=max \
|
--cache-to=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:$cache_tag,mode=max \
|
||||||
--tag $DOCKERHUB_IMAGE_ID:$VERSION \
|
"${image_tags[@]}" \
|
||||||
.
|
.
|
||||||
|
Loading…
Reference in New Issue
Block a user