From b4ef4e099f757044b4be5be3c40c4035d6d17ba0 Mon Sep 17 00:00:00 2001 From: ChenXing Yang <20001020ycx@gmail.com> Date: Wed, 8 Jul 2026 10:26:46 -0400 Subject: [PATCH 1/3] build: Add a Taskfile to build the Spider service images. Adds `taskfiles/docker.yaml` (wired into the root `taskfile.yaml` as the `docker` namespace) with `build`, `build-storage`, `build-scheduler`, and `build-worker` tasks that delegate to `tools/docker/build.sh `. For each service the script builds the matching multi-stage Dockerfile target, records the built image's ID to `build/spider--image.id` (so a local docker-compose deployment can pin the exact image), tags it `spider-:dev--`, and removes the previously built image. The script closely mirrors CLP's `tools/docker-images/clp-package/build.sh`, omitting the Ubuntu-codename detection (Spider pins `ubuntu:jammy`) and the Git OCI labels (Spider's CI applies labels via `docker/metadata-action`). --- taskfile.yaml | 1 + taskfiles/docker.yaml | 23 +++++++++++++++++++ tools/docker/build.sh | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 taskfiles/docker.yaml create mode 100755 tools/docker/build.sh diff --git a/taskfile.yaml b/taskfile.yaml index cca2a76d..82302511 100644 --- a/taskfile.yaml +++ b/taskfile.yaml @@ -3,6 +3,7 @@ version: "3" includes: build: "taskfiles/build.yaml" deps: "taskfiles/deps.yaml" + docker: "taskfiles/docker.yaml" docs: "taskfiles/docs.yaml" lint: "taskfiles/lint.yaml" test: "taskfiles/test.yaml" diff --git a/taskfiles/docker.yaml b/taskfiles/docker.yaml new file mode 100644 index 00000000..38b30b2f --- /dev/null +++ b/taskfiles/docker.yaml @@ -0,0 +1,23 @@ +version: "3" + +vars: + G_BUILD_SCRIPT: "{{.ROOT_DIR}}/tools/docker/build.sh" + +tasks: + build: + cmds: + - task: "build-storage" + - task: "build-scheduler" + - task: "build-worker" + + build-storage: + deps: [":init"] + cmd: "{{.G_BUILD_SCRIPT}} storage" + + build-scheduler: + deps: [":init"] + cmd: "{{.G_BUILD_SCRIPT}} scheduler" + + build-worker: + deps: [":init"] + cmd: "{{.G_BUILD_SCRIPT}} worker" diff --git a/tools/docker/build.sh b/tools/docker/build.sh new file mode 100755 index 00000000..a1979737 --- /dev/null +++ b/tools/docker/build.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +service="${1:?Usage: build.sh }" + +remove_temp_file_and_prev_image() { + rm -f "$temp_iid_file" + + [[ -z "$prev_image_id" || "$prev_image_id" == "$new_image_id" ]] && return + + docker image inspect "$prev_image_id" >/dev/null 2>&1 || return + + echo "Removing previous image $prev_image_id." + docker image remove "$prev_image_id" || true +} +trap remove_temp_file_and_prev_image EXIT + +script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +repo_root="${script_dir}/../../" +iid_file="${repo_root}/build/spider-${service}-image.id" + +prev_image_id="" +if [[ -f "$iid_file" ]]; then + prev_image_id=$(<"$iid_file") +fi + +temp_iid_file="$(mktemp)" +new_image_id="" + +docker build \ + --pull \ + --target "$service" \ + --iidfile "$temp_iid_file" \ + --file "${script_dir}/Dockerfile" \ + "$repo_root" + +if [[ -s "$temp_iid_file" ]]; then + new_image_id="$(<"$temp_iid_file")" + echo "$new_image_id" > "$iid_file" + + user="${USER:-$(whoami 2>/dev/null)}" \ + || user=$(id -un 2>/dev/null) \ + || user=$(id -u 2>/dev/null) \ + || user="unknown"; + short_id="${new_image_id#sha256:}" + short_id="${short_id:0:4}" + docker tag "$new_image_id" "spider-${service}:dev-${user}-${short_id}" +fi From 3250c44cfb56071a201b510f6f8f39f067fec619 Mon Sep 17 00:00:00 2001 From: ChenXing Yang <60459812+20001020ycx@users.noreply.github.com> Date: Thu, 9 Jul 2026 14:28:28 -0400 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Junhao Liao --- taskfiles/docker.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taskfiles/docker.yaml b/taskfiles/docker.yaml index 38b30b2f..d08e457f 100644 --- a/taskfiles/docker.yaml +++ b/taskfiles/docker.yaml @@ -12,12 +12,12 @@ tasks: build-storage: deps: [":init"] - cmd: "{{.G_BUILD_SCRIPT}} storage" + cmd: "'{{.G_BUILD_SCRIPT}}' storage" build-scheduler: deps: [":init"] - cmd: "{{.G_BUILD_SCRIPT}} scheduler" + cmd: "'{{.G_BUILD_SCRIPT}}' scheduler" build-worker: deps: [":init"] - cmd: "{{.G_BUILD_SCRIPT}} worker" + cmd: "'{{.G_BUILD_SCRIPT}}' worker" From 2a133738968d4004b4e0ffdbd555a019455404ad Mon Sep 17 00:00:00 2001 From: ChenXing Yang <60459812+20001020ycx@users.noreply.github.com> Date: Thu, 9 Jul 2026 18:37:32 -0400 Subject: [PATCH 3/3] Apply suggestion from @junhaoliao Co-authored-by: Junhao Liao --- tools/docker/build.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/docker/build.sh b/tools/docker/build.sh index a1979737..77d65d59 100755 --- a/tools/docker/build.sh +++ b/tools/docker/build.sh @@ -9,7 +9,13 @@ service="${1:?Usage: build.sh }" remove_temp_file_and_prev_image() { rm -f "$temp_iid_file" - [[ -z "$prev_image_id" || "$prev_image_id" == "$new_image_id" ]] && return + if [[ -z "$new_image_id" ]]; then + rm -f "$iid_file" + elif [[ "$prev_image_id" == "$new_image_id" ]]; then + return + fi + + [[ -z "$prev_image_id" ]] && return docker image inspect "$prev_image_id" >/dev/null 2>&1 || return