Skip to content

Commit 2030d63

Browse files
committed
Fix containerized tests and builds
The containerized targets weren't working everywhere due to a few missing items. These are corrected so containerized tests and builds will successfully. Signed-off-by: Ryan Egesdahl <[email protected]>
1 parent a28ea75 commit 2030d63

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

Makefile

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ GO ?= go
2323
GOBIN := $(shell $(GO) env GOBIN)
2424
GOOS ?= $(shell go env GOOS)
2525
GOARCH ?= $(shell go env GOARCH)
26+
GOPATH ?= $(shell go env GOPATH)
2627

2728
# N/B: This value is managed by Renovate, manual changes are
2829
# possible, as long as they don't disturb the formatting
2930
# (i.e. DO NOT ADD A 'v' prefix!)
3031
GOLANGCI_LINT_VERSION := 1.55.2
3132

33+
GO_MD2MAN_VERSION := 2.0.3
34+
3235
ifeq ($(GOBIN),)
3336
GOBIN := $(GOPATH)/bin
3437
endif
@@ -82,7 +85,7 @@ endif
8285
CONTAINER_GOSRC = /src/github.com/containers/skopeo
8386
CONTAINER_RUN ?= $(CONTAINER_CMD) --security-opt label=disable -v $(CURDIR):$(CONTAINER_GOSRC) -w $(CONTAINER_GOSRC) $(SKOPEO_CIDEV_CONTAINER_FQIN)
8487

85-
GIT_COMMIT := $(shell GIT_CEILING_DIRECTORIES=$$(cd ..; pwd) git rev-parse HEAD 2> /dev/null || true)
88+
GIT_COMMIT := $(shell GIT_CEILING_DIRECTORIES=$$(cd ..; pwd) git rev-parse HEAD || true)
8689

8790
EXTRA_LDFLAGS ?=
8891
SKOPEO_LDFLAGS := -ldflags '-X main.gitCommit=${GIT_COMMIT} $(EXTRA_LDFLAGS)'
@@ -127,7 +130,8 @@ help:
127130

128131
# Do the build and the output (skopeo) should appear in current dir
129132
binary: cmd/skopeo
130-
$(CONTAINER_RUN) make bin/skopeo $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
133+
$(CONTAINER_RUN) bash -c \
134+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && make bin/skopeo $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'"
131135

132136
# Build w/o using containers
133137
.PHONY: bin/skopeo
@@ -145,7 +149,8 @@ endif
145149
docs: $(MANPAGES)
146150

147151
docs-in-container:
148-
${CONTAINER_RUN} $(MAKE) docs $(if $(DEBUG),DEBUG=$(DEBUG))
152+
${CONTAINER_RUN} bash -c \
153+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) docs $(if $(DEBUG),DEBUG=$(DEBUG))"
149154

150155
.PHONY: completions
151156
completions: bin/skopeo
@@ -188,6 +193,9 @@ shell:
188193
$(CONTAINER_RUN) bash
189194

190195
tools:
196+
if [ ! -x "$(GOBIN)/go-md2man" ]; then \
197+
go install github.com/cpuguy83/go-md2man/v2@v$(GO_MD2MAN_VERSION) ; \
198+
fi
191199
if [ ! -x "$(GOBIN)/golangci-lint" ]; then \
192200
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v$(GOLANGCI_LINT_VERSION) ; \
193201
fi
@@ -199,25 +207,36 @@ test-integration:
199207
# --cap-add=cap_mknod is important to allow skopeo to use containers-storage: directly as it exists in the callers’ environment, without
200208
# creating a nested user namespace (which requires /etc/subuid and /etc/subgid to be set up)
201209
$(CONTAINER_CMD) --security-opt label=disable --cap-add=cap_mknod -v $(CURDIR):$(CONTAINER_GOSRC) -w $(CONTAINER_GOSRC) $(SKOPEO_CIDEV_CONTAINER_FQIN) \
202-
$(MAKE) test-integration-local
210+
bash -c \
211+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) test-integration-local"
203212

204213

205214
# Intended for CI, assumed to be running in quay.io/libpod/skopeo_cidev container.
206215
test-integration-local: bin/skopeo
207216
hack/warn-destructive-tests.sh
208217
hack/test-integration.sh
209218

210-
# complicated set of options needed to run podman-in-podman
211219
test-system:
212-
DTEMP=$(shell mktemp -d --tmpdir=/var/tmp podman-tmp.XXXXXX); \
213-
$(CONTAINER_CMD) --privileged \
214-
-v $(CURDIR):$(CONTAINER_GOSRC) -w $(CONTAINER_GOSRC) \
215-
-v $$DTEMP:/var/lib/containers:Z -v /run/systemd/journal/socket:/run/systemd/journal/socket \
216-
"$(SKOPEO_CIDEV_CONTAINER_FQIN)" \
217-
$(MAKE) test-system-local; \
218-
rc=$$?; \
219-
$(CONTAINER_RUNTIME) unshare rm -rf $$DTEMP; # This probably doesn't work with Docker, oh well, better than nothing... \
220-
exit $$rc
220+
# complicated set of options needed to run podman-in-podman
221+
if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \
222+
DTEMP=$(shell mktemp -d --tmpdir=/var/tmp podman-tmp.XXXXXX); \
223+
$(CONTAINER_CMD) --privileged \
224+
-v $(CURDIR):$(CONTAINER_GOSRC) -w $(CONTAINER_GOSRC) \
225+
-v $$DTEMP:/var/lib/containers:Z -v /run/systemd/journal/socket:/run/systemd/journal/socket \
226+
"$(SKOPEO_CIDEV_CONTAINER_FQIN)" \
227+
bash -c \
228+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) test-system-local"; \
229+
rc=$$?; \
230+
$(CONTAINER_RUNTIME) unshare rm -rf $$DTEMP; \
231+
exit $$rc; \
232+
else \
233+
$(CONTAINER_CMD) --privileged \
234+
-v $(CURDIR):$(CONTAINER_GOSRC) -w $(CONTAINER_GOSRC) \
235+
-v /run/systemd/journal/socket:/run/systemd/journal/socket \
236+
"$(SKOPEO_CIDEV_CONTAINER_FQIN)" \
237+
bash -c \
238+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) test-system-local"; \
239+
fi;
221240

222241
# Intended for CI, assumed to already be running in quay.io/libpod/skopeo_cidev container.
223242
test-system-local: bin/skopeo
@@ -226,16 +245,18 @@ test-system-local: bin/skopeo
226245

227246
test-unit:
228247
# Just call (make test unit-local) here instead of worrying about environment differences
229-
$(CONTAINER_RUN) $(MAKE) test-unit-local
248+
$(CONTAINER_RUN) bash -c \
249+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) test-unit-local"
230250

231251
validate:
232-
$(CONTAINER_RUN) $(MAKE) validate-local
252+
$(CONTAINER_RUN) bash -c \
253+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) validate-local"
233254

234255
# This target is only intended for development, e.g. executing it from an IDE. Use (make test) for CI or pre-release testing.
235256
test-all-local: validate-local validate-docs test-unit-local
236257

237258
.PHONY: validate-local
238-
validate-local:
259+
validate-local: tools
239260
hack/validate-git-marks.sh
240261
hack/validate-gofmt.sh
241262
GOBIN=$(GOBIN) hack/validate-lint.sh

0 commit comments

Comments
 (0)