Added working auto-tagging

master
Jef Roosens 2021-03-23 10:55:00 +01:00
parent c411fc5d6c
commit e81205bef7
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
1 changed files with 10 additions and 10 deletions

20
build
View File

@ -15,25 +15,18 @@ minor_version="$(echo "$patch_version" |
branch="$(git branch --show-current)" branch="$(git branch --show-current)"
if [[ "$branch" = "master" ]]; then if [[ "$branch" = "master" ]]; then
tags=("$patch_version" "$minor_version" "$major_version" "latest" ) tags=("$patch_version" "$minor_version" "$major_version" "latest")
elif [[ "$branch" = "develop" ]]; then elif [[ "$branch" = "develop" ]]; then
tags=("$patch_version-dev" "$minor_version-dev" "$major_version-dev" ) tags=("$patch_version-dev" "$minor_version-dev" "$major_version-dev" "dev")
else else
tags=("$branch") tags=("$branch")
fi fi
tag_flags=()
for tag in "${tags[@]}"; do
tag_flags+=("-t $1:$tag")
done
# Run the actual build command # Run the actual build command
docker build $tag_flags . docker build -t "$1:$tags" .
if [[ "$2" = push ]]; then if [[ "$2" = push ]]; then
[[ "$branch" =~ ^develop|master$ ]] || { [[ "$branch" =~ ^develop|master$ ]] || {
@ -42,7 +35,14 @@ if [[ "$2" = push ]]; then
} }
for tag in "${tags[@]}"; do for tag in "${tags[@]}"; do
# Create the tag
docker tag "$1:$tags" "$1:$tag"
# Push the tag
docker push "$1:$tag" docker push "$1:$tag"
# Remove the tag again, if it's not the main tag
[[ "$tag" != "$tags" ]] && docker rmi "$1:$tag"
done done
elif [[ "$2" = run ]]; then elif [[ "$2" = run ]]; then