mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-28 01:28:30 +00:00
Move docker build to separate script for less jank
This commit is contained in:
parent
2578be2447
commit
89e8fe580e
.github
45
.github/scripts/docker-build.bash
vendored
Executable file
45
.github/scripts/docker-build.bash
vendored
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
DOCKERHUB_IMAGE_ID=$DOCKERHUB_ACCOUNT/$IMAGE_NAME
|
||||
|
||||
# Change all uppercase to lowercase
|
||||
DOCKERHUB_IMAGE_ID=$(echo $DOCKERHUB_IMAGE_ID | tr '[A-Z]' '[a-z]')
|
||||
|
||||
image_tags=()
|
||||
|
||||
# Strip git ref prefix from version
|
||||
VERSION_TAG=$(echo $GITHUB_REF | sed -e 's,.*/\(.*\),\1,')
|
||||
|
||||
# Strip "v" prefix from tag name
|
||||
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
||||
VERSION_TAG=$(echo $VERSION_TAG | sed -e 's/^v//')
|
||||
fi
|
||||
|
||||
image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:$VERSION_TAG")
|
||||
|
||||
# tag as latest on releases
|
||||
if [[ "$RELEASE" == ON ]]; then
|
||||
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"
|
||||
|
||||
# Only push on main
|
||||
if [[ "$GITHUB_REF" == refs/head/main ]]; then
|
||||
push_image="--push"
|
||||
image_platforms="--platform linux/arm/v7,linux/arm64/v8,linux/amd64"
|
||||
cache_tag="main-cache"
|
||||
fi
|
||||
|
||||
docker buildx build \
|
||||
${push_image} \
|
||||
${image_platforms} \
|
||||
--cache-from=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:$cache_tag \
|
||||
--cache-to=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:$cache_tag,mode=max \
|
||||
"${image_tags[@]}" \
|
||||
.
|
42
.github/workflows/docker.yaml
vendored
42
.github/workflows/docker.yaml
vendored
@ -44,43 +44,5 @@ jobs:
|
||||
- name: Build and push Docker image
|
||||
env:
|
||||
RELEASE: "${{ startsWith(github.ref, 'refs/tags/') && 'ON' || 'OFF' }}"
|
||||
run: |
|
||||
set -ex
|
||||
|
||||
DOCKERHUB_IMAGE_ID=$DOCKERHUB_ACCOUNT/$IMAGE_NAME
|
||||
|
||||
# Change all uppercase to lowercase
|
||||
DOCKERHUB_IMAGE_ID=$(echo $DOCKERHUB_IMAGE_ID | tr '[A-Z]' '[a-z]')
|
||||
|
||||
image_tags=()
|
||||
|
||||
# Strip git ref prefix from version
|
||||
VERSION_TAG=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
||||
|
||||
# Strip "v" prefix from tag name
|
||||
[[ "${{ github.ref }}" == refs/tags/* ]] && VERSION_TAG=$(echo $VERSION_TAG | sed -e 's/^v//')
|
||||
|
||||
image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:$VERSION_TAG")
|
||||
|
||||
# tag as latest on releases
|
||||
[[ "$RELEASE" == ON ]] && image_tags+=("--tag" "$DOCKERHUB_IMAGE_ID:latest")
|
||||
|
||||
# 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
|
||||
[[ "${{ github.ref }}" == refs/head/main ]] \
|
||||
&& push_image="--push" \
|
||||
&& image_platforms="--platform linux/arm/v7,linux/arm64/v8,linux/amd64" \
|
||||
&& cache_tag="main-cache"
|
||||
|
||||
docker buildx build \
|
||||
${push_image} \
|
||||
${image_platforms} \
|
||||
--cache-from=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:$cache_tag \
|
||||
--cache-to=type=registry,ref=$DOCKERHUB_ACCOUNT/$IMAGE_NAME:$cache_tag,mode=max \
|
||||
"${image_tags[@]}" \
|
||||
.
|
||||
GITHUB_REF: ${{ github.ref }}
|
||||
run: ./.github/scripts/docker-build.bash
|
||||
|
Loading…
x
Reference in New Issue
Block a user