Skip to content

Commit d7da39e

Browse files
committed
install skopeo from source, if missing
1 parent 5345a85 commit d7da39e

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ else
109109
GO111MODULE=on go build -o $(GOPATH)/bin/golangci-lint ./vendor/github.com/golangci/golangci-lint/cmd/golangci-lint
110110
endif
111111

112+
SKOPEO := $(shell command -v skopeo 2> /dev/null)
113+
install-skopeo:
114+
ifdef SKOPEO
115+
@echo "Found skopeo"
116+
skopeo --version
117+
else
118+
@echo "Installing skopeo"
119+
./hack/install-skopeo.sh
120+
endif
121+
122+
# install-skopeo is purposely omitted from this target because it is only
123+
# needed for a single test target (test-e2e-ocl).
112124
install-tools: install-golangci-lint install-go-junit-report install-setup-envtest
113125

114126
# Runs golangci-lint
@@ -203,8 +215,9 @@ test-e2e-techpreview: install-go-junit-report
203215
test-e2e-single-node: install-go-junit-report
204216
set -o pipefail; go test -tags=$(GOTAGS) -failfast -timeout 120m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-single-node/ | ./hack/test-with-junit.sh $(@)
205217

206-
test-e2e-ocl: install-go-junit-report
207-
set -o pipefail; go test -tags=$(GOTAGS) -failfast -timeout 190m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-ocl/ | ./hack/test-with-junit.sh $(@)
218+
test-e2e-ocl: install-go-junit-report install-skopeo
219+
# Temporarily include /tmp/skopeo/bin in our PATH variable so that the test suite can find skopeo.
220+
set -o pipefail; PATH="$(PATH):/tmp/skopeo/bin" go test -tags=$(GOTAGS) -failfast -timeout 190m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-ocl/ | ./hack/test-with-junit.sh $(@)
208221

209222
bootstrap-e2e: install-go-junit-report install-setup-envtest
210223
@echo "Setting up KUBEBUILDER_ASSETS"

hack/install-skopeo.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeuo
4+
5+
# This is an isntallation script for skopeo.
6+
# skopeo is needed by the e2e-gcp-op-ocl test suite since it pushes and pulls images around.
7+
#
8+
# I would much rather use a build-root image for this (see:
9+
# https://docs.ci.openshift.org/docs/architecture/ci-operator/#build-root-image).
10+
# However, that process is a bit more involved. While it would ultimately pay
11+
# off, it is not in-scope with the bug I am trying to resolve. Hence the need
12+
# for this script.
13+
#
14+
# Because of limitations within the builder container image and the context it
15+
# runs in, certain adaptations must be made:
16+
# - The builder image does not run as a privileged user and is denied privilege
17+
# escalation. This means that running dnf install -y skopeo cannot be done.
18+
# - The builder image does not have jq installed, but it does have Python,
19+
# which has a built-in JSON parser in its stdlib. This means we need to use
20+
# Python for any JSON parsing we need to perform.
21+
# - Because this runs as a non-privileged user, we cannot run the make install
22+
# step for skopeo. Instead, we need to append /tmp/skopeo/bin to the PATH. This
23+
# is done in the Makefile and only for the go test invocation.
24+
25+
OPENSHIFT_CI="${OPENSHIFT_CI:-""}"
26+
27+
install_skopeo() {
28+
# If we've already built skopeo once, check if it works and then return.
29+
if [ -f /tmp/skopeo/bin/skopeo ]; then
30+
echo "Prebuilt skopeo found at /tmp/skopeo/bin/skopeo, skipping installation"
31+
/tmp/skopeo/bin/skopeo --version
32+
return 0
33+
fi
34+
35+
# Get the most recent tagged version of skopeo.
36+
skopeo_version="$(curl -s https://api.github.com/repos/containers/skopeo/releases/latest | python3 -c 'import sys, json; print(json.load(sys.stdin)["tag_name"])')"
37+
38+
skopeo_clone_dir="/tmp/skopeo"
39+
40+
mkdir -p "$skopeo_clone_dir"
41+
42+
# Shallow-clone the skopeo repo to the local repo dir.
43+
git clone --branch "$skopeo_version" --depth 1 https://github.com/containers/skopeo.git "$skopeo_clone_dir"
44+
45+
cd "$skopeo_clone_dir"
46+
47+
# Build skopeo
48+
make bin/skopeo
49+
}
50+
51+
# Check if we have skopeo installed first.
52+
if command -v skopeo >/dev/null 2>&1 ; then
53+
# If we do, just output its version.
54+
skopeo --version
55+
else
56+
# Check if we're running in CI.
57+
if [ "$OPENSHIFT_CI" == "true" ]; then
58+
# Only when we're in CI should we install skopeo.
59+
install_skopeo
60+
else
61+
# Otherwise, we should exit with a clear error.
62+
echo "Missing required binary 'skopeo'"
63+
exit 1
64+
fi
65+
fi

0 commit comments

Comments
 (0)