-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(build-scripts): consolidate image build and push scripts
- Replaced with a single `build-and-push-images.sh` script. - Support for both Spin and Docker build workflows with the `--spin`, `--docker`, and `--both` options. - Added parallel processing for building and pushing images. Signed-off-by: Jiaxiao (mossaka) Zhou <[email protected]>
- Loading branch information
Showing
5 changed files
with
92 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
RUN_SPIN=false | ||
RUN_DOCKER=false | ||
|
||
cluster_name="test-cluster" | ||
OUT_DIRS=("test/out_spin" "test/out_spin_keyvalue" "test/out_spin_outbound_redis" "test/out_spin_multi_trigger_app" "test/out_spin_static_assets" "test/out_spin_mqtt_message_logger") | ||
IMAGES=("spin-hello-world" "spin-keyvalue" "spin-outbound-redis" "spin-multi-trigger-app" "spin-static-assets" "spin-mqtt-message-logger") | ||
|
||
|
||
spin_build_and_push() { | ||
local i=$1 | ||
spin build -f "./images/${IMAGES[$i]}/spin.toml" | ||
if [ "${IMAGES[$i]}" == "spin-static-assets" ]; then | ||
export SPIN_OCI_ARCHIVE_LAYERS=1 | ||
fi | ||
spin registry push "localhost:5000/spin-registry-push/${IMAGES[$i]}:latest" -f "./images/${IMAGES[$i]}/spin.toml" -k | ||
} | ||
|
||
docker_build_and_push() { | ||
local image="$1" | ||
local out_dir="$2" | ||
|
||
docker buildx build -t "${image}:latest" "./images/${image}" --load | ||
mkdir -p "${out_dir}" | ||
docker save -o "${out_dir}/img.tar" "${image}:latest" | ||
k3d image import "${out_dir}/img.tar" -c "$cluster_name" | ||
} | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
case "$1" in | ||
--spin) RUN_SPIN=true ;; | ||
--docker) RUN_DOCKER=true ;; | ||
--both) RUN_SPIN=true; RUN_DOCKER=true ;; | ||
*) echo "Unknown option: $1"; exit 1 ;; | ||
esac | ||
shift | ||
done | ||
|
||
if ! $RUN_SPIN && ! $RUN_DOCKER; then | ||
echo "Error: At least one of --spin, --docker, or --both must be specified." | ||
exit 1 | ||
fi | ||
|
||
|
||
if $RUN_SPIN; then | ||
echo "Running Spin builds and pushes..." | ||
if ! docker ps | grep -q test-registry; then | ||
docker run -d -p 5000:5000 --name test-registry registry:2 | ||
fi | ||
for i in "${!IMAGES[@]}"; do | ||
spin_build_and_push "$i" & | ||
done | ||
fi | ||
|
||
if $RUN_DOCKER; then | ||
echo "Running Docker builds and pushes..." | ||
for i in "${!IMAGES[@]}"; do | ||
docker_build_and_push "${IMAGES[$i]}" "${OUT_DIRS[$i]}" & | ||
done | ||
fi | ||
|
||
# Wait for all background jobs to finish | ||
wait | ||
|
||
sleep 5 | ||
echo "Images are ready" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
cluster_name="test-cluster" | ||
dockerfile_path="deployments/k3d" | ||
|
||
docker build -t k3d-shim-test "$dockerfile_path" | ||
|
||
k3d cluster create "$cluster_name" \ | ||
--image k3d-shim-test --api-port 6551 -p '8082:80@loadbalancer' --agents 2 \ | ||
--registry-create test-registry:0.0.0.0:5000 \ | ||
--k3s-arg '--kubelet-arg=eviction-hard=imagefs.available<1%,nodefs.available<1%@agent:*' \ | ||
--k3s-arg '--kubelet-arg=eviction-minimum-reclaim=imagefs.available=1%,nodefs.available=1%@agent:*' | ||
|
||
kubectl wait --for=condition=ready node --all --timeout=120s | ||
|
||
echo "Running Spin and Docker builds and pushes..." | ||
./scripts/spin-build-and-push-images.sh --both | ||
|
||
echo ">>> Cluster setup and image builds/pushes complete!" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.