Skip to content

Add handling of tags in docker-helper #12943

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 10 additions & 4 deletions bin/docker-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,21 @@ function _get_current_branch() {
git branch --show-current
}

function _get_current_tag() {
git describe --tags --exact-match 2> /dev/null || true
}

function _enforce_image_name() {
if [ -z "$IMAGE_NAME" ]; then _fail "Mandatory parameter IMAGE_NAME missing."; fi
}

function _enforce_main_branch() {
function _enforce_tagged_or_main_branch() {
MAIN_BRANCH=${MAIN_BRANCH-"main"}
CURRENT_BRANCH=$(_get_current_branch)
CURRENT_TAG=$(_get_current_tag)
echo "Current git branch: '$CURRENT_BRANCH'"
test "$CURRENT_BRANCH" == "$MAIN_BRANCH" || _fail "Current branch ($CURRENT_BRANCH) is not $MAIN_BRANCH."
echo "Current tag: '$CURRENT_TAG'"
test -n "$CURRENT_TAG" || test "$CURRENT_BRANCH" == "$MAIN_BRANCH" || _fail "Current branch ($CURRENT_BRANCH) is not $MAIN_BRANCH and current tag ($CURRENT_TAG) is not set."
}

function _enforce_no_fork() {
Expand Down Expand Up @@ -158,7 +164,7 @@ function cmd-load() {

function cmd-push() {
_enforce_image_name
_enforce_main_branch
_enforce_tagged_or_main_branch
_enforce_no_fork
_enforce_docker_credentials
_enforce_platform
Expand Down Expand Up @@ -213,7 +219,7 @@ function cmd-push() {

function cmd-push-manifests() {
_enforce_image_name
_enforce_main_branch
_enforce_tagged_or_main_branch
_enforce_no_fork
_enforce_docker_credentials
_set_version_defaults
Expand Down
17 changes: 17 additions & 0 deletions tests/bin/test.docker-helper.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ setup_file() {
"branch")
echo "main"
;;
"describe")
echo "$TEST_TAG"
;;
"remote")
echo "origin [email protected]:localstack/localstack.git (push)"
;;
Expand Down Expand Up @@ -117,12 +120,26 @@ setup_file() {
@test "push fails on non-default branch" {
export MAIN_BRANCH="non-existing-branch"
export IMAGE_NAME="localstack/test"
export DOCKER_USERNAME=test
export DOCKER_PASSWORD=test
export PLATFORM=amd64
run bin/docker-helper.sh push
[ "$status" -ne 0 ]
[[ "$output" =~ "is not non-existing-branch" ]]
}

@test "push succeeds on tag without main branch" {
export MAIN_BRANCH="non-existing-branch"
export IMAGE_NAME="localstack/test"
export DOCKER_USERNAME=test
export DOCKER_PASSWORD=test
export PLATFORM=amd64
export TEST_TAG=v1.0.0
run bin/docker-helper.sh push
echo "$output"
[ "$status" -eq 0 ]
}

@test "push fails without PLATFORM" {
export IMAGE_NAME="localstack/test"
export MAIN_BRANCH="main"
Expand Down
Loading