Skip to content

Commit d724eb2

Browse files
committed
emulator fixes
1 parent 7d9e156 commit d724eb2

4 files changed

Lines changed: 338 additions & 76 deletions

File tree

docker/local-emulator/Dockerfile

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,17 @@ RUN cp $(which qstash) /qstash-binary 2>/dev/null || \
105105

106106
# ── Strip / compress service binaries (parallel stages) ──────────────────────
107107

108-
FROM debian:trixie-slim AS strip-clickhouse
109-
COPY --from=clickhouse-bin /usr/bin/clickhouse /usr/bin/clickhouse
110-
RUN apt-get update && apt-get install -y --no-install-recommends binutils && \
111-
strip --strip-all /usr/bin/clickhouse && \
112-
rm -rf /var/lib/apt/lists/*
113-
114108
FROM debian:trixie-slim AS upx-compress
115-
RUN apt-get update && apt-get install -y --no-install-recommends upx-ucl && \
109+
RUN apt-get update && apt-get install -y --no-install-recommends upx-ucl binutils && \
116110
rm -rf /var/lib/apt/lists/*
111+
COPY --from=clickhouse-bin /usr/bin/clickhouse /out/clickhouse
117112
COPY --from=svix-bin /usr/local/bin/svix-server /out/svix-server
118113
COPY --from=minio-bin /usr/bin/minio /out/minio
119114
COPY --from=mc-bin /usr/bin/mc /out/mc
120115
COPY --from=qstash-bin /qstash-binary /out/qstash
121-
RUN upx -9 /out/minio /out/svix-server /out/mc /out/qstash
116+
RUN chmod u+w /out/* && \
117+
strip --strip-all /out/clickhouse /out/minio /out/svix-server /out/mc /out/qstash && \
118+
upx -9 /out/minio /out/svix-server /out/mc /out/qstash
122119

123120

124121
# ── Final image ───────────────────────────────────────────────────────────────
@@ -160,8 +157,8 @@ COPY --from=inbucket-bin /opt/inbucket /opt/inbucket
160157
# Svix (UPX-compressed)
161158
COPY --from=upx-compress /out/svix-server /usr/local/bin/svix-server
162159

163-
# ClickHouse (stripped)
164-
COPY --from=strip-clickhouse /usr/bin/clickhouse /usr/bin/clickhouse
160+
# ClickHouse (stripped only)
161+
COPY --from=upx-compress /out/clickhouse /usr/bin/clickhouse
165162
RUN ln -sf /usr/bin/clickhouse /usr/bin/clickhouse-server && \
166163
ln -sf /usr/bin/clickhouse /usr/bin/clickhouse-client
167164

docker/local-emulator/qemu/build-image.sh

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,46 @@ prepare_bundle_artifacts() {
176176
printf "%s" "$current_ids" > "$bundle_meta"
177177
}
178178

179+
contains_provision_marker() {
180+
local provision_log="$1"
181+
local serial_log="$2"
182+
local marker="$3"
183+
184+
if [ -f "$provision_log" ] && grep -Fqx "$marker" "$provision_log" 2>/dev/null; then
185+
return 0
186+
fi
187+
188+
if [ -f "$serial_log" ] && LC_ALL=C strings -a "$serial_log" 2>/dev/null | grep -Fqx "$marker" 2>/dev/null; then
189+
return 0
190+
fi
191+
192+
return 1
193+
}
194+
195+
line_count() {
196+
local file="$1"
197+
local count=0
198+
199+
if [ -f "$file" ]; then
200+
count="$(wc -l < "$file" | tr -d '[:space:]')" || count=0
201+
fi
202+
203+
case "$count" in
204+
''|*[!0-9]*) count=0 ;;
205+
esac
206+
207+
printf '%s\n' "$count"
208+
}
209+
210+
persist_provision_logs() {
211+
local arch="$1"
212+
local serial_log="$2"
213+
local provision_log="$3"
214+
215+
cp "$serial_log" "$IMAGE_DIR/provision-emulator-${arch}.log" 2>/dev/null || true
216+
cp "$provision_log" "$IMAGE_DIR/provision-emulator-${arch}.progress.log" 2>/dev/null || true
217+
}
218+
179219
build_one() {
180220
local arch="$1"
181221
local base_img="$IMAGE_DIR/debian-${DEBIAN_VERSION}-base-${arch}.qcow2"
@@ -192,8 +232,11 @@ build_one() {
192232
local bundle_iso="$tmp_dir/bundle.iso"
193233
local bundle_dir="$tmp_dir/bundle"
194234
local serial_log="$tmp_dir/serial.log"
235+
local provision_log="$tmp_dir/provision.log"
195236
local pidfile="$tmp_dir/qemu.pid"
196-
local qemu_base pid elapsed
237+
local qemu_base pid elapsed total_build_lines
238+
local last_build_lines=0
239+
local guest_exited=false
197240
local start_time=$SECONDS
198241

199242
cp "$base_img" "$tmp_img"
@@ -213,6 +256,7 @@ build_one() {
213256
make_iso_from_dir "$bundle_iso" "STACKBUNDLE" "$bundle_dir"
214257

215258
: > "$serial_log"
259+
: > "$provision_log"
216260
qemu_base="$(qemu_cmd_prefix_for_arch "$arch")"
217261

218262
# shellcheck disable=SC2086
@@ -225,6 +269,7 @@ build_one() {
225269
-drive "file=$bundle_iso,format=raw,if=virtio,readonly=on" \
226270
-netdev user,id=net0 \
227271
-device virtio-net-pci,netdev=net0 \
272+
-virtfs "local,path=$tmp_dir,mount_tag=hostfs,security_model=none" \
228273
-serial "file:$serial_log" \
229274
-display none \
230275
-daemonize \
@@ -233,23 +278,55 @@ build_one() {
233278
pid="$(cat "$pidfile")"
234279
elapsed=0
235280
while [ "$elapsed" -lt "$PROVISION_TIMEOUT" ]; do
236-
if grep -q "STACK_CLOUD_INIT_DONE" "$serial_log" 2>/dev/null; then
281+
if contains_provision_marker "$provision_log" "$serial_log" "STACK_CLOUD_INIT_DONE"; then
282+
break
283+
fi
284+
285+
if [ -f "$provision_log" ]; then
286+
total_build_lines="$(line_count "$provision_log")"
287+
if [ "$total_build_lines" -gt "$last_build_lines" ]; then
288+
echo ""
289+
sed -n "$((last_build_lines + 1)),${total_build_lines}p" "$provision_log" 2>/dev/null | while IFS= read -r msg; do
290+
if [ "$msg" = "STACK_CLOUD_INIT_DONE" ]; then
291+
continue
292+
fi
293+
printf " [%3ds] %s\n" "$elapsed" "$msg"
294+
done
295+
last_build_lines="$total_build_lines"
296+
fi
297+
fi
298+
299+
if ! kill -0 "$pid" 2>/dev/null; then
300+
guest_exited=true
237301
break
238302
fi
303+
239304
sleep 5
240305
elapsed=$((SECONDS - start_time))
241306
printf "\r [%3ds / %ds] provisioning emulator..." "$elapsed" "$PROVISION_TIMEOUT"
242307
done
243308
echo ""
244309

245-
if ! grep -q "STACK_CLOUD_INIT_DONE" "$serial_log" 2>/dev/null; then
246-
err "Provisioning timed out for emulator (${arch})"
247-
tail -50 "$serial_log" >&2 || true
310+
if ! contains_provision_marker "$provision_log" "$serial_log" "STACK_CLOUD_INIT_DONE"; then
311+
if [ "$guest_exited" = true ]; then
312+
err "Provisioning exited before completion for emulator (${arch})"
313+
else
314+
err "Provisioning timed out for emulator (${arch})"
315+
fi
316+
317+
if [ -s "$provision_log" ]; then
318+
tail -50 "$provision_log" >&2 || true
319+
else
320+
LC_ALL=C strings -a "$serial_log" 2>/dev/null | tail -50 >&2 || tail -50 "$serial_log" >&2 || true
321+
fi
322+
248323
if kill -0 "$pid" 2>/dev/null; then
249324
kill "$pid" 2>/dev/null || true
250325
sleep 1
251326
kill -9 "$pid" 2>/dev/null || true
252327
fi
328+
329+
persist_provision_logs "$arch" "$serial_log" "$provision_log"
253330
rm -rf "$tmp_dir"
254331
exit 1
255332
fi
@@ -267,7 +344,7 @@ build_one() {
267344
kill -9 "$pid" 2>/dev/null || true
268345
fi
269346

270-
cp "$serial_log" "$IMAGE_DIR/provision-emulator-${arch}.log"
347+
persist_provision_logs "$arch" "$serial_log" "$provision_log"
271348

272349
log "Compressing final image (this may take several minutes)..."
273350
qemu-img convert -p -O qcow2 -c "$tmp_img" "$final_img"

0 commit comments

Comments
 (0)