-
Notifications
You must be signed in to change notification settings - Fork 11
build(huntsman): Add local build tasks for Spider Huntsman images. #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b4ef4e0
3250c44
2a13373
76ca648
46a600c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| set -o errexit | ||||||||||||||||||||||||||||||||||||||||||||||
| set -o nounset | ||||||||||||||||||||||||||||||||||||||||||||||
| set -o pipefail | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| service="${1:?Usage: build.sh <storage|scheduler|worker>}" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| remove_temp_file_and_prev_image() { | ||||||||||||||||||||||||||||||||||||||||||||||
| rm -f "$temp_iid_file" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| echo "Removing previous image $prev_image_id." | ||||||||||||||||||||||||||||||||||||||||||||||
| docker image remove "$prev_image_id" || true | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| trap remove_temp_file_and_prev_image EXIT | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win Previous image is deleted on build failure. When 🔒 Proposed fix: short-circuit when no new image was built- [[ -z "$prev_image_id" || "$prev_image_id" == "$new_image_id" ]] && return
+ [[ -z "$prev_image_id" || -z "$new_image_id" || "$prev_image_id" == "$new_image_id" ]] && return📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @junhaoliao should we add
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Fetch CLP's build.sh to check whether it has the same guard logic
gh api repos/y-scope/clp/contents/tools/docker/build.sh --jq '.content' 2>/dev/null | base64 -d || echo "NOT_FOUND_default_path"Length of output: 410 🏁 Script executed: #!/bin/bash
set -euo pipefail
gh search code "remove_temp_file_and_prev_image" --repo y-scope/clp
echo "---"
gh api repos/y-scope/clp/git/trees/main?recursive=1 --jq '.tree[].path' | grep -i docker | grep -i build || trueLength of output: 1027 🏁 Script executed: #!/bin/bash
set -euo pipefail
gh api repos/y-scope/clp/contents/tools/docker-images/clp-package/build.sh --jq '.content' | base64 -dLength of output: 2172
I fetched CLP's [[ -z "$prev_image_id" || "$prev_image_id" == "$new_image_id" ]] && returnBoth scripts initialize
So the guard doesn't short-circuit, and the previous working image gets deleted even though the build failed — leaving Regarding the fix: to be precise, it's - [[ -z "$prev_image_id" || "$prev_image_id" == "$new_image_id" ]] && return
+ [[ -z "$prev_image_id" || -z "$new_image_id" || "$prev_image_id" == "$new_image_id" ]] && returnSince this is inherited from CLP, it'd be worth fixing here in Spider regardless, and optionally flagging it upstream to the CLP maintainers as a separate issue if you'd like — happy to help draft that if you want to go that route.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, i agree that:
i proposed https://github.com/y-scope/spider/pull/381/changes#r3553514597 instead then
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we consider making these tasks private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think public also makes sense, developer may just run
task docker:build-storagefor faster docker build.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@junhaoliao what do you think? :)
I am fine with both