Skip to content

Commit

Permalink
use master as latest in dev only
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Oct 7, 2023
1 parent d98ea78 commit c54274c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
14 changes: 11 additions & 3 deletions scripts/docker_build_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ fi


if [[ "${REFSPEC}" == "master" ]]; then
LATEST_TAG="latest"
LATEST_TAG="master"
fi

# get the latest release tag
if [ -n "${GITHUB_RELEASE_TAG_NAME}" ]; then
output=$(source ./scripts/tag_latest_release.sh "${GITHUB_RELEASE_TAG_NAME}" --dry-run) || true
SKIP_TAG=$(echo "${output}" | grep "SKIP_TAG" | cut -d'=' -f2)
if [[ "${SKIP_TAG}" == "SKIP_TAG::false" ]]; then
LATEST_TAG="latest-official"
LATEST_TAG="latest"
fi
fi

Expand Down Expand Up @@ -77,6 +77,14 @@ else
fi
set -x

# for the dev image, it's ok to tag master as latest-dev
# for production, we only want to tag the latest official release as latest
if [ "${LATEST_TAG}" = "master" ]; then
DEV_TAG="${REPO_NAME}:latest-dev"
else
DEV_TAG="${REPO_NAME}:${LATEST_TAG}-dev"
fi

#
# Build the dev image
#
Expand All @@ -87,7 +95,7 @@ docker buildx build --target dev \
--cache-to=type=local,ignore-error=true,dest=/tmp/superset \
-t "${REPO_NAME}:${SHA}-dev" \
-t "${REPO_NAME}:${REFSPEC}-dev" \
-t "${REPO_NAME}:${LATEST_TAG}-dev" \
-t "${DEV_TAG}" \
--platform linux/amd64 \
--label "sha=${SHA}" \
--label "built_at=$(date)" \
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/fixtures/bash_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def tag_latest_release(tag):
return result

@staticmethod
def docker_build_push(tag):
def docker_build_push(tag, branch):
bash_command = f"./scripts/docker_build_push.sh {tag}"
result = subprocess.run(
bash_command,
shell=True,
capture_output=True,
text=True,
env={"TEST_ENV": "true", "GITHUB_REF": "refs/heads/master"},
env={"TEST_ENV": "true", "GITHUB_REF": f"refs/heads/{branch}"},
)
return result
24 changes: 12 additions & 12 deletions tests/unit_tests/scripts/docker_build_push_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ def wrapped(*args, **kwargs):


@pytest.mark.parametrize(
"tag, expected_output",
"tag, expected_output, branch",
[
("1.0.0", "LATEST_TAG is latest"),
("2.1.0", "LATEST_TAG is latest"),
("2.1.1", "LATEST_TAG is latest-official"),
("3.0.0", "LATEST_TAG is latest-official"),
("2.1.0rc1", "LATEST_TAG is latest"),
("", "LATEST_TAG is latest"),
("2.1", "LATEST_TAG is latest"),
("does_not_exist", "LATEST_TAG is latest"),
("1.0.0", "LATEST_TAG is master", "master"),
("2.1.0", "LATEST_TAG is master", "master"),
("2.1.1", "LATEST_TAG is latest", "master"),
("3.0.0", "LATEST_TAG is latest", "master"),
("2.1.0rc1", "LATEST_TAG is 2.1.0", "2.1.0"),
("", "LATEST_TAG is foo", "foo"),
("2.1", "LATEST_TAG is 2.1", "2.1"),
("does_not_exist", "LATEST_TAG is does-not-exist", "does_not_exist"),
],
)
def test_tag_latest_release(tag, expected_output):
def test_tag_latest_release(tag, expected_output, branch):
with mock.patch(
"tests.unit_tests.fixtures.bash_mock.subprocess.run", wraps=wrapped
) as subprocess_mock:
result = BashMock.docker_build_push(tag)
result = BashMock.docker_build_push(tag, branch)

subprocess_mock.assert_called_once_with(
f"./scripts/docker_build_push.sh {tag}",
shell=True,
capture_output=True,
text=True,
env={"TEST_ENV": "true", "GITHUB_REF": "refs/heads/master"},
env={"TEST_ENV": "true", "GITHUB_REF": f"refs/heads/{branch}"},
)

assert re.search(expected_output, result.stdout, re.MULTILINE)

0 comments on commit c54274c

Please sign in to comment.