Skip to content

Commit 48e3b19

Browse files
committed
taprpc+scripts: add comprehensive Podman support to build system
Detect Podman by checking "$DOCKER --version", allowing overrides via the DOCKER environment variable. Retain "--user $UID:$(id -g)" for Docker/CI to ensure generated files are user-owned. For Podman, switch to "--user=0:0" to avoid EACCES errors caused by rootless subuid/subgid remapping on bind mounts. Changes: - scripts/docker_helpers.sh: new shared helper for Docker/Podman detection and user argument selection - scripts/gen_sqlc_docker.sh: source shared helper for container runtime detection; properly quote variables - taprpc/gen_protos_docker.sh: source shared helper for container runtime detection; properly quote variables - Makefile: add DOCKER variable and IS_PODMAN detection; update DOCKER_TOOLS, docker-release, and docker-tools targets to use configurable runtime - make/release_flags.mk: add Podman detection with conditional user args for DOCKER_RELEASE_HELPER Fixes "Permission denied" errors with rootless Podman, while preserving existing Docker behavior.
1 parent daf5060 commit 48e3b19

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,26 @@ ifneq ($(workers),)
5151
LINT_WORKERS = --concurrency=$(workers)
5252
endif
5353

54+
# Use docker by default; allow overrides and detect podman wrapper.
55+
DOCKER ?= docker
56+
IS_PODMAN := $(shell $(DOCKER) --version 2>/dev/null | grep -qi podman && echo 1 || echo 0)
57+
5458
# Docker cache mounting strategy:
5559
# - CI (GitHub Actions): Use bind mounts to host paths that GA caches persist.
5660
# - Local: Use Docker named volumes (much faster on macOS/Windows due to
5761
# avoiding slow host-syncing overhead).
5862
# Paths inside container must match GOCACHE/GOMODCACHE in tools/Dockerfile.
5963
ifdef CI
6064
# CI mode: bind mount to host paths that GitHub Actions caches.
61-
DOCKER_TOOLS = docker run \
65+
DOCKER_TOOLS = $(DOCKER) run \
6266
--rm \
6367
-v $${HOME}/.cache/go-build:/tmp/build/.cache \
6468
-v $${HOME}/go/pkg/mod:/tmp/build/.modcache \
6569
-v $${HOME}/.cache/golangci-lint:/root/.cache/golangci-lint \
6670
-v $$(pwd):/build taproot-assets-tools
6771
else
6872
# Local mode: Docker named volumes for fast macOS/Windows performance.
69-
DOCKER_TOOLS = docker run \
73+
DOCKER_TOOLS = $(DOCKER) run \
7074
--rm \
7175
-v tapd-go-build-cache:/tmp/build/.cache \
7276
-v tapd-go-mod-cache:/tmp/build/.modcache \
@@ -157,15 +161,15 @@ docker-release:
157161
@$(call print, "Building release helper docker image.")
158162
if [ "$(tag)" = "" ]; then echo "Must specify tag=<commit_or_tag>!"; exit 1; fi
159163

160-
docker build -t taproot-assets-release-helper -f make/builder.Dockerfile make/
164+
$(DOCKER) build -t taproot-assets-release-helper -f make/builder.Dockerfile make/
161165

162166
# Run the actual compilation inside the docker image. We pass in all flags
163167
# that we might want to overwrite in manual tests.
164168
$(DOCKER_RELEASE_HELPER) make release tag="$(tag)" sys="$(sys)" COMMIT="$(COMMIT)"
165169

166170
docker-tools:
167171
@$(call print, "Building tools docker image.")
168-
docker build -q -t taproot-assets-tools $(TOOLS_DIR)
172+
$(DOCKER) build -q -t taproot-assets-tools $(TOOLS_DIR)
169173

170174
scratch: build
171175

make/release_flags.mk

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@ VERSION_TAG = $(tag)
88
VERSION_CHECK = ./scripts/release.sh check-tag "$(VERSION_TAG)" "$(VERSION_GO_FILE)"
99
endif
1010

11-
DOCKER_RELEASE_HELPER = docker run \
11+
# Use docker by default; allow overrides and detect podman wrapper.
12+
DOCKER ?= docker
13+
IS_PODMAN_RELEASE := $(shell $(DOCKER) --version 2>/dev/null | grep -qi podman && echo 1 || echo 0)
14+
15+
# For Podman rootless, use --user=0:0 to avoid permission issues.
16+
# For Docker, use current user to ensure generated files are user-owned.
17+
ifeq ($(IS_PODMAN_RELEASE),1)
18+
USER_ARGS = --user=0:0
19+
else
20+
USER_ARGS = --user $(shell id -u):$(shell id -g)
21+
endif
22+
23+
DOCKER_RELEASE_HELPER = $(DOCKER) run \
1224
-it \
1325
--rm \
14-
--user $(shell id -u):$(shell id -g) \
26+
$(USER_ARGS) \
1527
-v $(shell pwd):/tmp/build/taproot-assets \
1628
-v $(shell bash -c "go env GOCACHE || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \
1729
-v $(shell bash -c "go env GOMODCACHE || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \

scripts/docker_helpers.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# docker_helpers.sh: Common Docker/Podman detection and configuration
4+
#
5+
# This script should be sourced by other scripts that need to run Docker or
6+
# Podman commands. It sets up the DOCKER variable and user_args array based
7+
# on whether Docker or Podman is being used.
8+
#
9+
# Usage:
10+
# source scripts/docker_helpers.sh
11+
# $DOCKER run "${user_args[@]}" ...
12+
13+
# Use docker by default; allow overrides and detect podman wrapper.
14+
DOCKER=${DOCKER:-docker}
15+
user_args=(--user "$UID:$(id -g)")
16+
if "$DOCKER" --version 2>/dev/null | grep -qi podman; then
17+
user_args=(--user=0:0)
18+
fi

scripts/gen_sqlc_docker.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
set -e
44

5+
# Directory of the script file, independent of where it's called from.
6+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
8+
# Source Docker/Podman detection helper.
9+
source "$DIR/docker_helpers.sh"
10+
511
# restore_files is a function to restore original schema files.
612
restore_files() {
713
echo "Restoring SQLite bigint patch..."
@@ -14,9 +20,6 @@ restore_files() {
1420
# are always restored.
1521
trap restore_files EXIT
1622

17-
# Directory of the script file, independent of where it's called from.
18-
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19-
2023
# Use the user's cache directories.
2124
GOCACHE=$(go env GOCACHE)
2225
GOMODCACHE=$(go env GOMODCACHE)
@@ -40,9 +43,9 @@ echo "Generating sql models and queries in go..."
4043

4144
# Run the script to generate the new generated code. Once the script exits, we
4245
# use `trap` to make sure all files are restored.
43-
docker run \
46+
$DOCKER run \
4447
--rm \
45-
--user "$UID:$(id -g)" \
48+
"${user_args[@]}" \
4649
-e UID=$UID \
4750
-v "$DIR/../:/build" \
4851
-w /build \

taprpc/gen_protos_docker.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ set -e
55
# Directory of the script file, independent of where it's called from.
66
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
77

8+
# Source Docker/Podman detection helper.
9+
source "$DIR/../scripts/docker_helpers.sh"
10+
811
PROTOBUF_VERSION=$(go list -f '{{.Version}}' -m google.golang.org/protobuf)
912
GRPC_GATEWAY_VERSION=$(go list -f '{{.Version}}' -m github.com/grpc-ecosystem/grpc-gateway/v2)
1013
LND_VERSION=$(go list -f '{{.Version}}' -m github.com/lightningnetwork/lnd)
1114

1215
echo "Building protobuf compiler docker image..."
13-
docker build -t taproot-assets-protobuf-builder \
16+
$DOCKER build -t taproot-assets-protobuf-builder \
1417
--build-arg PROTOBUF_VERSION="$PROTOBUF_VERSION" \
1518
--build-arg GRPC_GATEWAY_VERSION="$GRPC_GATEWAY_VERSION" \
1619
--build-arg LND_VERSION="$LND_VERSION" \
1720
.
1821

1922
echo "Compiling and formatting *.proto files..."
20-
docker run \
23+
$DOCKER run \
2124
--rm \
22-
--user "$UID:$(id -g)" \
25+
"${user_args[@]}" \
2326
-e UID=$UID \
2427
-e COMPILE_MOBILE \
2528
-e SUBSERVER_PREFIX \

0 commit comments

Comments
 (0)