Skip to content

Commit

Permalink
Updates postgres versions for Docker images (#340)
Browse files Browse the repository at this point in the history
* Updates file path with new postgres versions
  • Loading branch information
gurkanindibay authored Sep 21, 2023
1 parent dbd7fef commit 4d60073
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 51 deletions.
14 changes: 7 additions & 7 deletions packaging_automation/publish_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class DockerImageType(Enum):
latest = 1
alpine = 2
nightly = 3
postgres_13 = 4
postgres_14 = 5
postgres_14 = 4
postgres_15 = 5


class ManualTriggerType(Enum):
Expand All @@ -55,16 +55,16 @@ class ScheduleType(Enum):
"docker-tag": "alpine",
"schedule-type": ScheduleType.regular,
},
DockerImageType.postgres_13: {
"file-name": "postgres-13/Dockerfile",
"docker-tag": "pg13",
"schedule-type": ScheduleType.regular,
},
DockerImageType.postgres_14: {
"file-name": "postgres-14/Dockerfile",
"docker-tag": "pg14",
"schedule-type": ScheduleType.regular,
},
DockerImageType.postgres_15: {
"file-name": "postgres-15/Dockerfile",
"docker-tag": "pg15",
"schedule-type": ScheduleType.regular,
},
DockerImageType.nightly: {
"file-name": "nightly/Dockerfile",
"docker-tag": "nightly",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ RUN apt-get update \
curl \
&& curl -s https://install.citusdata.com/community/deb.sh | bash \
&& apt-get install -y postgresql-$PG_MAJOR-citus-{{project_minor_version}}=$CITUS_VERSION \
postgresql-$PG_MAJOR-hll=2.17.citus-1 \
postgresql-$PG_MAJOR-topn=2.5.0.citus-1 \
postgresql-$PG_MAJOR-hll=2.18.citus-1 \
postgresql-$PG_MAJOR-topn=2.6.0.citus-1 \
&& apt-get purge -y --auto-remove curl \
&& rm -rf /var/lib/apt/lists/*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is auto generated from it's template,
# see citusdata/tools/packaging_automation/templates/docker/postgres-13/postgres-13.tmpl.dockerfile.
# see citusdata/tools/packaging_automation/templates/docker/postgres-15/postgres-15.tmpl.dockerfile.
FROM postgres:{{postgres_version}}
ARG VERSION={{project_version}}
LABEL maintainer="Citus Data https://citusdata.com" \
Expand All @@ -20,8 +20,8 @@ RUN apt-get update \
curl \
&& curl -s https://install.citusdata.com/community/deb.sh | bash \
&& apt-get install -y postgresql-$PG_MAJOR-citus-{{project_minor_version}}=$CITUS_VERSION \
postgresql-$PG_MAJOR-hll=2.17.citus-1 \
postgresql-$PG_MAJOR-topn=2.5.0.citus-1 \
postgresql-$PG_MAJOR-hll=2.18.citus-1 \
postgresql-$PG_MAJOR-topn=2.6.0.citus-1 \
&& apt-get purge -y --auto-remove curl \
&& rm -rf /var/lib/apt/lists/*

Expand Down
30 changes: 15 additions & 15 deletions packaging_automation/tests/test_publish_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
publish_nightly_docker_image,
)

NON_DEFAULT_BRANCH_NAME = "10.0.3_test"
NON_DEFAULT_BRANCH_NAME = "12.0.0_test"
DEFAULT_BRANCH_NAME = "master"
TAG_NAME = "v10.0.3"
INVALID_TAG_NAME = "v10.x"
TAG_NAME = "v12.0.0"
INVALID_TAG_NAME = "v12.x"
DOCKER_IMAGE_NAME = "citusdata/citus"
docker_client = docker.from_env()

Expand Down Expand Up @@ -49,9 +49,9 @@ def test_decode_tag_parts():
tag_parts = decode_tag_parts(TAG_NAME)
assert (
len(tag_parts) == 3
and tag_parts[0] == "10"
and tag_parts[0] == "12"
and tag_parts[1] == "0"
and tag_parts[2] == "3"
and tag_parts[2] == "0"
)

with pytest.raises(ValueError):
Expand All @@ -60,12 +60,12 @@ def test_decode_tag_parts():

def test_get_image_tag():
image_name = get_image_tag(remove_prefix(TAG_NAME, "v"), DockerImageType.latest)
assert image_name == "10.0.3"
assert image_name == "12.0.0"

image_name = get_image_tag(
remove_prefix(TAG_NAME, "v"), DockerImageType.postgres_13
remove_prefix(TAG_NAME, "v"), DockerImageType.postgres_15
)
assert image_name == "10.0.3-pg13"
assert image_name == "12.0.0-pg15"


def test_publish_main_docker_images():
Expand All @@ -86,10 +86,10 @@ def test_publish_tagged_docker_images_latest():
os.chdir("docker")
try:
run_with_output("git checkout -b docker-unit-test")
publish_tagged_docker_images(DockerImageType.latest, "v10.0.3", False)
docker_client.images.get("citusdata/citus:10")
docker_client.images.get("citusdata/citus:10.0")
docker_client.images.get("citusdata/citus:10.0.3")
publish_tagged_docker_images(DockerImageType.latest, "v12.0.0", False)
docker_client.images.get("citusdata/citus:12")
docker_client.images.get("citusdata/citus:12.0")
docker_client.images.get("citusdata/citus:12.0.0")
finally:
run_with_output("git checkout master")
run_with_output("git branch -D docker-unit-test")
Expand All @@ -101,9 +101,9 @@ def test_publish_tagged_docker_images_alpine():
try:
run_with_output("git checkout -b docker-unit-test")
publish_tagged_docker_images(DockerImageType.alpine, TAG_NAME, False)
docker_client.images.get("citusdata/citus:10-alpine")
docker_client.images.get("citusdata/citus:10.0-alpine")
docker_client.images.get("citusdata/citus:10.0.3-alpine")
docker_client.images.get("citusdata/citus:12-alpine")
docker_client.images.get("citusdata/citus:12.0-alpine")
docker_client.images.get("citusdata/citus:12.0.0-alpine")
finally:
run_with_output("git checkout master")
run_with_output("git branch -D docker-unit-test")
Expand Down
19 changes: 9 additions & 10 deletions packaging_automation/tests/test_update_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
update_docker_file_for_latest_postgres,
update_regular_docker_compose_file,
update_docker_file_alpine,
update_docker_file_for_postgres15,
update_docker_file_for_postgres14,
update_docker_file_for_postgres13,
update_changelog,
)

BASE_PATH = os.getenv("BASE_PATH", default=pathlib2.Path(__file__).parents[2])
TEST_BASE_PATH = f"{BASE_PATH}/docker"
PROJECT_VERSION = "10.0.3"
PROJECT_VERSION = "12.0.0"

POSTGRES_14_VERSION = "14.5"
POSTGRES_13_VERSION = "13.8"
POSTGRES_15_VERSION = "15.4"
POSTGRES_14_VERSION = "14.9"

PROJECT_NAME = "citus"
version_details = get_version_details(PROJECT_VERSION)
Expand Down Expand Up @@ -120,19 +120,19 @@ def test_update_docker_file_for_postgres14():
assert len(lines) == 42


def test_update_docker_file_for_postgres13():
update_docker_file_for_postgres13(
PROJECT_VERSION, TEMPLATE_PATH, TEST_BASE_PATH, POSTGRES_13_VERSION
def test_update_docker_file_for_postgres15():
update_docker_file_for_postgres15(
PROJECT_VERSION, TEMPLATE_PATH, TEST_BASE_PATH, POSTGRES_15_VERSION
)
with open(
f"{TEST_BASE_PATH}/postgres-13/Dockerfile",
f"{TEST_BASE_PATH}/postgres-15/Dockerfile",
"r",
encoding=DEFAULT_ENCODING_FOR_FILE_HANDLING,
errors=DEFAULT_UNICODE_ERROR_HANDLER,
) as reader:
content = reader.read()
lines = content.splitlines()
assert lines[2].strip() == f"FROM postgres:{POSTGRES_13_VERSION}"
assert lines[2].strip() == f"FROM postgres:{POSTGRES_15_VERSION}"
assert lines[3].strip() == f"ARG VERSION={PROJECT_VERSION}"
assert (
f"postgresql-$PG_MAJOR-{PROJECT_NAME}-"
Expand Down Expand Up @@ -179,4 +179,3 @@ def test_pkgvar_postgres_version_existence():
config = dotenv_values(PKGVARS_FILE)
assert config["postgres_15_version"]
assert config["postgres_14_version"]
assert config["postgres_13_version"]
28 changes: 14 additions & 14 deletions packaging_automation/update_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ class SupportedDockerImages(Enum):
latest = 1
docker_compose = 2
alpine = 3
postgres13 = 4
postgres14 = 5
postgres14 = 4
postgres15 = 5


docker_templates = {
SupportedDockerImages.latest: "latest/latest.tmpl.dockerfile",
SupportedDockerImages.docker_compose: "latest/docker-compose.tmpl.yml",
SupportedDockerImages.alpine: "alpine/alpine.tmpl.dockerfile",
SupportedDockerImages.postgres13: "postgres-13/postgres-13.tmpl.dockerfile",
SupportedDockerImages.postgres14: "postgres-14/postgres-14.tmpl.dockerfile",
SupportedDockerImages.postgres15: "postgres-15/postgres-15.tmpl.dockerfile",
}

docker_outputs = {
SupportedDockerImages.latest: "Dockerfile",
SupportedDockerImages.docker_compose: "docker-compose.yml",
SupportedDockerImages.alpine: "alpine/Dockerfile",
SupportedDockerImages.postgres13: "postgres-13/Dockerfile",
SupportedDockerImages.postgres14: "postgres-14/Dockerfile",
SupportedDockerImages.postgres15: "postgres-15/Dockerfile",
}

BASE_PATH = pathlib2.Path(__file__).parent.absolute()
Expand Down Expand Up @@ -99,19 +99,19 @@ def update_docker_file_alpine(
write_to_file(content, dest_file_name)


def update_docker_file_for_postgres13(
def update_docker_file_for_postgres15(
project_version: str, template_path: str, exec_path: str, postgres_version: str
):
minor_version = get_minor_project_version_for_docker(project_version)
debian_project_version = project_version.replace("_", "-")
content = process_template_file_with_minor(
debian_project_version,
template_path,
docker_templates[SupportedDockerImages.postgres13],
docker_templates[SupportedDockerImages.postgres15],
minor_version,
postgres_version,
)
dest_file_name = f"{exec_path}/{docker_outputs[SupportedDockerImages.postgres13]}"
dest_file_name = f"{exec_path}/{docker_outputs[SupportedDockerImages.postgres15]}"
create_directory_if_not_exists(dest_file_name)
write_to_file(content, dest_file_name)

Expand Down Expand Up @@ -157,7 +157,7 @@ def update_changelog(project_version: str, exec_path: str):
encoding=DEFAULT_ENCODING_FOR_FILE_HANDLING,
errors=DEFAULT_UNICODE_ERROR_HANDLER,
) as reader:
if not (f"({project_version}" in reader.readline()):
if f"({project_version}" not in reader.readline():
reader.seek(0, 0)
old_changelog = reader.read()
changelog = f"{latest_changelog}{old_changelog}"
Expand All @@ -174,12 +174,12 @@ def update_all_docker_files(project_version: str, exec_path: str):
pkgvars_file = f"{exec_path}/pkgvars"

(
postgres_16_version,
postgres_15_version,
postgres_14_version,
postgres_13_version,
) = read_postgres_versions(pkgvars_file)

latest_postgres_version = postgres_15_version
latest_postgres_version = postgres_16_version

update_docker_file_for_latest_postgres(
project_version, template_path, exec_path, latest_postgres_version
Expand All @@ -188,21 +188,21 @@ def update_all_docker_files(project_version: str, exec_path: str):
update_docker_file_alpine(
project_version, template_path, exec_path, latest_postgres_version
)
update_docker_file_for_postgres13(
project_version, template_path, exec_path, postgres_13_version
)
update_docker_file_for_postgres14(
project_version, template_path, exec_path, postgres_14_version
)
update_docker_file_for_postgres15(
project_version, template_path, exec_path, postgres_15_version
)
update_changelog(project_version, exec_path)


def read_postgres_versions(pkgvars_file: str) -> Tuple[str, str, str]:
config = dotenv_values(pkgvars_file)
return (
config["postgres_16_version"],
config["postgres_15_version"],
config["postgres_14_version"],
config["postgres_13_version"],
)


Expand Down

0 comments on commit 4d60073

Please sign in to comment.