-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-devtools.sh
More file actions
executable file
·180 lines (160 loc) · 6.49 KB
/
build-devtools.sh
File metadata and controls
executable file
·180 lines (160 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env bash
set -euo pipefail
#
# build-devtools.sh -- Build the salt-dev-tools image with Intel IFX compilers.
#
# Automates the full pipeline: build devtools image from a base image, install
# Intel IFX inside a temporary container, commit the result, and tag it.
#
# Usage:
# bash build-devtools.sh [options]
#
# Options:
# -h, --help Print this help and exit
# --base=<image:tag> Base image (default: salt-dev:latest)
# --tag=<tag> Output tag (default: intel-2025.2)
# --ifx-version=<version> Intel IFX version (default: 2025.2)
# --builder=<name> Buildx builder for devtools stage (default: desktop-linux)
# --skip-devtools-build Skip the Dockerfile.devtools build; use existing salt-dev-tools:latest
# --no-intel Skip Intel IFX installation
# --no-push Don't push to Docker Hub
# --push-repo=<repo> Docker Hub repo (default: paratools/salt-dev-tools)
#
# Examples:
# bash build-devtools.sh
# bash build-devtools.sh --base=paratools/salt-dev:1.3
# bash build-devtools.sh --ifx-version=2025.3 --tag=intel-2025.3
# bash build-devtools.sh --skip-devtools-build
# bash build-devtools.sh --no-push
#
###############################################################################
# Helpers
###############################################################################
info() { echo "==> $*"; }
warn() { echo "WARNING: $*" >&2; }
die() { echo "ERROR: $*" >&2; exit 1; }
usage() {
sed -n '/^# Usage:/,/^$/{ /^#/s/^# \{0,1\}//p; }' "$0"
exit 0
}
cleanup() {
if [[ -n "${CONTAINER_NAME:-}" ]]; then
if docker inspect "$CONTAINER_NAME" &>/dev/null; then
info "Cleaning up container: $CONTAINER_NAME"
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
fi
fi
}
trap cleanup EXIT
###############################################################################
# Defaults
###############################################################################
# Prefer local salt-dev image; fall back to Docker Hub if not present
if docker image inspect salt-dev:latest &>/dev/null; then
BASE_IMAGE="salt-dev"
else
BASE_IMAGE="paratools/salt-dev"
fi
BASE_TAG="latest"
OUTPUT_TAG="intel-2025.2"
IFX_VERSION="2025.2"
BUILDER="desktop-linux"
SKIP_DEVTOOLS_BUILD=false
INSTALL_INTEL=true
DO_PUSH=true
PUSH_REPO="paratools/salt-dev-tools"
CONTAINER_NAME="salt-devtools-build-$$"
###############################################################################
# Option parsing
###############################################################################
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help) usage ;;
--base=*)
base_arg="${1#--base=}"
if [[ "$base_arg" == *:* ]]; then
BASE_IMAGE="${base_arg%%:*}"
BASE_TAG="${base_arg#*:}"
else
BASE_IMAGE="$base_arg"
fi
shift
;;
--tag=*) OUTPUT_TAG="${1#--tag=}"; shift ;;
--ifx-version=*) IFX_VERSION="${1#--ifx-version=}"; shift ;;
--builder=*) BUILDER="${1#--builder=}"; shift ;;
--skip-devtools-build) SKIP_DEVTOOLS_BUILD=true; shift ;;
--no-intel) INSTALL_INTEL=false; shift ;;
--no-push) DO_PUSH=false; shift ;;
--push-repo=*) PUSH_REPO="${1#--push-repo=}"; shift ;;
-*) die "Unknown option: $1" ;;
*) die "Unexpected argument: $1" ;;
esac
done
###############################################################################
# Locate repo root
###############################################################################
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
if [[ -z "$REPO_ROOT" ]]; then
# Try worktree common dir
REPO_ROOT="$(cd "$(git rev-parse --git-common-dir 2>/dev/null)/.." && pwd)"
fi
if [[ ! -f "${REPO_ROOT}/Dockerfile.devtools" ]]; then
die "Cannot find Dockerfile.devtools in repo root: ${REPO_ROOT}"
fi
###############################################################################
# Stage 1: Build Dockerfile.devtools
###############################################################################
if [[ "$SKIP_DEVTOOLS_BUILD" == false ]]; then
info "Building salt-dev-tools from ${BASE_IMAGE}:${BASE_TAG} (builder: ${BUILDER})"
docker buildx build \
--builder "$BUILDER" \
-f "${REPO_ROOT}/Dockerfile.devtools" \
--build-arg "BASE_IMAGE=${BASE_IMAGE}" \
--build-arg "BASE_TAG=${BASE_TAG}" \
-t salt-dev-tools:latest \
--load \
"$REPO_ROOT"
info "Devtools image built: salt-dev-tools:latest"
else
info "Skipping devtools build (--skip-devtools-build)"
if ! docker image inspect salt-dev-tools:latest &>/dev/null; then
die "salt-dev-tools:latest not found; remove --skip-devtools-build to build it"
fi
fi
###############################################################################
# Push devtools (non-Intel) to Docker Hub
###############################################################################
if [[ "$DO_PUSH" == true ]]; then
info "Pushing salt-dev-tools:latest to ${PUSH_REPO}:latest"
docker tag salt-dev-tools:latest "${PUSH_REPO}:latest"
docker push "${PUSH_REPO}:latest"
else
info "Skipping push (--no-push)"
fi
###############################################################################
# Stage 2: Install Intel IFX (local only -- not pushed)
###############################################################################
if [[ "$INSTALL_INTEL" == true ]]; then
info "Installing Intel IFX ${IFX_VERSION} in temporary container: ${CONTAINER_NAME}"
docker run \
--name "$CONTAINER_NAME" \
salt-dev-tools:latest \
bash -c "sudo install-intel-ifx.sh --trust-intel-repo ${IFX_VERSION} \
&& echo 'source /opt/intel/oneapi/env.sh' >> ~/.bashrc"
info "Committing container as salt-dev-tools:${OUTPUT_TAG} (local only)"
# Reset CMD to interactive shell; docker commit inherits the container's
# bash -c "install..." command otherwise
docker commit --change 'CMD ["/bin/bash"]' "$CONTAINER_NAME" "salt-dev-tools:${OUTPUT_TAG}"
info "Removing temporary container"
docker rm "$CONTAINER_NAME" >/dev/null
# Clear the name so the EXIT trap doesn't try again
CONTAINER_NAME=""
else
info "Skipping Intel IFX installation (--no-intel)"
fi
###############################################################################
# Summary
###############################################################################
info "Done! Tagged images:"
docker images salt-dev-tools --format ' {{.Repository}}:{{.Tag}} {{.Size}} {{.CreatedSince}}'