Skip to content

Commit ed278df

Browse files
authored
Merge pull request #1482 from thewtex/local-vars
build(docker): generate variables needed for local repo builds
2 parents 227072c + 7b15536 commit ed278df

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/docker/itk-wasm-base/build.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,19 @@ if [[ -n "$local_itk" ]]; then
8080
local_itk_build_arg="--build-arg USE_LOCAL_ITK=1"
8181
fi
8282

83-
# Cleanup function to restore ITKLocalCopy to placeholder state
84-
cleanup_local_itk() {
83+
# Generate environment variables file for Docker
84+
"$script_dir/generate-env-vars.sh"
85+
86+
# Cleanup function to restore ITKLocalCopy to placeholder state and remove generated files
87+
cleanup_build_artifacts() {
8588
if [[ -n "$local_itk" ]]; then
8689
rm -rf "$script_dir/ITKLocalCopy"/*
8790
touch "$script_dir/ITKLocalCopy/.gitkeep"
8891
fi
92+
# Remove generated env vars file
93+
rm -f "$script_dir/itk_wasm_env_vars.sh"
8994
}
90-
trap cleanup_local_itk EXIT
95+
trap cleanup_build_artifacts EXIT
9196

9297
$exe $build_cmd $tag_flag quay.io/itkwasm/emscripten-base:latest-$host_arch \
9398
--build-arg IMAGE=quay.io/itkwasm/emscripten-base \
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
# Generate itk_wasm_env_vars.sh for use in Docker builds
4+
# This script sources the root itk_wasm_env.bash and extracts only
5+
# the variables needed by the Dockerfile
6+
7+
set -eo pipefail
8+
9+
script_dir="$(cd "$(dirname "$0")" && pwd)"
10+
root_dir="$(cd "$script_dir/../../.." && pwd)"
11+
12+
# Source the main environment file
13+
# Note: We need to handle the fact that itk_wasm_env.bash tries to parse
14+
# package.json files which may not work in all contexts
15+
export ITK_WASM_DEV_DOCKER_TAG="${ITK_WASM_DEV_DOCKER_TAG:-latest}"
16+
17+
# Extract the core variables we need
18+
source "$root_dir/itk_wasm_env.bash" 2>/dev/null || {
19+
# If sourcing fails (e.g., due to jq commands), extract manually
20+
ITK_WASM_DCMTK_REPOSITORY="${ITK_WASM_DCMTK_REPOSITORY:-https://github.com/InsightSoftwareConsortium/DCMTK}"
21+
ITK_WASM_DCMTK_GIT_TAG="${ITK_WASM_DCMTK_GIT_TAG:-2fe4dacbe9c343dba350fcff6eab365241636623}"
22+
ITK_WASM_ITK_REPOSITORY="${ITK_WASM_ITK_REPOSITORY:-https://github.com/thewtex/ITK}"
23+
ITK_WASM_ITK_BRANCH="${ITK_WASM_ITK_BRANCH:-itkwasm-2025-03-19-25d3162371}"
24+
}
25+
26+
# Generate the env vars file for Docker
27+
cat > "$script_dir/itk_wasm_env_vars.sh" << EOF
28+
#!/usr/bin/env sh
29+
# Auto-generated by generate-env-vars.sh - DO NOT EDIT
30+
# Generated from: $root_dir/itk_wasm_env.bash
31+
32+
export ITK_WASM_DCMTK_REPOSITORY="${ITK_WASM_DCMTK_REPOSITORY}"
33+
export ITK_WASM_DCMTK_GIT_TAG="${ITK_WASM_DCMTK_GIT_TAG}"
34+
export ITK_WASM_ITK_REPOSITORY="${ITK_WASM_ITK_REPOSITORY}"
35+
export ITK_WASM_ITK_BRANCH="${ITK_WASM_ITK_BRANCH}"
36+
EOF
37+
38+
chmod +x "$script_dir/itk_wasm_env_vars.sh"
39+
40+
echo "Generated $script_dir/itk_wasm_env_vars.sh with:"
41+
echo " ITK_WASM_ITK_REPOSITORY=${ITK_WASM_ITK_REPOSITORY}"
42+
echo " ITK_WASM_ITK_BRANCH=${ITK_WASM_ITK_BRANCH}"
43+
echo " ITK_WASM_DCMTK_REPOSITORY=${ITK_WASM_DCMTK_REPOSITORY}"
44+
echo " ITK_WASM_DCMTK_GIT_TAG=${ITK_WASM_DCMTK_GIT_TAG}"

0 commit comments

Comments
 (0)