2024-01-31 02:03:25 -05:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
# distributed with this work for additional information
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
SHA = "22e7c602b9aa321ec7e0df4bb0033048664dcdf0"
|
|
|
|
PR_ID = "666"
|
|
|
|
OLD_REL = "2.1.0"
|
|
|
|
NEW_REL = "2.1.1"
|
|
|
|
REPO = "apache/superset"
|
|
|
|
|
|
|
|
# Add the 'scripts' directory to sys.path
|
|
|
|
scripts_dir = os.path.abspath(
|
|
|
|
os.path.join(os.path.dirname(__file__), "../../../scripts")
|
|
|
|
)
|
|
|
|
sys.path.append(scripts_dir)
|
|
|
|
|
2024-04-24 20:19:53 -04:00
|
|
|
import build_docker as docker_utils # Replace with the actual function name # noqa: E402
|
2024-01-31 02:03:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def set_env_var():
|
|
|
|
os.environ["TEST_ENV"] = "true"
|
|
|
|
yield
|
|
|
|
del os.environ["TEST_ENV"]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"release, expected_bool",
|
|
|
|
[
|
|
|
|
("2.1.0", False),
|
|
|
|
("2.1.1", True),
|
|
|
|
("1.0.0", False),
|
|
|
|
("3.0.0", True),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_is_latest_release(release, expected_bool):
|
|
|
|
assert docker_utils.is_latest_release(release) == expected_bool
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2024-02-08 23:58:36 -05:00
|
|
|
"build_preset, build_platforms, sha, build_context, build_context_ref, expected_tags",
|
2024-01-31 02:03:25 -05:00
|
|
|
[
|
|
|
|
# PRs
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/arm64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"pull_request",
|
|
|
|
PR_ID,
|
2024-02-01 21:04:23 -05:00
|
|
|
[f"{REPO}:22e7c60-arm", f"{REPO}:{SHA}-arm", f"{REPO}:pr-{PR_ID}-arm"],
|
2024-01-31 02:03:25 -05:00
|
|
|
),
|
|
|
|
(
|
|
|
|
"ci",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"pull_request",
|
|
|
|
PR_ID,
|
2024-02-01 21:04:23 -05:00
|
|
|
[f"{REPO}:22e7c60-ci", f"{REPO}:{SHA}-ci", f"{REPO}:pr-{PR_ID}-ci"],
|
2024-01-31 02:03:25 -05:00
|
|
|
),
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"pull_request",
|
|
|
|
PR_ID,
|
2024-02-01 21:04:23 -05:00
|
|
|
[f"{REPO}:22e7c60", f"{REPO}:{SHA}", f"{REPO}:pr-{PR_ID}"],
|
2024-01-31 02:03:25 -05:00
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/arm64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"pull_request",
|
|
|
|
PR_ID,
|
2024-02-01 21:04:23 -05:00
|
|
|
[
|
|
|
|
f"{REPO}:22e7c60-dev-arm",
|
|
|
|
f"{REPO}:{SHA}-dev-arm",
|
|
|
|
f"{REPO}:pr-{PR_ID}-dev-arm",
|
|
|
|
],
|
2024-01-31 02:03:25 -05:00
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"pull_request",
|
|
|
|
PR_ID,
|
2024-02-01 21:04:23 -05:00
|
|
|
[f"{REPO}:22e7c60-dev", f"{REPO}:{SHA}-dev", f"{REPO}:pr-{PR_ID}-dev"],
|
2024-01-31 02:03:25 -05:00
|
|
|
),
|
|
|
|
# old releases
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/arm64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"release",
|
|
|
|
OLD_REL,
|
|
|
|
[f"{REPO}:22e7c60-arm", f"{REPO}:{SHA}-arm", f"{REPO}:{OLD_REL}-arm"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"release",
|
|
|
|
OLD_REL,
|
|
|
|
[f"{REPO}:22e7c60", f"{REPO}:{SHA}", f"{REPO}:{OLD_REL}"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/arm64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"release",
|
|
|
|
OLD_REL,
|
|
|
|
[
|
|
|
|
f"{REPO}:22e7c60-dev-arm",
|
|
|
|
f"{REPO}:{SHA}-dev-arm",
|
|
|
|
f"{REPO}:{OLD_REL}-dev-arm",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"release",
|
|
|
|
OLD_REL,
|
|
|
|
[f"{REPO}:22e7c60-dev", f"{REPO}:{SHA}-dev", f"{REPO}:{OLD_REL}-dev"],
|
|
|
|
),
|
|
|
|
# new releases
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/arm64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"release",
|
|
|
|
NEW_REL,
|
|
|
|
[
|
|
|
|
f"{REPO}:22e7c60-arm",
|
|
|
|
f"{REPO}:{SHA}-arm",
|
|
|
|
f"{REPO}:{NEW_REL}-arm",
|
|
|
|
f"{REPO}:latest-arm",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"release",
|
|
|
|
NEW_REL,
|
|
|
|
[f"{REPO}:22e7c60", f"{REPO}:{SHA}", f"{REPO}:{NEW_REL}", f"{REPO}:latest"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/arm64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"release",
|
|
|
|
NEW_REL,
|
|
|
|
[
|
|
|
|
f"{REPO}:22e7c60-dev-arm",
|
|
|
|
f"{REPO}:{SHA}-dev-arm",
|
|
|
|
f"{REPO}:{NEW_REL}-dev-arm",
|
|
|
|
f"{REPO}:latest-dev-arm",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"release",
|
|
|
|
NEW_REL,
|
|
|
|
[
|
|
|
|
f"{REPO}:22e7c60-dev",
|
|
|
|
f"{REPO}:{SHA}-dev",
|
|
|
|
f"{REPO}:{NEW_REL}-dev",
|
|
|
|
f"{REPO}:latest-dev",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
# merge on master
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/arm64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"push",
|
|
|
|
"master",
|
|
|
|
[f"{REPO}:22e7c60-arm", f"{REPO}:{SHA}-arm", f"{REPO}:master-arm"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"push",
|
|
|
|
"master",
|
|
|
|
[f"{REPO}:22e7c60", f"{REPO}:{SHA}", f"{REPO}:master"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/arm64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"push",
|
|
|
|
"master",
|
|
|
|
[
|
|
|
|
f"{REPO}:22e7c60-dev-arm",
|
|
|
|
f"{REPO}:{SHA}-dev-arm",
|
|
|
|
f"{REPO}:master-dev-arm",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
SHA,
|
|
|
|
"push",
|
|
|
|
"master",
|
|
|
|
[f"{REPO}:22e7c60-dev", f"{REPO}:{SHA}-dev", f"{REPO}:master-dev"],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_get_docker_tags(
|
2024-02-08 23:58:36 -05:00
|
|
|
build_preset, build_platforms, sha, build_context, build_context_ref, expected_tags
|
2024-01-31 02:03:25 -05:00
|
|
|
):
|
|
|
|
tags = docker_utils.get_docker_tags(
|
2024-02-08 23:58:36 -05:00
|
|
|
build_preset, build_platforms, sha, build_context, build_context_ref
|
2024-01-31 02:03:25 -05:00
|
|
|
)
|
|
|
|
for tag in expected_tags:
|
|
|
|
assert tag in tags
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2024-02-08 23:58:36 -05:00
|
|
|
"build_preset, build_platforms, is_authenticated, sha, build_context, build_context_ref, contains",
|
2024-01-31 02:03:25 -05:00
|
|
|
[
|
|
|
|
(
|
|
|
|
"lean",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
True,
|
|
|
|
SHA,
|
|
|
|
"push",
|
|
|
|
"master",
|
|
|
|
["--push", f"-t {REPO}:master "],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"dev",
|
2024-02-08 23:58:36 -05:00
|
|
|
["linux/amd64"],
|
2024-01-31 02:03:25 -05:00
|
|
|
False,
|
|
|
|
SHA,
|
|
|
|
"push",
|
|
|
|
"master",
|
2024-02-14 19:58:47 -05:00
|
|
|
["--load", f"-t {REPO}:master-dev ", "--target dev"],
|
2024-01-31 02:03:25 -05:00
|
|
|
),
|
2024-02-08 23:58:36 -05:00
|
|
|
# multi-platform
|
|
|
|
(
|
|
|
|
"lean",
|
|
|
|
["linux/arm64", "linux/amd64"],
|
|
|
|
True,
|
|
|
|
SHA,
|
|
|
|
"push",
|
|
|
|
"master",
|
2024-04-24 20:19:53 -04:00
|
|
|
["--platform linux/arm64,linux/amd64"],
|
2024-02-08 23:58:36 -05:00
|
|
|
),
|
2024-01-31 02:03:25 -05:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_get_docker_command(
|
|
|
|
build_preset,
|
2024-02-08 23:58:36 -05:00
|
|
|
build_platforms,
|
2024-01-31 02:03:25 -05:00
|
|
|
is_authenticated,
|
|
|
|
sha,
|
|
|
|
build_context,
|
|
|
|
build_context_ref,
|
|
|
|
contains,
|
|
|
|
):
|
|
|
|
cmd = docker_utils.get_docker_command(
|
|
|
|
build_preset,
|
2024-02-08 23:58:36 -05:00
|
|
|
build_platforms,
|
2024-01-31 02:03:25 -05:00
|
|
|
is_authenticated,
|
|
|
|
sha,
|
|
|
|
build_context,
|
|
|
|
build_context_ref,
|
|
|
|
)
|
|
|
|
for s in contains:
|
|
|
|
assert s in cmd
|