Skip to content

Commit 979a2da

Browse files
authored
Merge pull request #1928 from lightninglabs/chore/add-podman-support
taprpc+scripts: detect Podman wrapper and preserve Docker UID mapping
2 parents b3f821e + 6352452 commit 979a2da

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ MAKE := make
2929
XARGS := xargs -L 1
3030
UNAME_S := $(shell uname -s)
3131

32+
# Use docker by default; allow overrides and detect podman wrapper.
33+
DOCKER ?= docker
34+
IS_PODMAN := $(shell $(DOCKER) --version 2>/dev/null | grep -qi podman && echo 1 || echo 0)
35+
3236
include make/testing_flags.mk
3337
include make/release_flags.mk
3438
include make/fuzz_flags.mk
@@ -74,7 +78,7 @@ endif
7478
# Paths inside container must match GOCACHE/GOMODCACHE in tools/Dockerfile.
7579
ifdef CI
7680
# CI mode: bind mount to host paths that GitHub Actions caches.
77-
DOCKER_TOOLS = docker run \
81+
DOCKER_TOOLS = $(DOCKER) run \
7882
--rm \
7983
-v $${HOME}/.cache/go-build:/tmp/build/.cache \
8084
-v $${HOME}/go/pkg/mod:/tmp/build/.modcache \
@@ -83,7 +87,7 @@ DOCKER_TOOLS = docker run \
8387
-v $$(pwd):/build taproot-assets-tools
8488
else
8589
# Local mode: Docker named volumes for fast macOS/Windows performance.
86-
DOCKER_TOOLS = docker run \
90+
DOCKER_TOOLS = $(DOCKER) run \
8791
--rm \
8892
-v tapd-go-build-cache:/tmp/build/.cache \
8993
-v tapd-go-mod-cache:/tmp/build/.modcache \
@@ -175,15 +179,15 @@ docker-release:
175179
@$(call print, "Building release helper docker image.")
176180
if [ "$(tag)" = "" ]; then echo "Must specify tag=<commit_or_tag>!"; exit 1; fi
177181

178-
docker build -t taproot-assets-release-helper -f make/builder.Dockerfile make/
182+
$(DOCKER) build -t taproot-assets-release-helper -f make/builder.Dockerfile make/
179183

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

184188
docker-tools:
185189
@$(call print, "Building tools docker image.")
186-
docker build -q -t taproot-assets-tools $(TOOLS_DIR)
190+
$(DOCKER) build -q -t taproot-assets-tools $(TOOLS_DIR)
187191

188192
scratch: build
189193

make/release_flags.mk

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ 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/IS_PODMAN from Makefile.
12+
13+
# For Podman rootless, use --user=0:0 to avoid permission issues.
14+
# For Docker, use current user to ensure generated files are user-owned.
15+
ifeq ($(IS_PODMAN),1)
16+
USER_ARGS = --user=0:0
17+
else
18+
USER_ARGS = --user $(shell id -u):$(shell id -g)
19+
endif
20+
21+
DOCKER_RELEASE_HELPER = $(DOCKER) run \
1222
--rm \
13-
--user $(shell id -u):$(shell id -g) \
23+
$(USER_ARGS) \
1424
-v $(shell pwd):/tmp/build/taproot-assets \
1525
-v $(shell bash -c "go env GOCACHE || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \
1626
-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)