Skip to content

Commit 8add7e5

Browse files
committed
Rework permission handling in scripts
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent 68bae25 commit 8add7e5

5 files changed

Lines changed: 34 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,32 +415,28 @@ jobs:
415415
- name: Install containerd dependencies
416416
env:
417417
RUNC_FLAVOR: ${{ matrix.runc }}
418-
GOFLAGS: -modcacherw
419418
run: |
420419
sudo apt-get install -y gperf
421-
sudo -E PATH=$PATH script/setup/install-seccomp
422-
sudo -E PATH=$PATH script/setup/install-runc
423-
sudo -E PATH=$PATH script/setup/install-cni $(grep containernetworking/plugins go.mod | awk '{print $2}')
424-
sudo -E PATH=$PATH script/setup/install-critools
420+
script/setup/install-seccomp
421+
script/setup/install-runc
422+
script/setup/install-cni $(grep containernetworking/plugins go.mod | awk '{print $2}')
423+
script/setup/install-critools
424+
script/setup/install-failpoint-binaries
425425
426426
- name: Install criu
427427
run: |
428428
sudo add-apt-repository ppa:criu/ppa
429429
sudo apt-get update
430430
sudo apt-get install -y criu
431431
432-
- name: Install failpoint binaries
433-
run: |
434-
script/setup/install-failpoint-binaries
435-
436432
- name: Install containerd
437433
env:
438434
CGO_ENABLED: 1
439435
run: |
440436
make binaries GO_BUILD_FLAGS="-mod=vendor"
441437
sudo -E PATH=$PATH make install
442438
443-
- run: sudo -E PATH=$PATH script/setup/install-gotestsum
439+
- run: script/setup/install-gotestsum
444440
- name: Tests
445441
env:
446442
GOPROXY: direct
@@ -540,7 +536,7 @@ jobs:
540536
with:
541537
go-version: ${{ env.GO_VERSION }}
542538
- uses: actions/checkout@v2
543-
- run: sudo -E PATH=$PATH script/setup/install-gotestsum
539+
- run: script/setup/install-gotestsum
544540
- name: Tests
545541
env:
546542
GOPROXY: direct

script/setup/install-cni

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ CNI_COMMIT=${1:-$(grep containernetworking/plugins "$GOPATH"/src/github.com/cont
2525
CNI_DIR=${DESTDIR:=''}/opt/cni
2626
CNI_CONFIG_DIR=${DESTDIR}/etc/cni/net.d
2727

28+
# e2e and Cirrus will fail with "sudo: command not found"
29+
SUDO=''
30+
if (( $EUID != 0 )); then
31+
SUDO='sudo'
32+
fi
33+
2834
TMPROOT=$(mktemp -d)
2935
git clone https://github.com/containernetworking/plugins.git "${TMPROOT}"/plugins
3036
pushd "${TMPROOT}"/plugins
3137
git checkout "$CNI_COMMIT"
3238
./build_linux.sh
3339
mkdir -p $CNI_DIR
3440
cp -r ./bin $CNI_DIR
35-
mkdir -p $CNI_CONFIG_DIR
36-
cat << EOF | tee $CNI_CONFIG_DIR/10-containerd-net.conflist
41+
$SUDO mkdir -p $CNI_CONFIG_DIR
42+
$SUDO cat << EOF | $SUDO tee $CNI_CONFIG_DIR/10-containerd-net.conflist
3743
{
3844
"cniVersion": "1.0.0",
3945
"name": "containerd-net",

script/setup/install-critools

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ set -eu -o pipefail
2222

2323
script_dir="$(cd -- "$(dirname -- "$0")" > /dev/null 2>&1; pwd -P)"
2424

25+
# e2e will fail with "sudo: command not found"
26+
SUDO=''
27+
if (( $EUID != 0 )); then
28+
SUDO='sudo'
29+
fi
30+
2531
cd "$(go env GOPATH)"
2632
go install github.com/onsi/ginkgo/v2/[email protected]
2733

@@ -33,10 +39,10 @@ git clone https://github.com/kubernetes-sigs/cri-tools.git "${TMPROOT}/cri-tools
3339
pushd "${TMPROOT}"/cri-tools
3440
git checkout "$CRITEST_COMMIT"
3541
make
36-
make install -e DESTDIR="${DESTDIR}" BINDIR=/usr/local/bin
42+
$SUDO make install -e DESTDIR="${DESTDIR}" BINDIR=/usr/local/bin
3743

3844
mkdir -p "${DESTDIR}/etc/"
39-
cat << EOF | tee "${DESTDIR}/etc/crictl.yaml"
45+
$SUDO cat << EOF | $SUDO tee "${DESTDIR}/etc/crictl.yaml"
4046
runtime-endpoint: unix:///run/containerd/containerd.sock
4147
EOF
4248

script/setup/install-runc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ set -eu -o pipefail
2222

2323
script_dir="$(cd -- "$(dirname -- "$0")" > /dev/null 2>&1; pwd -P)"
2424

25+
# e2e and Cirrus will fail with "sudo: command not found"
26+
SUDO=''
27+
if (( $EUID != 0 )); then
28+
SUDO='sudo'
29+
fi
30+
2531
function install_runc() {
2632
# When updating runc-version, consider updating the runc module in go.mod as well
2733
: "${RUNC_VERSION:=$(cat "${script_dir}/runc-version")}"
@@ -31,15 +37,15 @@ function install_runc() {
3137
pushd "${TMPROOT}"/runc
3238
git checkout "${RUNC_VERSION}"
3339
make BUILDTAGS='seccomp' runc
34-
make install
40+
$SUDO make install
3541
popd
3642
rm -fR "${TMPROOT}"
3743
}
3844

3945
function install_crun() {
4046
: "${CRUN_VERSION:=$(cat "${script_dir}/crun-version")}"
41-
curl -S -o /usr/local/sbin/runc -L https://github.com/containers/crun/releases/download/"${CRUN_VERSION}"/crun-"${CRUN_VERSION}"-linux-"$(go env GOARCH)"
42-
chmod +x /usr/local/sbin/runc
47+
$SUDO curl -S -o /usr/local/sbin/runc -L https://github.com/containers/crun/releases/download/"${CRUN_VERSION}"/crun-"${CRUN_VERSION}"-linux-"$(go env GOARCH)"
48+
$SUDO chmod +x /usr/local/sbin/runc
4349
}
4450

4551
: "${RUNC_FLAVOR:=runc}"

script/setup/install-seccomp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_V
3030
cd "$SECCOMP_PATH"
3131
./configure --prefix=/usr/local
3232
make
33-
make install
34-
ldconfig
33+
sudo make install
34+
sudo ldconfig
3535
)
3636

3737
rm -rf "$SECCOMP_PATH"

0 commit comments

Comments
 (0)