Skip to content

Commit 46e46c2

Browse files
committed
ci: do not use custom ssh user for image tests
With lima we already run as rootless user so just run the tests as that user. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
1 parent 6f419aa commit 46e46c2

1 file changed

Lines changed: 8 additions & 39 deletions

File tree

hack/ci/runner.sh

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,6 @@ prepare_storage_env() {
2727
done
2828
}
2929

30-
prepare_image_env() {
31-
ROOTLESS_USER="testuser$$"
32-
rootless_uid=$((RANDOM+1000))
33-
rootless_gid=$((RANDOM+1000))
34-
sudo groupadd -g $rootless_gid $ROOTLESS_USER
35-
sudo useradd -g $rootless_gid -u $rootless_uid --no-user-group --create-home $ROOTLESS_USER
36-
37-
sudo mkdir -p "$(go env GOPATH)"
38-
sudo chown -R $ROOTLESS_USER:$ROOTLESS_USER "$(go env GOPATH)"
39-
sudo chown -R $ROOTLESS_USER:$ROOTLESS_USER "$(pwd)"
40-
41-
sudo mkdir -p "/run/user/$rootless_uid"
42-
sudo chown $ROOTLESS_USER:$ROOTLESS_USER "/run/user/$rootless_uid"
43-
44-
sudo mkdir -p /root/.ssh "/home/$ROOTLESS_USER/.ssh"
45-
sudo ssh-keygen -t ed25519 -P "" -f /root/.ssh/id_ed25519
46-
sudo bash -c "cat /root/.ssh/*.pub >> /home/$ROOTLESS_USER/.ssh/authorized_keys"
47-
sudo chmod -R 700 /root/.ssh "/home/$ROOTLESS_USER/.ssh"
48-
sudo chown -R $ROOTLESS_USER:$ROOTLESS_USER "/home/$ROOTLESS_USER/.ssh"
49-
50-
sudo systemctl start sshd || sudo systemctl start ssh
51-
sudo ssh-keyscan localhost > /tmp/known_hosts
52-
sudo cp /tmp/known_hosts /root/.ssh/known_hosts
53-
54-
export ROOTLESS_USER rootless_uid
55-
}
56-
5730
###############################################################################
5831
# Test runners
5932
###############################################################################
@@ -143,26 +116,22 @@ run_image() {
143116
sed -n 's/func \(Test[[:alnum:]]*\)(.*/^\1$$/p' |
144117
paste -sd "|" -)
145118
if [ -n "$test_filter" ]; then
146-
sudo -E env "PATH=$PATH" "GOPATH=$GOPATH_DIR" "HOME=$HOME" \
119+
sudo -E env "PATH=$PATH" "GOPATH=$GOPATH_DIR" \
147120
make test "BUILDTAGS=$BUILDTAGS" "TESTFLAGS=-v -run '$test_filter'" TEST_PACKAGES=./storage
148121
fi
149122

123+
# Restore permissions
124+
sudo chown -R $(id -u):$(id -g) "$GOPATH_DIR"
125+
150126
# Run rootless tests
151127
cleanup() {
152-
sudo ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_ed25519 \
153-
$ROOTLESS_USER@localhost \
154-
"export XDG_RUNTIME_DIR=/run/user/$rootless_uid && export PATH=$GOROOT_DIR/bin:\$PATH && bash $GOSRC/image/signature/sigstore/rekor/testdata/start-rekor.sh ci remove" || true
155-
sudo chown -R $(id -u):$(id -g) "$GOPATH_DIR" "$GOSRC"
128+
$GOSRC/image/signature/sigstore/rekor/testdata/start-rekor.sh ci remove || true
156129
}
157130
trap cleanup EXIT
158131

159-
sudo ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_ed25519 \
160-
$ROOTLESS_USER@localhost \
161-
"export XDG_RUNTIME_DIR=/run/user/$rootless_uid && export PATH=$GOROOT_DIR/bin:\$PATH && export GOPATH=$GOPATH_DIR && bash $GOSRC/image/signature/sigstore/rekor/testdata/start-rekor.sh ci"
162-
163-
sudo ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_ed25519 \
164-
$ROOTLESS_USER@localhost \
165-
"export XDG_RUNTIME_DIR=/run/user/$rootless_uid && export PATH=$GOROOT_DIR/bin:\$PATH && export GOPATH=$GOPATH_DIR && cd $GOSRC/image && make test BUILDTAGS='$BUILDTAGS' TESTFLAGS=-v REKOR_SERVER_URL='http://127.0.0.1:3000'"
132+
# start custom rekor which is needed by the tests
133+
$GOSRC/image/signature/sigstore/rekor/testdata/start-rekor.sh ci
134+
make test BUILDTAGS='$BUILDTAGS' TESTFLAGS=-v REKOR_SERVER_URL='http://127.0.0.1:3000'
166135
}
167136

168137
run_image_skopeo() {

0 commit comments

Comments
 (0)