Skip to content

Commit e826f0c

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 2e76b0b commit e826f0c

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

Makefile

Lines changed: 20 additions & 8 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,7 +207,8 @@ 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.
@@ -214,7 +223,8 @@ test-system:
214223
-v $(CURDIR):$(CONTAINER_GOSRC) -w $(CONTAINER_GOSRC) \
215224
-v $$DTEMP:/var/lib/containers:Z -v /run/systemd/journal/socket:/run/systemd/journal/socket \
216225
"$(SKOPEO_CIDEV_CONTAINER_FQIN)" \
217-
$(MAKE) test-system-local; \
226+
bash -c \
227+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) test-system-local;" \
218228
rc=$$?; \
219229
$(CONTAINER_RUNTIME) unshare rm -rf $$DTEMP; # This probably doesn't work with Docker, oh well, better than nothing... \
220230
exit $$rc
@@ -226,16 +236,18 @@ test-system-local: bin/skopeo
226236

227237
test-unit:
228238
# Just call (make test unit-local) here instead of worrying about environment differences
229-
$(CONTAINER_RUN) $(MAKE) test-unit-local
239+
$(CONTAINER_RUN) bash -c \
240+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) test-unit-local"
230241

231242
validate:
232-
$(CONTAINER_RUN) $(MAKE) validate-local
243+
$(CONTAINER_RUN) bash -c \
244+
"git config --global --add safe.directory $(CONTAINER_GOSRC) && $(MAKE) validate-local"
233245

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

237249
.PHONY: validate-local
238-
validate-local:
250+
validate-local: tools
239251
hack/validate-git-marks.sh
240252
hack/validate-gofmt.sh
241253
GOBIN=$(GOBIN) hack/validate-lint.sh

0 commit comments

Comments
 (0)