|
| 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 | +Vagrant.configure("2") do |config| |
| 19 | + config.vm.box = ENV["BOX"] ? ENV["BOX"].split("@")[0] : "almalinux/8" |
| 20 | + # BOX_VERSION is deprecated. Use "BOX=<BOX>@<BOX_VERSION>". |
| 21 | + config.vm.box_version = ENV["BOX_VERSION"] || (ENV["BOX"].split("@")[1] if ENV["BOX"]) |
| 22 | + |
| 23 | + memory = 4096 |
| 24 | + cpus = 2 |
| 25 | + disk_size = 60 |
| 26 | + config.vm.provider :virtualbox do |v, o| |
| 27 | + v.memory = memory |
| 28 | + v.cpus = cpus |
| 29 | + # Needs env var VAGRANT_EXPERIMENTAL="disks" |
| 30 | + o.vm.disk :disk, size: "#{disk_size}GB", primary: true |
| 31 | + v.customize ["modifyvm", :id, "--firmware", "efi"] |
| 32 | + end |
| 33 | + config.vm.provider :libvirt do |v| |
| 34 | + v.memory = memory |
| 35 | + v.cpus = cpus |
| 36 | + v.machine_virtual_size = disk_size |
| 37 | + # https://github.com/vagrant-libvirt/vagrant-libvirt/issues/1725#issuecomment-1454058646 |
| 38 | + # Needs `sudo cp /usr/share/OVMF/OVMF_VARS_4M.fd /var/lib/libvirt/qemu/nvram/` |
| 39 | + v.loader = '/usr/share/OVMF/OVMF_CODE_4M.fd' |
| 40 | + v.nvram = '/var/lib/libvirt/qemu/nvram/OVMF_VARS_4M.fd' |
| 41 | + end |
| 42 | + |
| 43 | + config.vm.synced_folder ".", "/vagrant", type: "rsync" |
| 44 | + |
| 45 | + config.vm.provision 'shell', path: 'script/resize-vagrant-root.sh' |
| 46 | + |
| 47 | + # To re-run, installing CNI from RPM: |
| 48 | + # INSTALL_PACKAGES="containernetworking-plugins" vagrant up --provision-with=install-packages |
| 49 | + # |
| 50 | + config.vm.provision "install-packages", type: "shell", run: "once" do |sh| |
| 51 | + sh.upload_path = "/tmp/vagrant-install-packages" |
| 52 | + sh.env = { |
| 53 | + 'INSTALL_PACKAGES': ENV['INSTALL_PACKAGES'], |
| 54 | + } |
| 55 | + sh.inline = <<~SHELL |
| 56 | + #!/usr/bin/env bash |
| 57 | + set -eux -o pipefail |
| 58 | + dnf -y install \ |
| 59 | + curl \ |
| 60 | + gcc \ |
| 61 | + git \ |
| 62 | + make \ |
| 63 | + ${INSTALL_PACKAGES} |
| 64 | + SHELL |
| 65 | + end |
| 66 | + |
| 67 | + # AlmaLinux does not have /usr/local/{bin,sbin} in the PATH by default |
| 68 | + config.vm.provision "setup-etc-environment", type: "shell", run: "once" do |sh| |
| 69 | + sh.upload_path = "/tmp/vagrant-setup-etc-environment" |
| 70 | + sh.inline = <<~SHELL |
| 71 | + #!/usr/bin/env bash |
| 72 | + set -eux -o pipefail |
| 73 | + cat >> /etc/environment <<EOF |
| 74 | +PATH=/usr/local/go/bin:/usr/local/bin:/usr/local/sbin:$PATH |
| 75 | +EOF |
| 76 | + source /etc/environment |
| 77 | + SHELL |
| 78 | + end |
| 79 | + |
| 80 | + # To re-run this provisioner, installing a different version of go: |
| 81 | + # GO_VERSION="1.14.6" vagrant up --provision-with=install-golang |
| 82 | + # |
| 83 | + config.vm.provision "install-golang", type: "shell", run: "once" do |sh| |
| 84 | + sh.upload_path = "/tmp/vagrant-install-golang" |
| 85 | + sh.env = { |
| 86 | + 'GO_VERSION': ENV['GO_VERSION'] || "1.24.3", |
| 87 | + } |
| 88 | + sh.inline = <<~SHELL |
| 89 | + #!/usr/bin/env bash |
| 90 | + set -eux -o pipefail |
| 91 | + curl -fsSL "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" | tar Cxz /usr/local |
| 92 | + cat >> /etc/profile.d/sh.local <<EOF |
| 93 | +GOPATH=\\$HOME/go |
| 94 | +PATH=\\$GOPATH/bin:\\$PATH |
| 95 | +export GOPATH PATH |
| 96 | +git config --global --add safe.directory /vagrant |
| 97 | +EOF |
| 98 | + source /etc/profile.d/sh.local |
| 99 | + SHELL |
| 100 | + end |
| 101 | + |
| 102 | + config.vm.provision "setup-gopath", type: "shell", run: "once" do |sh| |
| 103 | + sh.upload_path = "/tmp/vagrant-setup-gopath" |
| 104 | + sh.inline = <<~SHELL |
| 105 | + #!/usr/bin/env bash |
| 106 | + source /etc/environment |
| 107 | + source /etc/profile.d/sh.local |
| 108 | + set -eux -o pipefail |
| 109 | + mkdir -p ${GOPATH}/src/github.com/containerd |
| 110 | + ln -fnsv /vagrant ${GOPATH}/src/github.com/containerd/cgroups |
| 111 | + SHELL |
| 112 | + end |
| 113 | + |
| 114 | + config.vm.provision "test", type: "shell", run: "never" do |sh| |
| 115 | + sh.upload_path = "/tmp/test" |
| 116 | + sh.env = { |
| 117 | + 'GOTEST': ENV['GOTEST'] || "go test", |
| 118 | + 'GOTESTSUM_JUNITFILE': ENV['GOTESTSUM_JUNITFILE'], |
| 119 | + 'GOTESTSUM_JSONFILE': ENV['GOTESTSUM_JSONFILE'], |
| 120 | + } |
| 121 | + sh.inline = <<~SHELL |
| 122 | + #!/usr/bin/env bash |
| 123 | + source /etc/environment |
| 124 | + source /etc/profile.d/sh.local |
| 125 | + set -eux -o pipefail |
| 126 | + cd ${GOPATH}/src/github.com/containerd/cgroups |
| 127 | + go env -w CGO_ENABLED=1 |
| 128 | + go test -exec "sudo" -v -race -coverprofile=coverage.txt -covermode=atomic ./... |
| 129 | + SHELL |
| 130 | + end |
| 131 | + |
| 132 | + config.vm.provision "build-cgctl", type: "shell", run: "never" do |sh| |
| 133 | + sh.upload_path = "/tmp/build-cgctl" |
| 134 | + sh.inline = <<~SHELL |
| 135 | + #!/usr/bin/env bash |
| 136 | + source /etc/environment |
| 137 | + source /etc/profile.d/sh.local |
| 138 | + set -eux -o pipefail |
| 139 | + cd ${GOPATH}/src/github.com/containerd/cgroups |
| 140 | + make all |
| 141 | + SHELL |
| 142 | + end |
| 143 | +end |
0 commit comments