Skip to content

Commit 64ad282

Browse files
[chore] Make the build system compatible with "podman-is-docker". (#1926)
1 parent cd0cbf6 commit 64ad282

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

Makefile

+31-14
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,28 @@ SEMCONVGEN_CONTAINER=$(SEMCONVGEN_CONTAINER_REPOSITORY)/$(VERSIONED_SEMCONVGEN_C
4848
OPA_CONTAINER=$(OPA_CONTAINER_REPOSITORY)/$(VERSIONED_OPA_CONTAINER_NO_REPO)
4949

5050

51-
DOCKER_USER=$(shell id -u):$(shell id -g)
52-
5351
CHECK_TARGETS=install-tools markdownlint misspell table-check compatibility-check \
5452
schema-check check-file-and-folder-names-in-docs
5553

54+
# Determine if "docker" is actually podman
55+
DOCKER_IS_PODMAN=$(docker --version | grep podman | wc -l)
56+
ifeq ($(DOCKER_IS_PODMAN),0)
57+
DOCKER_COMMAND=docker
58+
else
59+
DOCKER_COMMAND=podman
60+
endif
61+
62+
DOCKER_RUN=$(DOCKER_COMMAND) run
63+
DOCKER_USER=$(shell id -u):$(shell id -g)
64+
DOCKER_USER_IS_HOST_USER_ARG=-u $(DOCKER_USER)
65+
ifeq ($(DOCKER_COMMAND),podman)
66+
# On podman, additional arguments are needed to make "-u" work
67+
# correctly with the host user ID and host group ID.
68+
#
69+
# Error: OCI runtime error: crun: setgroups: Invalid argument
70+
DOCKER_USER_IS_HOST_USER_ARG=--userns=keep-id -u $(DOCKER_USER)
71+
endif
72+
5673

5774
# TODO: add `yamllint` step to `all` after making sure it works on Mac.
5875
.PHONY: all
@@ -95,7 +112,7 @@ normalized-link-check:
95112

96113
.PHONY: markdown-link-check
97114
markdown-link-check: normalized-link-check
98-
docker run --rm \
115+
$(DOCKER_RUN) --rm \
99116
--mount 'type=bind,source=$(PWD),target=/home/repo' \
100117
lycheeverse/lychee \
101118
--config home/repo/.lychee.toml \
@@ -106,7 +123,7 @@ markdown-link-check: normalized-link-check
106123

107124
.PHONY: markdown-link-check-changelog-preview
108125
markdown-link-check-changelog-preview:
109-
docker run --rm \
126+
$(DOCKER_RUN) --rm \
110127
--mount 'type=bind,source=$(PWD),target=/home/repo' \
111128
lycheeverse/lychee \
112129
--config /home/repo/.lychee.toml \
@@ -153,8 +170,8 @@ yamllint:
153170
# Generate markdown tables from YAML definitions
154171
.PHONY: table-generation
155172
table-generation:
156-
docker run --rm \
157-
-u $(DOCKER_USER) \
173+
$(DOCKER_RUN) --rm \
174+
$(DOCKER_USER_IS_HOST_USER_ARG) \
158175
--mount 'type=bind,source=$(PWD)/templates,target=/home/weaver/templates,readonly' \
159176
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/source,readonly' \
160177
--mount 'type=bind,source=$(PWD)/docs,target=/home/weaver/target' \
@@ -169,8 +186,8 @@ table-generation:
169186
# Generate attribute registry markdown.
170187
.PHONY: attribute-registry-generation
171188
attribute-registry-generation:
172-
docker run --rm \
173-
-u $(DOCKER_USER) \
189+
$(DOCKER_RUN) --rm \
190+
$(DOCKER_USER_IS_HOST_USER_ARG) \
174191
--mount 'type=bind,source=$(PWD)/templates,target=/home/weaver/templates,readonly' \
175192
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/source,readonly' \
176193
--mount 'type=bind,source=$(PWD)/docs,target=/home/weaver/target' \
@@ -183,7 +200,7 @@ attribute-registry-generation:
183200
# Check if current markdown tables differ from the ones that would be generated from YAML definitions (weaver).
184201
.PHONY: table-check
185202
table-check:
186-
docker run --rm \
203+
$(DOCKER_RUN) --rm \
187204
--mount 'type=bind,source=$(PWD)/templates,target=/home/weaver/templates,readonly' \
188205
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/source,readonly' \
189206
--mount 'type=bind,source=$(PWD)/docs,target=/home/weaver/target,readonly' \
@@ -242,8 +259,8 @@ chlog-update: $(CHLOGGEN)
242259
.PHONY: generate-gh-issue-templates
243260
generate-gh-issue-templates:
244261
mkdir -p $(TOOLS_DIR)/bin
245-
docker run --rm \
246-
-u $(id -u ${USER}):$(id -g ${USER}) \
262+
$(DOCKER_RUN) --rm \
263+
$(DOCKER_USER_IS_HOST_USER_ARG) \
247264
--mount 'type=bind,source=$(PWD)/internal/tools/scripts,target=/home/weaver/templates,readonly' \
248265
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/source,readonly' \
249266
--mount 'type=bind,source=$(TOOLS_DIR)/bin,target=/home/weaver/target' \
@@ -271,7 +288,7 @@ generate-gh-issue-templates:
271288
LATEST_RELEASED_SEMCONV_VERSION := $(shell git ls-remote --tags https://github.com/open-telemetry/semantic-conventions.git | cut -f 2 | sort --reverse | head -n 1 | tr '/' ' ' | cut -d ' ' -f 3 | $(SED) 's/v//g')
272289
.PHONY: check-policies
273290
check-policies:
274-
docker run --rm \
291+
$(DOCKER_RUN) --rm \
275292
--mount 'type=bind,source=$(PWD)/policies,target=/home/weaver/policies,readonly' \
276293
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/source,readonly' \
277294
${WEAVER_CONTAINER} registry check \
@@ -282,7 +299,7 @@ check-policies:
282299
# Test rego policies
283300
.PHONY: test-policies
284301
test-policies:
285-
docker run --rm -v $(PWD)/policies:/policies -v $(PWD)/policies_test:/policies_test \
302+
$(DOCKER_RUN) --rm -v $(PWD)/policies:/policies -v $(PWD)/policies_test:/policies_test \
286303
${OPA_CONTAINER} test \
287304
--var-values \
288305
--explain fails \
@@ -293,5 +310,5 @@ test-policies:
293310
# once github action requirements are updated.
294311
.PHONY: compatibility-check
295312
compatibility-check:
296-
docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec --pull=always \
313+
$(DOCKER_RUN) --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec --pull=always \
297314
$(SEMCONVGEN_CONTAINER) --continue-on-validation-errors -f /source compatibility --previous-version $(LATEST_RELEASED_SEMCONV_VERSION)

0 commit comments

Comments
 (0)