Files
VoelinClient/scripts/docker-build.sh
T
faumarayandClaude Sonnet 5.5 b89116c0f4 Let the Docker builds fetch the private VoelinProtocol repository with an ssh-agent
Every cargo command in the images (linux, windows, android and the gateway
image) failed for the same reason as the CI job: Cargo resolves the whole
workspace, which includes the git dependency voelin-identity on the private
Voelin/VoelinProtocol repository, and the images had no SSH access to it. The
crates that depend on voelin-identity are voelin-store and, through it,
voelin-core, voelin-ui, voelin-ui-vm, voelin-android and voelinctl; the
gateway crate does not, but `cargo build -p voelin-gateway` fails without
access too (checked with an empty CARGO_HOME), so its Dockerfile needs the
same.

Each cargo RUN gets --mount=type=ssh,required=true: the build is handed the
caller's ssh-agent (docker build --ssh default), the key stays in the agent
and never reaches a layer or the build context, and a build without --ssh
fails at that step with "unset ssh forward key default". The build stage
copies the host key committed in .gitea/known_hosts to
/etc/ssh/ssh_known_hosts and sets CARGO_NET_GIT_FETCH_WITH_CLI=true, so that
Cargo uses the system git and ssh. The toolchain stages install git and
openssh-client where they were missing; the gateway Dockerfile gets the
syntax directive the others already have. scripts/docker-build.sh passes
--ssh default and stops early, with a message, when ssh-add -l shows no agent
or no key.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 13:43:12 +03:00

62 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build the packages in Docker, the same ones CI uploads (docs/building.md).
#
# scripts/docker-build.sh [linux|windows|android|all] [docker build args…]
#
# Output goes to dist/<platform>/. Needs Docker with BuildKit (Docker 23+, or
# docker buildx). Extra arguments go to `docker build`, e.g.
# scripts/docker-build.sh android --build-arg ABIS=arm64-v8a
#
# The workspace depends on the private VoelinProtocol repository, which the
# build fetches over SSH with your ssh-agent (`docker build --ssh default`):
# the agent must hold a key that can read it (docs/building.md, "Depending on
# VoelinProtocol"). The key stays in the agent, never in the image.
#
# Behind an HTTPS proxy, HTTPS_PROXY/HTTP_PROXY/NO_PROXY are passed on to the
# build; a proxy on this machine's loopback is reached with host networking.
# If the proxy inspects TLS, point BUILD_CA_CERT at its CA certificate (PEM):
# the builds then trust it.
set -euo pipefail
cd "$(dirname "$0")/.."
platform=${1:-all}
shift || true
case "$platform" in
linux | windows | android) platforms=("$platform") ;;
all) platforms=(linux windows android) ;;
*) echo "usage: $0 [linux|windows|android|all] [docker build args…]" >&2; exit 2 ;;
esac
# The build's cargo needs VoelinProtocol; fail here, not after the toolchain
# stage, when the agent is missing or empty.
if ! ssh-add -l > /dev/null 2>&1; then
cat >&2 <<'MSG'
docker-build.sh: no ssh-agent with a key that can read Voelin/VoelinProtocol.
Start one and add the key, then run this again:
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/<key>
docs/building.md ("Depending on VoelinProtocol") has the details.
MSG
exit 1
fi
args=(--ssh default)
for var in HTTPS_PROXY https_proxy HTTP_PROXY http_proxy NO_PROXY no_proxy; do
if [[ -n ${!var:-} ]]; then
args+=(--build-arg "$var=${!var}")
case "${!var}" in
*://127.* | *://localhost*) args+=(--network host) ;;
esac
fi
done
if [[ -n ${BUILD_CA_CERT:-} ]]; then
args+=(--secret "id=ca,src=$BUILD_CA_CERT")
fi
for p in "${platforms[@]}"; do
echo "== $p → dist/$p"
DOCKER_BUILDKIT=1 docker build -f "docker/$p.Dockerfile" -o "dist/$p" "${args[@]}" "$@" .
ls -l "dist/$p"
done