Debian Codegraph @

Vagrantfile

raw
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3
4 # Copyright The containerd Authors.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9
10 # http://www.apache.org/licenses/LICENSE-2.0
11
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 # Vagrantfile for Fedora and EL
19 Vagrant.configure("2") do |config|
20 config.vm.box = ENV["BOX"] ? ENV["BOX"].split("@")[0] : "fedora/43-cloud-base"
21 # BOX_VERSION is deprecated. Use "BOX=<BOX>@<BOX_VERSION>".
22 config.vm.box_version = ENV["BOX_VERSION"] || (ENV["BOX"].split("@")[1] if ENV["BOX"])
23
24 memory = 4096
25 cpus = 2
26 disk_size = 60
27 config.vm.provider :virtualbox do |v, o|
28 v.memory = memory
29 v.cpus = cpus
30 # Needs env var VAGRANT_EXPERIMENTAL="disks"
31 o.vm.disk :disk, size: "#{disk_size}GB", primary: true
32 v.customize ["modifyvm", :id, "--firmware", "efi"]
33 end
34 config.vm.provider :libvirt do |v|
35 v.memory = memory
36 v.cpus = cpus
37 v.machine_virtual_size = disk_size
38 # https://github.com/vagrant-libvirt/vagrant-libvirt/issues/1725#issuecomment-1454058646
39 # Needs `sudo cp /usr/share/OVMF/OVMF_VARS_4M.fd /var/lib/libvirt/qemu/nvram/`
40 v.loader = '/usr/share/OVMF/OVMF_CODE_4M.fd'
41 v.nvram = '/var/lib/libvirt/qemu/nvram/OVMF_VARS_4M.fd'
42 end
43
44 config.vm.synced_folder ".", "/vagrant", type: "rsync"
45
46 config.vm.provision 'shell', path: 'script/resize-vagrant-root.sh'
47
48 # Disabled by default. To run:
49 # vagrant up --provision-with=upgrade-packages
50 # To upgrade only specific packages:
51 # UPGRADE_PACKAGES=selinux vagrant up --provision-with=upgrade-packages
52 #
53 config.vm.provision "upgrade-packages", type: "shell", run: "never" do |sh|
54 sh.upload_path = "/tmp/vagrant-upgrade-packages"
55 sh.env = {
56 'UPGRADE_PACKAGES': ENV['UPGRADE_PACKAGES'],
57 }
58 sh.inline = <<~SHELL
59 #!/usr/bin/env bash
60 set -eux -o pipefail
61 dnf -y upgrade ${UPGRADE_PACKAGES}
62 SHELL
63 end
64
65 # To re-run, installing CNI from RPM:
66 # INSTALL_PACKAGES="containernetworking-plugins" vagrant up --provision-with=install-packages
67 #
68 config.vm.provision "install-packages", type: "shell", run: "once" do |sh|
69 sh.upload_path = "/tmp/vagrant-install-packages"
70 sh.env = {
71 'INSTALL_PACKAGES': ENV['INSTALL_PACKAGES'],
72 }
73 sh.inline = <<~SHELL
74 #!/usr/bin/env bash
75 set -eux -o pipefail
76 dnf -y install \
77 container-selinux \
78 curl \
79 gcc \
80 git \
81 iptables \
82 libseccomp-devel \
83 libselinux-devel \
84 lsof \
85 make \
86 strace \
87 kernel-modules-extra-$(uname -r) \
88 ${INSTALL_PACKAGES}
89 modprobe xt_comment
90 SHELL
91 end
92
93 # EL does not have /usr/local/{bin,sbin} in the PATH by default
94 config.vm.provision "setup-etc-environment", type: "shell", run: "once" do |sh|
95 sh.upload_path = "/tmp/vagrant-setup-etc-environment"
96 sh.inline = <<~SHELL
97 #!/usr/bin/env bash
98 set -eux -o pipefail
99 cat >> /etc/environment <<EOF
100 PATH=/usr/local/go/bin:/usr/local/bin:/usr/local/sbin:$PATH
101 EOF
102 source /etc/environment
103 SHELL
104 end
105
106 # To re-run this provisioner, installing a different version of go:
107 # GO_VERSION="1.14.6" vagrant up --provision-with=install-golang
108 #
109 config.vm.provision "install-golang", type: "shell", run: "once" do |sh|
110 sh.upload_path = "/tmp/vagrant-install-golang"
111 sh.env = {
112 'GO_VERSION': ENV['GO_VERSION'] || "1.25.11",
113 }
114 sh.inline = <<~SHELL
115 #!/usr/bin/env bash
116 set -eux -o pipefail
117 curl -fsSL "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" | tar Cxz /usr/local
118 cat >> /etc/profile.d/sh.local <<EOF
119 GOPATH=\\$HOME/go
120 PATH=\\$GOPATH/bin:\\$PATH
121 export GOPATH PATH
122 git config --global --add safe.directory /vagrant
123 EOF
124 source /etc/profile.d/sh.local
125 SHELL
126 end
127
128 config.vm.provision "setup-gopath", type: "shell", run: "once" do |sh|
129 sh.upload_path = "/tmp/vagrant-setup-gopath"
130 sh.inline = <<~SHELL
131 #!/usr/bin/env bash
132 source /etc/environment
133 source /etc/profile.d/sh.local
134 set -eux -o pipefail
135 mkdir -p ${GOPATH}/src/github.com/containerd
136 ln -fnsv /vagrant ${GOPATH}/src/github.com/containerd/containerd
137 SHELL
138 end
139
140 config.vm.provision "install-runc", type: "shell", run: "once" do |sh|
141 sh.upload_path = "/tmp/vagrant-install-runc"
142 sh.env = {
143 'RUNC_FLAVOR': ENV['RUNC_FLAVOR'] || "runc",
144 }
145 sh.inline = <<~SHELL
146 #!/usr/bin/env bash
147 source /etc/environment
148 source /etc/profile.d/sh.local
149 set -eux -o pipefail
150 ${GOPATH}/src/github.com/containerd/containerd/script/setup/install-runc
151 type runc
152 runc --version
153 chcon -v -t container_runtime_exec_t $(type -ap runc)
154 SHELL
155 end
156
157 config.vm.provision "install-cni", type: "shell", run: "once" do |sh|
158 sh.upload_path = "/tmp/vagrant-install-cni"
159 sh.env = {
160 'CNI_BINARIES': 'bridge dhcp flannel host-device host-local ipvlan loopback macvlan portmap ptp tuning vlan',
161 }
162 sh.inline = <<~SHELL
163 #!/usr/bin/env bash
164 source /etc/environment
165 source /etc/profile.d/sh.local
166 set -eux -o pipefail
167 cd ${GOPATH}/src/github.com/containerd/containerd
168 script/setup/install-cni
169 PATH=/opt/cni/bin:$PATH type ${CNI_BINARIES} || true
170 SHELL
171 end
172
173 config.vm.provision "install-cri-tools", type: "shell", run: "once" do |sh|
174 sh.upload_path = "/tmp/vagrant-install-cri-tools"
175 sh.env = {
176 'CRI_TOOLS_VERSION': ENV['CRI_TOOLS_VERSION'] || '16911795a3c33833fa0ec83dac1ade3172f6989e',
177 'GOBIN': '/usr/local/bin',
178 }
179 sh.inline = <<~SHELL
180 #!/usr/bin/env bash
181 source /etc/environment
182 source /etc/profile.d/sh.local
183 set -eux -o pipefail
184 ${GOPATH}/src/github.com/containerd/containerd/script/setup/install-critools
185 type crictl critest
186 critest --version
187 SHELL
188 end
189
190 config.vm.provision "install-containerd", type: "shell", run: "once" do |sh|
191 sh.upload_path = "/tmp/vagrant-install-containerd"
192 sh.inline = <<~SHELL
193 #!/usr/bin/env bash
194 source /etc/environment
195 source /etc/profile.d/sh.local
196 set -eux -o pipefail
197 cd ${GOPATH}/src/github.com/containerd/containerd
198 make BUILDTAGS="seccomp selinux no_btrfs no_devmapper no_zfs" binaries install
199 type containerd
200 containerd --version
201 chcon -v -t container_runtime_exec_t /usr/local/bin/{containerd,containerd-shim*}
202 ./script/setup/config-containerd
203 SHELL
204 end
205
206 config.vm.provision "install-gotestsum", type: "shell", run: "once" do |sh|
207 sh.upload_path = "/tmp/vagrant-install-gotestsum"
208 sh.inline = <<~SHELL
209 #!/usr/bin/env bash
210 source /etc/environment
211 source /etc/profile.d/sh.local
212 set -eux -o pipefail
213 ${GOPATH}/src/github.com/containerd/containerd/script/setup/install-gotestsum
214 sudo cp ${GOPATH}/bin/gotestsum /usr/local/bin/
215 SHELL
216 end
217
218 config.vm.provision "install-failpoint-binaries", type: "shell", run: "once" do |sh|
219 sh.upload_path = "/tmp/vagrant-install-failpoint-binaries"
220 sh.inline = <<~SHELL
221 #!/usr/bin/env bash
222 source /etc/environment
223 source /etc/profile.d/sh.local
224 set -eux -o pipefail
225 ${GOPATH}/src/github.com/containerd/containerd/script/setup/install-failpoint-binaries
226 chcon -v -t container_runtime_exec_t $(type -ap containerd-shim-runc-fp-v1)
227 containerd-shim-runc-fp-v1 -v
228 SHELL
229 end
230
231 # SELinux is Enforcing by default.
232 # To set SELinux as Disabled on a VM that has already been provisioned:
233 # SELINUX=Disabled vagrant up --provision-with=selinux
234 # To set SELinux as Permissive on a VM that has already been provsioned
235 # SELINUX=Permissive vagrant up --provision-with=selinux
236 config.vm.provision "selinux", type: "shell", run: "never" do |sh|
237 sh.upload_path = "/tmp/vagrant-selinux"
238 sh.env = {
239 'SELINUX': ENV['SELINUX'] || "Enforcing"
240 }
241 sh.inline = <<~SHELL
242 /vagrant/script/setup/config-selinux
243 /vagrant/script/setup/config-containerd
244 SHELL
245 end
246
247 # SELinux is Enforcing by default (via provisioning) in this VM. To re-run with SELinux disabled:
248 # SELINUX=Disabled vagrant up --provision-with=selinux,test-integration
249 #
250 config.vm.provision "test-integration", type: "shell", run: "never" do |sh|
251 sh.upload_path = "/tmp/test-integration"
252 sh.env = {
253 'RUNC_FLAVOR': ENV['RUNC_FLAVOR'] || "runc",
254 'GOTEST': ENV['GOTEST'] || "go test",
255 'GOTESTSUM_JUNITFILE': ENV['GOTESTSUM_JUNITFILE'],
256 'GOTESTSUM_JSONFILE': ENV['GOTESTSUM_JSONFILE'],
257 }
258 sh.inline = <<~SHELL
259 #!/usr/bin/env bash
260 source /etc/environment
261 source /etc/profile.d/sh.local
262 set -eux -o pipefail
263 rm -rf /var/lib/containerd-test /run/containerd-test
264 cd ${GOPATH}/src/github.com/containerd/containerd
265 go test -v -count=1 -race ./core/metrics/cgroups
266 make integration EXTRA_TESTFLAGS="-timeout 15m -no-criu -test.v" TEST_RUNTIME=io.containerd.runc.v2 RUNC_FLAVOR=$RUNC_FLAVOR
267 SHELL
268 end
269
270 # SELinux is Enforcing by default (via provisioning) in this VM. To re-run with SELinux disabled:
271 # SELINUX=Disabled vagrant up --provision-with=selinux,test-cri-integration
272 #
273 config.vm.provision "test-cri-integration", type: "shell", run: "never" do |sh|
274 sh.upload_path = "/tmp/test-cri-integration"
275 sh.env = {
276 'GOTEST': ENV['GOTEST'] || "go test",
277 'GOTESTSUM_JUNITFILE': ENV['GOTESTSUM_JUNITFILE'],
278 'GOTESTSUM_JSONFILE': ENV['GOTESTSUM_JSONFILE'],
279 'GITHUB_WORKSPACE': '',
280 'CGROUP_DRIVER': ENV['CGROUP_DRIVER'],
281 'RUNC_FLAVOR': ENV['RUNC_FLAVOR'] || "runc",
282 }
283 sh.inline = <<~SHELL
284 #!/usr/bin/env bash
285 source /etc/environment
286 source /etc/profile.d/sh.local
287 set -eux -o pipefail
288 cleanup() {
289 rm -rf /var/lib/containerd* /run/containerd* /tmp/containerd* /tmp/test* /tmp/failpoint* /tmp/nri*
290 }
291 cleanup
292 cd ${GOPATH}/src/github.com/containerd/containerd
293 # cri-integration.sh executes containerd from ./bin, not from $PATH .
294 make BUILDTAGS="seccomp selinux no_btrfs no_devmapper no_zfs" binaries bin/cri-integration.test
295 chcon -v -t container_runtime_exec_t ./bin/{containerd,containerd-shim*}
296 CONTAINERD_RUNTIME=io.containerd.runc.v2 ./script/test/cri-integration.sh
297 cleanup
298 SHELL
299 end
300
301 # SELinux is Enforcing by default (via provisioning) in this VM. To re-run with SELinux disabled:
302 # SELINUX=Disabled vagrant up --provision-with=selinux,test-cri
303 #
304 config.vm.provision "test-cri", type: "shell", run: "never" do |sh|
305 sh.upload_path = "/tmp/test-cri"
306 sh.env = {
307 'GOTEST': ENV['GOTEST'] || "go test",
308 'REPORT_DIR': ENV['REPORT_DIR'],
309 'CGROUP_DRIVER': ENV['CGROUP_DRIVER'],
310 'RUNC_FLAVOR': ENV['RUNC_FLAVOR'] || "runc",
311 }
312 sh.inline = <<~SHELL
313 #!/usr/bin/env bash
314 source /etc/environment
315 source /etc/profile.d/sh.local
316 set -eux -o pipefail
317 systemctl disable --now containerd || true
318 rm -rf /var/lib/containerd /run/containerd
319 function cleanup()
320 {
321 journalctl -u containerd > /tmp/containerd.log
322 cat /tmp/containerd.log
323 systemctl stop containerd
324 }
325 selinux=$(getenforce)
326 if [[ $selinux == Enforcing ]]; then
327 setenforce 0
328 fi
329 systemctl enable --now ${GOPATH}/src/github.com/containerd/containerd/containerd.service
330 if [[ $selinux == Enforcing ]]; then
331 setenforce 1
332 fi
333 trap cleanup EXIT
334 ctr version
335 critest --parallel=$[$(nproc)+2] --ginkgo.skip='HostIpc is true' --report-dir="${REPORT_DIR}"
336 SHELL
337 end
338
339 end