datahaven/operator/scripts/build-runtime-srtool.sh
Steve Degosserie 8c950af4a4
fix: 🔧 Add Podman support to srtool runtime build script (#222)
## Summary

- Adds support for both Docker and Podman container engines in
`build-runtime-srtool.sh` via `IS_PODMAN` environment variable
- Uses `--userns=keep-id` for Podman (proper user namespace handling)
and `--user $(id -u):$(id -g)` for Docker
- Sets `IS_PODMAN=true` in `task-publish-runtime.yml` workflow to enable
Podman by default

## Changes

**`operator/scripts/build-runtime-srtool.sh`:**
- Added conditional logic to detect `IS_PODMAN` env var
- Dynamically selects between `podman` and `docker` as container engine
- Sets appropriate user/namespace flags based on container engine

**`.github/workflows/task-publish-runtime.yml`:**
- Added `IS_PODMAN: true` environment variable to the srtool build step
- Updated comment to use generic "container user" instead of "docker
user"

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-10 22:57:34 +02:00

53 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
# CARGO_NET_GIT_FETCH_WITH_CLI=true and --entrypoint /srtool/entrypoint.sh
# are required to allow srtool to fetch from github private repositories
# self-hosted runner uses user `maintenance` to match srtool `builder` user 1001
# $(~/srtool/uid-gid-mapping.sh 1001 | xargs) is used to map the user and group
# Determine whether to use Podman or Docker
if [ "${IS_PODMAN}" = "true" ]; then
CONTAINER_ENGINE="podman"
USER_FLAG="--userns=keep-id"
else
CONTAINER_ENGINE="docker"
USER_FLAG="--user $(id -u):$(id -g)"
fi
# Container command to generate JSON blob of the runtime
CMD="${CONTAINER_ENGINE} run \
-i \
--rm \
${USER_FLAG} \
-e CARGO_NET_GIT_FETCH_WITH_CLI=true \
-e PACKAGE=datahaven-${GH_WORKFLOW_MATRIX_CHAIN}-runtime \
-e RUNTIME_DIR=operator/runtime/${GH_WORKFLOW_MATRIX_CHAIN} \
-e BUILD_OPTS=${RUNTIME_BUILD_OPTS} \
-e PROFILE=${RUNTIME_BUILD_PROFILE} \
-v "${PWD}:/build" \
${GH_WORKFLOW_MATRIX_SRTOOL_IMAGE}:${GH_WORKFLOW_MATRIX_SRTOOL_IMAGE_TAG} \
build --app --json -cM"
# Here we run the command and stream the output (JSON blob) to a variable
stdbuf -oL $CMD | {
while IFS= read -r line
do
echo$line
JSON="$line"
done
echo "json=$JSON" >> $GITHUB_OUTPUT
PROP=$(echo $JSON | jq -r .runtimes.compact.prop)
echo "proposal_hash=$PROP" >> $GITHUB_OUTPUT
WASM=$(echo $JSON | jq -r .runtimes.compact.wasm)
echo "wasm=$WASM" >> $GITHUB_OUTPUT
Z_WASM=$(echo $JSON | jq -r .runtimes.compressed.wasm)
echo "wasm_compressed=$Z_WASM" >> $GITHUB_OUTPUT
IPFS=$(echo $JSON | jq -r .runtimes.compact.ipfs)
echo "ipfs=$IPFS" >> $GITHUB_OUTPUT
}