Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Also tag dev-* images when building production images #152

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions build/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,11 @@ append_tags() {
local search=$1
local replace=$2
local csv_string=$3
local exclude=${4:-dummy}
local new_string=""
for item in ${csv_string//,/ }; do
new_string+="${new_string:+,}$item"
if [[ $item == *"$search"* ]]; then
if echo "$item"| grep -v "$exclude" | grep -Eq "$search"; then
local new_item=${item/$search/$replace}
new_string+="${new_string:+,}$new_item"
fi
Expand Down Expand Up @@ -485,6 +486,11 @@ fi
# BUILD_TAGS="$(append_tags "-$OS_BASE" "-tidy" "$BUILD_TAGS")"
# fi

# also tag 'dev-' variants when the tag prefix is empty
if [ "$BUILD_TAG_PREFIX" == "" ]; then
BUILD_TAGS="$(append_tags ":" ":dev-" "$BUILD_TAGS")"
fi

# also publish to ghcr.io
if [ "$PUBLISH_TO_GHCR" == "1" ]; then
BUILD_TAGS="$(append_tags "$DEFAULT_REPO" "ghcr.io/$DEFAULT_REPO" "$BUILD_TAGS")"
Expand All @@ -493,7 +499,7 @@ fi
# also push a copy to archived repo
if [ "$ARCHIVES_REPO" != "" ] && [ "$BUILD_TAG_PREFIX" == "" ]; then
unique_id="$(date +%Y%m%d)"
BUILD_TAGS="$(append_tags "${DEFAULT_BUILD_NAME}:" "${ARCHIVES_REPO}:${unique_id}-" "$BUILD_TAGS")"
BUILD_TAGS="$(append_tags "${DEFAULT_BUILD_NAME}:" "${ARCHIVES_REPO}:${unique_id}-" "$BUILD_TAGS" ":dev-")"
fi

################################################################################
Expand Down Expand Up @@ -584,7 +590,7 @@ fi

BUILD_CACHE_KEY="$BUILD_CACHE_KEY/(buildfile:$(path_hash $BUILD_DOCKERFILE | head -c10))\
/(buildcontext:$(path_hash $BUILD_CONTEXT | shasum | head -c10))\
/(workflows:$(path_hash $BASE_DIR/.github/workflows | shasum | head -c10))"
/(workflows:$(path_hash $BASE_DIR/.github/workflows/template-* | shasum | head -c10))"

BUILD_TMP_NAME="localhost:5000/$(path_hash "$BUILD_CACHE_KEY" | head -c10)"

Expand Down Expand Up @@ -668,7 +674,7 @@ github_env UPDATE_README $UPDATE_README

if [ "$SKIP_BUILD" != "1" ]; then
echo "🐧 Debug:"
path_hash "$BUILD_CONTEXT"
path_hash "$BUILD_DOCKERFILE"
path_hash "$BASE_DIR/.github/workflows"
path_hash $BUILD_CONTEXT
path_hash $BUILD_DOCKERFILE
path_hash $BASE_DIR/.github/workflows/template-*
fi
24 changes: 14 additions & 10 deletions build/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,23 @@ github_env() {
################################################################################

path_hash() {
if [ "$1" == "" ]; then
if [ $# -eq 0 ]; then
echo -n "" | shasum
return
fi

local target="$1"
if [ -d $target ]; then
find "$target" -type f -not -name '.*' \
| sort -dbfi | xargs -r shasum 2>/dev/null
elif [ -f $target ]; then
shasum $target 2>/dev/null
else
echo -n "$@" | shasum 2>/dev/null
fi
for target; do
if [ ! -z "$target" ]; then
if [ -d "$target" ]; then
find "$target" -type f -not -name '.*' \
| sort -dbfi | xargs -r shasum 2>/dev/null
elif [ -f "$target" ]; then
shasum "$target" 2>/dev/null
else
echo -n "$@" | shasum 2>/dev/null
fi
fi
done
}

################################################################################
Expand All @@ -109,3 +112,4 @@ path_hash() {
# get_dockerhub_latest_sha "library/alpine"
# get_dockerhub_latest_sha "library/ubuntu"
# get_dockerhub_latest_sha "library/debian"
# path_hash ./.github/workflows/template-*