Repository: farost/typedb-dependencies
Pull request #1: Update 3.x docker image generation scripts
Author: login: krishnangovindraj
Created: 2025-04-28T17:18:50Z | Merged: 2025-04-30T13:48:27Z



Diff:
diff --git a/images/docker/BUILD b/images/docker/BUILD
index 3e8118fa0..8da73419a 100644
--- a/images/docker/BUILD
+++ b/images/docker/BUILD
@@ -3,6 +3,7 @@
 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
 
 load("//tool/checkstyle:rules.bzl", "checkstyle_test")
+exports_files(["assemble-docker.sh", "deploy-docker.sh"])
 
 checkstyle_test(
     name = "checkstyle",
diff --git a/images/docker/ubuntu-3x/assemble-docker.sh b/images/docker/assemble-docker.sh
similarity index 55%
rename from images/docker/ubuntu-3x/assemble-docker.sh
rename to images/docker/assemble-docker.sh
index 69ec86ecd..cdfdba1f8 100755
--- a/images/docker/ubuntu-3x/assemble-docker.sh
+++ b/images/docker/assemble-docker.sh
@@ -7,13 +7,12 @@ set -ex
 
 # Usage: ./assemble-docker.sh Dockerfile.amd64 amd64 3.1.0 typedb ubuntu
 
-DOCKERFILE=$1
+DOCKERFILE=$(realpath $1)
 PLATFORM=$2
-DOCKER_VERSION=$3
+TAG=$(cat $3)
 DOCKER_ORG=$4
 DOCKER_REPO=$5
-TAG="${DOCKER_ORG}/${DOCKER_REPO}:${DOCKER_VERSION}-${PLATFORM}"
-
-echo "Assembling image for ${PLATFORM}: ${TAG}"
-docker buildx build --platform "linux/${PLATFORM}" --load -f "${DOCKERFILE}" -t "${TAG}" .
-echo "Successfully assembled ${TAG}"
+FULL_TAG="${DOCKER_ORG}/${DOCKER_REPO}:${TAG}"
+echo "Assembling image for ${PLATFORM}: ${FULL_TAG}"
+docker buildx build --platform "linux/${PLATFORM}" --load -f $DOCKERFILE -t "${FULL_TAG}" .
+echo "Successfully assembled ${FULL_TAG}"
diff --git a/images/docker/ubuntu-3x/deploy-docker.sh b/images/docker/deploy-docker.sh
similarity index 66%
rename from images/docker/ubuntu-3x/deploy-docker.sh
rename to images/docker/deploy-docker.sh
index 8668c1243..b62bd65e9 100755
--- a/images/docker/ubuntu-3x/deploy-docker.sh
+++ b/images/docker/deploy-docker.sh
@@ -7,12 +7,11 @@ set -ex
 
 # Usage: ./deploy-docker.sh amd64 3.1.0 typedb ubuntu
 
-PLATFORM=$1
-DOCKER_VERSION=$2
-DOCKER_ORG=$3
-DOCKER_REPO=$4
-TAG="${DOCKER_ORG}/${DOCKER_REPO}:${DOCKER_VERSION}-${PLATFORM}"
+TAG=$(cat $1)
+DOCKER_ORG=$2
+DOCKER_REPO=$3
+TAG="${DOCKER_ORG}/${DOCKER_REPO}:${TAG}"
 
-echo "Deploying image for ${PLATFORM}: ${TAG}"
+echo "Deploying image: ${TAG}"
 docker push "${TAG}"
 echo "Successfully pushed ${TAG}"
diff --git a/images/docker/ubuntu-2x/BUILD b/images/docker/ubuntu-2x/BUILD
index 32a381b3c..9fcc91175 100644
--- a/images/docker/ubuntu-2x/BUILD
+++ b/images/docker/ubuntu-2x/BUILD
@@ -6,30 +6,56 @@
 load("//images/docker/ubuntu-2x:deployment.bzl", deployment_docker = "deployment")
 load("//tool/checkstyle:rules.bzl", "checkstyle_test")
 
-sh_library(
-    name = "version-docker",
-    srcs = ["version-docker.sh"],
+# Gen-rules to generate <VERSION>-<PLATFORM> as tag
+genrule(
+    name = "tag-amd64",
+    srcs = [":VERSION"],
+    outs = ["tag-amd64.txt"],
+    cmd = "cat $(location :VERSION) | tr -d '\n' > $(location tag-amd64.txt) && echo \"-amd64\" >> $(location tag-amd64.txt)",
+)
+genrule(
+    name = "tag-arm64",
+    srcs = [":VERSION"],
+    outs = ["tag-arm64.txt"],
+    cmd = "cat $(location :VERSION) | tr -d '\n' > $(location tag-arm64.txt) && echo \"-arm64\" >> $(location tag-arm64.txt)",
+)
+
+sh_binary(
+    name = "assemble-docker-amd64",
+    srcs = ["//images/docker:assemble-docker.sh"],
+    data = ["Dockerfile.amd64", "VERSION", "tag-amd64"],
+    deps = [":tag-amd64"],
+    args = ["$(location Dockerfile.amd64)", "amd64", "$(location :tag-amd64)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
+)
+
+sh_binary(
+    name = "assemble-docker-arm64",
+    srcs = ["//images/docker:assemble-docker.sh"],
+    data = ["Dockerfile.arm64", "VERSION", "tag-arm64"],
+    deps = [":tag-arm64"],
+    args = ["$(location Dockerfile.arm64)", "arm64", "$(location :tag-arm64)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
 )
 
 sh_binary(
-    name = "assemble-docker",
-    srcs = ["assemble-docker.sh"],
-    data = ["Dockerfile"],
-    deps = [":version-docker"],
-    args = ["$(location Dockerfile)", "$(location :version-docker)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
+    name = "deploy-docker-amd64",
+    deps = [],
+    srcs = ["//images/docker:deploy-docker.sh"],
+    data = ["VERSION", "tag-amd64"],
+    args = ["$(location :tag-amd64)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
 )
 
 sh_binary(
-    name = "deploy-docker",
-    deps = [":version-docker"],
-    srcs = ["deploy-docker.sh"],
-    args = ["$(location :version-docker)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
+    name = "deploy-docker-arm64",
+    deps = [],
+    srcs = ["//images/docker:deploy-docker.sh"],
+    data = ["VERSION", "tag-arm64"],
+    args = ["$(location :tag-arm64)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
 )
 
 checkstyle_test(
     name = "checkstyle",
     include = glob(["*"]),
-    exclude = glob(["*.md"]),
+    exclude = glob(["*.md", "VERSION"]),
     license_type = "mpl-header",
     size = "small",
 )
diff --git a/images/docker/ubuntu-2x/Dockerfile b/images/docker/ubuntu-2x/Dockerfile.amd64
similarity index 78%
rename from images/docker/ubuntu-2x/Dockerfile
rename to images/docker/ubuntu-2x/Dockerfile.amd64
index e0b9f3955..04d1b457b 100644
--- a/images/docker/ubuntu-2x/Dockerfile
+++ b/images/docker/ubuntu-2x/Dockerfile.amd64
@@ -3,5 +3,5 @@
 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
 
 
-FROM ubuntu:focal-20210723
+FROM ubuntu@sha256:1e48201ccc2ab83afc435394b3bf70af0fa0055215c1e26a5da9b50a1ae367c9
 RUN apt-get -y update && apt-get install -y openjdk-11-jre-headless && rm -rf /var/lib/apt/lists
diff --git a/images/docker/ubuntu-2x/deploy-docker.sh b/images/docker/ubuntu-2x/Dockerfile.arm64
old mode 100755
new mode 100644
similarity index 52%
rename from images/docker/ubuntu-2x/deploy-docker.sh
rename to images/docker/ubuntu-2x/Dockerfile.arm64
index 91645b90b..f0a093a70
--- a/images/docker/ubuntu-2x/deploy-docker.sh
+++ b/images/docker/ubuntu-2x/Dockerfile.arm64
@@ -1,14 +1,7 @@
-#!/usr/bin/env bash
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
 
 
-set -ex
-
-DOCKER_VERSION_LIB=$1
-DOCKER_VERSION=`$DOCKER_VERSION_LIB`
-DOCKER_ORG=$2
-DOCKER_REPO=$3
-
-docker push $DOCKER_ORG/$DOCKER_REPO:$DOCKER_VERSION
+FROM ubuntu@sha256:c0dd38485ed8b6e149d2fc935d1c61a3b750cda3b3eace0ad6df4abe33fa2b90
+RUN apt-get -y update && apt-get install -y openjdk-11-jre-headless && rm -rf /var/lib/apt/lists
diff --git a/images/docker/ubuntu-2x/VERSION b/images/docker/ubuntu-2x/VERSION
new file mode 100644
index 000000000..f01356823
--- /dev/null
+++ b/images/docker/ubuntu-2x/VERSION
@@ -0,0 +1 @@
+2.29.0
diff --git a/images/docker/ubuntu-2x/assemble-docker.sh b/images/docker/ubuntu-2x/assemble-docker.sh
deleted file mode 100755
index 1aef65635..000000000
--- a/images/docker/ubuntu-2x/assemble-docker.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env bash
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at https://mozilla.org/MPL/2.0/.
-
-
-set -ex
-
-DOCKER_VERSION_LIB=$2
-DOCKER_VERSION=`$DOCKER_VERSION_LIB`
-DOCKER_ORG=$3
-DOCKER_REPO=$4
-
-docker build -f $1 -t $DOCKER_ORG/$DOCKER_REPO:$DOCKER_VERSION .
diff --git a/images/docker/ubuntu-2x/version-docker.sh b/images/docker/ubuntu-2x/version-docker.sh
deleted file mode 100755
index e5df4498e..000000000
--- a/images/docker/ubuntu-2x/version-docker.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at https://mozilla.org/MPL/2.0/.
-
-
-echo "$(git -C $BUILD_WORKSPACE_DIRECTORY rev-parse HEAD)"
diff --git a/images/docker/ubuntu-3x/BUILD b/images/docker/ubuntu-3x/BUILD
index e4304dd86..f7e27707e 100644
--- a/images/docker/ubuntu-3x/BUILD
+++ b/images/docker/ubuntu-3x/BUILD
@@ -1,9 +1,58 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
-
 load("//tool/checkstyle:rules.bzl", "checkstyle_test")
 
+# Same repository as 2.x images.
+load("//images/docker/ubuntu-2x:deployment.bzl", deployment_docker = "deployment")
+
+# Gen-rules to generate <VERSION>-<PLATFORM> as tag
+genrule(
+    name = "tag-amd64",
+    srcs = [":VERSION"],
+    outs = ["tag-amd64.txt"],
+    cmd = "cat $(location :VERSION) | tr -d '\n' > $(location tag-amd64.txt) && echo \"-amd64\" >> $(location tag-amd64.txt)",
+)
+genrule(
+    name = "tag-arm64",
+    srcs = [":VERSION"],
+    outs = ["tag-arm64.txt"],
+    cmd = "cat $(location :VERSION) | tr -d '\n' > $(location tag-arm64.txt) && echo \"-arm64\" >> $(location tag-arm64.txt)",
+)
+
+
+sh_binary(
+    name = "assemble-docker-amd64",
+    srcs = ["//images/docker:assemble-docker.sh"],
+    data = ["Dockerfile.amd64", "VERSION", "tag-amd64"],
+    deps = [],
+    args = ["$(location Dockerfile.amd64)", "amd64", "$(location :tag-amd64)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
+)
+
+sh_binary(
+    name = "assemble-docker-arm64",
+    srcs = ["//images/docker:assemble-docker.sh"],
+    data = ["Dockerfile.arm64", "VERSION", "tag-arm64"],
+    deps = [],
+    args = ["$(location Dockerfile.arm64)", "arm64", "$(location :tag-arm64)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
+)
+
+sh_binary(
+    name = "deploy-docker-amd64",
+    deps = [],
+    srcs = ["//images/docker:deploy-docker.sh"],
+    data = ["VERSION", "tag-amd64"],
+    args = ["$(location :tag-amd64)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
+)
+
+sh_binary(
+    name = "deploy-docker-arm64",
+    deps = [],
+    srcs = ["//images/docker:deploy-docker.sh"],
+    data = ["VERSION", "tag-arm64"],
+    args = ["$(location :tag-arm64)", deployment_docker["docker.organisation"], deployment_docker["docker.repository"]]
+)
+
 checkstyle_test(
     name = "checkstyle",
     include = glob(["*"]),
diff --git a/images/docker/ubuntu-3x/VERSION b/images/docker/ubuntu-3x/VERSION
index 13d683ccb..944880fa1 100644
--- a/images/docker/ubuntu-3x/VERSION
+++ b/images/docker/ubuntu-3x/VERSION
@@ -1 +1 @@
-3.0.1
\ No newline at end of file
+3.2.0
diff --git a/images/docker/ubuntu-3x/assemble-deploy-all.sh b/images/docker/ubuntu-3x/assemble-deploy-all.sh
index 2f8e7223b..d92d5f151 100755
--- a/images/docker/ubuntu-3x/assemble-deploy-all.sh
+++ b/images/docker/ubuntu-3x/assemble-deploy-all.sh
@@ -29,8 +29,10 @@ DOCKER_REPO=ubuntu
 PLATFORMS=("amd64" "arm64") # Update `docker manifest` commands below if it's changed
 
 for ARCH in "${PLATFORMS[@]}"; do
-  ./assemble-docker.sh "Dockerfile.${ARCH}" "${ARCH}" "${VERSION}" "${DOCKER_ORG}" "${DOCKER_REPO}"
-  ./deploy-docker.sh "${ARCH}" "${VERSION}" "${DOCKER_ORG}" "${DOCKER_REPO}"
+  ASSEMBLE_TARGET="//images/docker/ubuntu-3x:assemble-docker-${ARCH}"
+  DEPLOY_TARGET="//images/docker/ubuntu-3x:deploy-docker-${ARCH}"
+  bazel run $ASSEMBLE_TARGET
+  bazel run $DEPLOY_TARGET
 done
 
 TAG="${DOCKER_ORG}/${DOCKER_REPO}:${VERSION}"


Reviews:
user: login: krishnangovindraj
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-28T17:20:26Z
user: login: farost
body: Seems to be fair, I didn't want to touch 2.x too much, but if you're confident that this arch split is good for it, I don't have anything to say against it
state: APPROVED
author_association: OWNER
submitted_at: 2025-04-29T15:47:21Z
user: login: krishnangovindraj
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-29T16:43:41Z

Review comments:
diff_hunk: @@ -7,13 +7,12 @@ set -ex
 
 # Usage: ./assemble-docker.sh Dockerfile.amd64 amd64 3.1.0 typedb ubuntu
 
-DOCKERFILE=$1
+DOCKERFILE=$(realpath $1)
 PLATFORM=$2
-DOCKER_VERSION=$3
+TAG=$(cat $3)
path: images/docker/assemble-docker.sh
user: login: krishnangovindraj
body: I've worked it back into bazel, so I sadly need to rely on a file for the tag.
I've removed the assumption that we want VERSION-PLATFORM as tag, and just accept a tag directly.
created_at: 2025-04-28T17:20:26Z
author_association: NONE
diff_hunk: @@ -29,8 +29,11 @@ DOCKER_REPO=ubuntu
 PLATFORMS=("amd64" "arm64") # Update `docker manifest` commands below if it's changed
 
 for ARCH in "${PLATFORMS[@]}"; do
-  ./assemble-docker.sh "Dockerfile.${ARCH}" "${ARCH}" "${VERSION}" "${DOCKER_ORG}" "${DOCKER_REPO}"
-  ./deploy-docker.sh "${ARCH}" "${VERSION}" "${DOCKER_ORG}" "${DOCKER_REPO}"
+  # Should we just invoke the bazel targets here instead?
path: images/docker/ubuntu-3x/assemble-deploy-all.sh
user: login: farost
body: ?
created_at: 2025-04-29T15:46:06Z
author_association: OWNER
diff_hunk: @@ -29,8 +29,11 @@ DOCKER_REPO=ubuntu
 PLATFORMS=("amd64" "arm64") # Update `docker manifest` commands below if it's changed
 
 for ARCH in "${PLATFORMS[@]}"; do
-  ./assemble-docker.sh "Dockerfile.${ARCH}" "${ARCH}" "${VERSION}" "${DOCKER_ORG}" "${DOCKER_REPO}"
-  ./deploy-docker.sh "${ARCH}" "${VERSION}" "${DOCKER_ORG}" "${DOCKER_REPO}"
+  # Should we just invoke the bazel targets here instead?
path: images/docker/ubuntu-3x/assemble-deploy-all.sh
user: login: krishnangovindraj
body: Oopsies. Removed that.

created_at: 2025-04-29T16:43:41Z
author_association: NONE

PR comments:
user: login: krishnangovindraj
created_at: 2025-04-29T16:45:24Z
body: I've not tested it end to end yet (i.e., I've not deployed and built TypeDB docker images on top)
But I did verify that each target is the right architecture. So it should be good enough because I can't imagine it breaking at any other point.
author_association: NONE
user: login: farost
created_at: 2025-04-30T09:05:57Z
body: Could you check the checkstyle failure?
author_association: OWNER