Skip to content

Commit a518fd3

Browse files
committed
Reduce sudo
We are using sudo too much. While there are operations that only root can do (chown, mount, ...), go and make don't need root. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 1441f91 commit a518fd3

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

.buildkite/pipeline.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ steps:
7878
- make deps
7979
# Build a rootfs with SSH enabled.
8080
- sudo -E FC_TEST_DATA_PATH=${FC_TEST_DATA_PATH} make ${FC_TEST_DATA_PATH}/root-drive-ssh-key
81-
- stat ${FC_TEST_DATA_PATH}/root-drive-ssh-key ${FC_TEST_DATA_PATH}/root-drive-with-ssh.img
81+
- sudo chown $USER ${FC_TEST_DATA_PATH}/root-drive-ssh-key ${FC_TEST_DATA_PATH}/root-drive-with-ssh.img
8282
agents:
8383
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
8484
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
@@ -103,8 +103,11 @@ steps:
103103

104104
- label: ':book: examples'
105105
commands:
106-
- "sudo -E PATH=$PATH FC_TEST_DATA_PATH=${FC_TEST_DATA_PATH} make -C examples/cmd/snapshotting run"
107-
- "sudo -E PATH=$PATH FC_TEST_DATA_PATH=${FC_TEST_DATA_PATH} make -C examples/cmd/snapshotting clean"
106+
- cp ${FC_TEST_DATA_PATH}/root-drive-ssh-key ${FC_TEST_DATA_PATH}/root-drive-with-ssh.img ${FC_TEST_DATA_PATH}/vmlinux examples/cmd/snapshotting
107+
- cd examples/cmd/snapshotting
108+
- make all
109+
- export FC_TEST_DATA_PATH=${FC_TEST_DATA_PATH}
110+
- sudo -E make run clean
108111
agents:
109112
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
110113
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
@@ -120,7 +123,9 @@ steps:
120123

121124
- label: ':hammer: root tests'
122125
commands:
123-
- "sudo -E PATH=$PATH FC_TEST_TAP=fc-root-tap${BUILDKITE_BUILD_NUMBER} FC_TEST_DATA_PATH=${FC_TEST_DATA_PATH} make test EXTRAGOARGS='-v -count=1 -race' DISABLE_ROOT_TESTS="
126+
- export FC_TEST_TAP=fc-root-tap${BUILDKITE_BUILD_NUMBER}
127+
- export FC_TEST_DATA_PATH=${FC_TEST_DATA_PATH}
128+
- make test EXTRAGOARGS="-exec 'sudo -E' -count=1 -race" DISABLE_ROOT_TESTS=
124129
agents:
125130
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
126131
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"
@@ -132,7 +137,8 @@ steps:
132137
FC_TEST_JAILER_BIN: "${FC_TEST_DATA_PATH}/jailer-main"
133138
DOCKER_IMAGE_TAG: "$BUILDKITE_BUILD_NUMBER"
134139
commands:
135-
- "sudo -E PATH=$PATH FC_TEST_TAP=fc-mst-tap${BUILDKITE_BUILD_NUMBER} make test EXTRAGOARGS='-v -count=1 -race' DISABLE_ROOT_TESTS="
140+
- export FC_TEST_TAP=fc-mst-tap${BUILDKITE_BUILD_NUMBER}
141+
- make test EXTRAGOARGS="-exec 'sudo -E' -v -count=1 -race" DISABLE_ROOT_TESTS=
136142
agents:
137143
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
138144
distro: "${BUILDKITE_AGENT_META_DATA_DISTRO}"

examples/cmd/snapshotting/Makefile

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ else
3333
endef
3434
endif
3535

36-
all: plugins image vmlinux firecracker
36+
all: snapshot-example plugins root-drive-with-ssh.img root-drive-ssh-key vmlinux firecracker
3737

3838
plugins: bin/tc-redirect-tap bin/ptp bin/host-local | bin
3939

@@ -48,15 +48,6 @@ bin/ptp: bin
4848

4949
bin/host-local: bin
5050
$(call install_go,github.com/containernetworking/plugins/plugins/ipam/host-local,v1.1.1)
51-
52-
image:
53-
ifeq ($(GID), 0)
54-
- cp ${FC_TEST_DATA_PATH}/root-drive-with-ssh.img root-drive-with-ssh.img
55-
- cp ${FC_TEST_DATA_PATH}/root-drive-ssh-key root-drive-ssh-key
56-
$(MAKE) root-drive-with-ssh.img root-drive-ssh-key
57-
else
58-
$(error unable to place ssh key without root permissions)
59-
endif
6051

6152
vmlinux:
6253
curl --location -o vmlinux https://s3.amazonaws.com/spec.ccfc.min/img/quickstart_guide/${ARCH}/kernels/vmlinux.bin
@@ -74,10 +65,13 @@ root-drive-with-ssh.img root-drive-ssh-key:
7465
cp temp/build/rootfs/ssh/id_rsa root-drive-ssh-key
7566
rm -rf temp
7667

77-
run: all
78-
go run example_demo.go
68+
snapshot-example:
69+
go build -o $@
70+
71+
run: snapshot-example
72+
./snapshot-example
7973

8074
clean:
8175
rm -rf bin firecracker root-drive-ssh-key root-drive-with-ssh.img vmlinux
8276

83-
.PHONY: all clean image plugins run
77+
.PHONY: all clean plugins run

0 commit comments

Comments
 (0)