mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-30 10:38:36 +00:00
Docker: only write to cache if creds available
This commit is contained in:
parent
0bc625fdea
commit
7043b34abb
26
.github/scripts/docker-build.bash
vendored
26
.github/scripts/docker-build.bash
vendored
@ -1,12 +1,17 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
DOCKERHUB_USERNAME="${DOCKERHUB_USERNAME:-conky}"
|
DH_USERNAME="${DOCKERHUB_USERNAME:-conky}"
|
||||||
DOCKERHUB_IMAGE_ID=$DOCKERHUB_USERNAME/$IMAGE_NAME
|
DOCKERHUB_IMAGE_ID=$DH_USERNAME/$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]')
|
||||||
|
|
||||||
|
# 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"
|
||||||
image_tags=()
|
image_tags=()
|
||||||
|
|
||||||
# Strip git ref prefix from version
|
# Strip git ref prefix from version
|
||||||
@ -24,12 +29,6 @@ if [[ "$RELEASE" == ON ]]; then
|
|||||||
image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:latest")
|
image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:latest")
|
||||||
fi
|
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"
|
|
||||||
|
|
||||||
# Only push on main
|
# Only push on main
|
||||||
if [[ "$GITHUB_REF" == refs/heads/main ]]; then
|
if [[ "$GITHUB_REF" == refs/heads/main ]]; then
|
||||||
push_image="--push"
|
push_image="--push"
|
||||||
@ -37,10 +36,17 @@ if [[ "$GITHUB_REF" == refs/heads/main ]]; then
|
|||||||
cache_tag="main-cache"
|
cache_tag="main-cache"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Only write to cache if credentials are available
|
||||||
|
if [[ -z "$DOCKERHUB_USERNAME" ]]; then
|
||||||
|
write_cache=""
|
||||||
|
else
|
||||||
|
write_cache="--cache-to=type=registry,ref=$DOCKERHUB_IMAGE_ID:$cache_tag,mode=max"
|
||||||
|
fi
|
||||||
|
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
${push_image} \
|
${push_image} \
|
||||||
${image_platforms} \
|
${image_platforms} \
|
||||||
--cache-from=type=registry,ref=$DOCKERHUB_USERNAME/$IMAGE_NAME:$cache_tag \
|
--cache-from=type=registry,ref=$DOCKERHUB_IMAGE_ID:$cache_tag \
|
||||||
--cache-to=type=registry,ref=$DOCKERHUB_USERNAME/$IMAGE_NAME:$cache_tag,mode=max \
|
${write_cache} \
|
||||||
"${image_tags[@]}" \
|
"${image_tags[@]}" \
|
||||||
.
|
.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user