Vagrantfile 13 KB

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