Skip to content

Commit

Permalink
Add support for (make check CHECK_BASE_IMAGES='fedora centos')
Browse files Browse the repository at this point in the history
This is intended for use in Travis (or perhaps also locally).  The
default behavior remains the same, uses the fedora image.

(Note that the (yum install) does not fail when one of the packages
is missing.  This is not a dealbreaker, but it will make diagnosing
future bugs more difficult.)

Uses CentOS 7 because CentOS 8 is missing some necessary -devel packages.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Jun 22, 2020
1 parent 7815c8a commit f1288ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM fedora

RUN dnf -y update && dnf install -y make git golang golang-github-cpuguy83-md2man \
RUN if (. /etc/os-release ; [ "$ID" != centos ]); then dnf=dnf; md2man=golang-github-cpuguy83-md2man; else dnf=yum; md2man=golang-github-cpuguy83-go-md2man; $dnf install -y epel-release; fi \
&& $dnf -y update && $dnf install -y make git golang $md2man \
# storage deps
btrfs-progs-devel \
device-mapper-devel \
Expand All @@ -11,9 +12,9 @@ RUN dnf -y update && dnf install -y make git golang golang-github-cpuguy83-md2ma
httpd-tools \
# OpenShift deps
which tar wget hostname util-linux bsdtar socat ethtool device-mapper iptables tree findutils nmap-ncat e2fsprogs xfsprogs lsof docker iproute \
bats jq podman runc \
bats jq podman runc openssl \
golint \
&& dnf clean all
&& $dnf clean all

# Install two versions of the registry. The first is an older version that
# only supports schema1 manifests. The second is a newer version that supports
Expand Down
49 changes: 33 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ ifeq ($(shell $(GO) env GOOS), linux)
endif

GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
IMAGE := skopeo-dev$(if $(GIT_BRANCH),:$(GIT_BRANCH))
# Default base container image on which to run tests
DEFAULT_BASE := fedora
# Base image for most commands, overridable by command-line arguments
BASE_IMAGE := fedora
# Base images (one or more) used for (make check), overridable by command-line arguments
CHECK_BASE_IMAGES := $(BASE_IMAGE)
# Name for our containers: skopeo-dev[-base-image][:branch]
define image_name
skopeo-dev$(if $(filter-out $(DEFAULT_BASE),$1),-$1)$(if $(GIT_BRANCH),:$(GIT_BRANCH))
endef
# set env like gobuildtag?
CONTAINER_CMD := ${CONTAINER_RUNTIME} run --rm -i -e TESTFLAGS="$(TESTFLAGS)" #$(CONTAINER_ENVS)
# if this session isn't interactive, then we don't want to allocate a
Expand All @@ -58,7 +67,6 @@ INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
ifeq ($(INTERACTIVE), 1)
CONTAINER_CMD += -t
endif
CONTAINER_RUN := $(CONTAINER_CMD) "$(IMAGE)"

GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true)

Expand Down Expand Up @@ -114,8 +122,12 @@ nixpkgs:
bin/skopeo:
$(GPGME_ENV) $(GO) build $(MOD_VENDOR) ${GO_DYN_FLAGS} ${LDFLAGS} -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o $@ ./cmd/skopeo

build-container:
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -t "$(IMAGE)" .
build-container: build-container-$(BASE_IMAGE)
build-container-%:
base=$*; if [ "$$base" = centos ]; then base=centos:7; fi; \
dockerfile=$$(mktemp -p .); sed "s/^FROM fedora/FROM $$base/" Dockerfile > "$$dockerfile"; \
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f $$dockerfile -t "$(call image_name,$*)" . ; exit=$$?; \
rm "$$dockerfile"; exit $$exit

$(MANPAGES): %: %.md
@sed -e 's/\((skopeo.*\.md)\)//' -e 's/\[\(skopeo.*\)\]/\1/' $< | $(GOMD2MAN) -in /dev/stdin -out $@
Expand Down Expand Up @@ -149,32 +161,37 @@ install-completions:
install -m 755 -d ${BASHINSTALLDIR}
install -m 644 completions/bash/skopeo ${BASHINSTALLDIR}/skopeo

shell: build-container
$(CONTAINER_RUN) bash
shell: shell-$(BASE_IMAGE)
shell-%: build-container-%
$(CONTAINER_CMD) "$(call image_name,$*)" bash

check: validate test-unit test-integration test-system
check: $(foreach image,$(CHECK_BASE_IMAGES),validate-$(image) test-unit-$(image) test-integration-$(image) test-system-$(image))

test-integration: test-integration-$(BASE_IMAGE)
# The tests can run out of entropy and block in containers, so replace /dev/random.
test-integration: build-container
$(CONTAINER_RUN) bash -c 'rm -f /dev/random; ln -sf /dev/urandom /dev/random; SKOPEO_CONTAINER_TESTS=1 BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-integration'
test-integration-%: build-container-%
$(CONTAINER_CMD) "$(call image_name,$*)" bash -c 'rm -f /dev/random; ln -sf /dev/urandom /dev/random; SKOPEO_CONTAINER_TESTS=1 BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-integration'

test-system: test-system-$(BASE_IMAGE)
# complicated set of options needed to run podman-in-podman
test-system: build-container
test-system-%: build-container-%
DTEMP=$(shell mktemp -d --tmpdir=/var/tmp podman-tmp.XXXXXX); \
$(CONTAINER_CMD) --privileged \
-v $$DTEMP:/var/lib/containers:Z -v /run/systemd/journal/socket:/run/systemd/journal/socket \
"$(IMAGE)" \
"$(call image_name,$*)" \
bash -c 'BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-system'; \
rc=$$?; \
$(RM) -rf $$DTEMP; \
exit $$rc

test-unit: build-container
# Just call (make test unit-local) here instead of worrying about environment differences
$(CONTAINER_RUN) make test-unit-local BUILDTAGS='$(BUILDTAGS)'
test-unit: test-unit-$(BASE_IMAGE)
# Just call (make test unit-local) here instead of worrying about environment differences
test-unit-%: build-container-%
$(CONTAINER_CMD) "$(call image_name,$*)" make test-unit-local BUILDTAGS='$(BUILDTAGS)'

validate: build-container
$(CONTAINER_RUN) hack/make.sh validate-git-marks validate-gofmt validate-lint validate-vet
validate: validate-$(BASE_IMAGE)
validate-%: build-container-%
$(CONTAINER_CMD) "$(call image_name,$*)" hack/make.sh validate-git-marks validate-gofmt validate-lint validate-vet

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

0 comments on commit f1288ef

Please sign in to comment.