Skip to content

Commit

Permalink
Refactor code to make it more declarative
Browse files Browse the repository at this point in the history
  • Loading branch information
whoan committed Oct 28, 2023
1 parent 81b82cf commit 16e9d90
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ _push() {
docker push "$(_get_full_image_name):$tag"
}

_is_logged_in() {
[ "$not_logged_in" != true ]
}

_must_pull() {
[ "$INPUT_PULL_IMAGE_AND_STAGES" == true ]
}

_can_pull() {
_must_pull && _is_logged_in
}

_must_push() {
if [ "$INPUT_PUSH_IMAGE_AND_STAGES" = on:push ]; then
Expand All @@ -128,6 +139,10 @@ _must_push() {
$INPUT_PUSH_IMAGE_AND_STAGES
}

_can_push() {
_must_push && _is_logged_in
}

_push_git_tag() {
[[ "$GITHUB_REF" =~ /tags/ ]] || return 0
local git_tag=${GITHUB_REF##*/tags/}
Expand Down Expand Up @@ -317,10 +332,7 @@ login_to_registry() {
}

create_repos() {
if [ "$not_logged_in" == true ]; then
return
fi
if ! _must_push; then
if ! _can_push; then
return
fi
if _is_aws_ecr; then
Expand All @@ -329,10 +341,7 @@ create_repos() {
}

pull_cached_stages() {
if [ "$not_logged_in" == true ]; then
return
fi
if [ "$INPUT_PULL_IMAGE_AND_STAGES" != true ]; then
if ! _can_pull; then
return
fi
# cache importing/exporting is done in build statement when BuildKit is enabled
Expand Down Expand Up @@ -433,7 +442,7 @@ push_image_and_stages() {
return
fi

if [ "$not_logged_in" ]; then
if ! _is_logged_in; then
echo "ERROR: Can't push when not logged in to registry. Set \"push_image_and_stages: false\" if you don't want to push" >&2
return 1
fi
Expand Down

0 comments on commit 16e9d90

Please sign in to comment.