-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathVagrantfile
223 lines (202 loc) · 8.45 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Run tests:
# echo 'make -C /vagrant clean test' | vagrant ssh
# Run tests in Docker containers:
# echo '/vagrant/machines/docker_test_all.sh' | vagrant ssh
# Run tests and record "make list-nobuild" output:
# script -c "echo '/vagrant/machines/docker_test_all.sh' | vagrant ssh" dockers.log
# ./machines/update_list_nobuild_from_log.py dockers.log
# In order to carry all possible Docker environments, at least 240 GB of storage
# is needed in the virtual machine. To expand a disk of a VM created using
# packer-arch and using libvirt, perform the following steps:
# * On the host, expand the QCow2 disk file:
#
# cd /var/lib/libvirt/images
# qemu-img resize shared_default.img +200G
# qemu-img info shared_default.img |grep 'virtual size:'
#
# * Power on the VM.
# * On the guest, expand the partition table:
#
# fdisk /dev/vda
# # Delete the first (and only) partition.
# # Create a new partition, starting at offset 2048, without removing the
# # ext4 partition signature.
#
# * On the guest, make the partition bootable again (-i installs Syslinux, -a
# sets the boot flag, -m installs Syslinux MBR):
#
# pacman -S gptfdisk
# sgdisk /dev/vda --attributes=1:set:2
# syslinux-install_update -i -a -m
#
# * Reboot the VM.
# * Resize the ext4 filesystem on the guest to fill the new space:
#
# resize2fs /dev/vda1
# Provisioning script: update the system, install docker and create an Arch Linux Docker image
$script = <<SCRIPT
timedatectl set-timezone UTC
sed -i -e 's/^#\\?MAKEFLAGS=.*/MAKEFLAGS="-j\\$(nproc)"/' /etc/makepkg.conf
# Update archlinux-keyring before the other packages in order to make sure the
# recently-added packagers are known.
pacman --noconfirm -Sy
if [ "$(pacman -Qi archlinux-keyring | grep '^Version')" != "$(pacman -Si archlinux-keyring | grep '^Version')" ]
then
pacman --noconfirm -S archlinux-keyring
fi
pacman --noconfirm -Su
# Make sure Python, Docker and other needed packages are installed
for PKG in docker docker-buildx gcc make pkgconf python
do
pacman -Qqi "$PKG" > /dev/null || pacman --noconfirm -S "$PKG"
done
# Install Docker and build Arch Linux Docker image
# Configure docker such that the ulimits is not crazy
# By default, prlimit shows:
# NOFILE max number of open files 1073741816 1073741816 files
# NPROC max number of processes unlimited unlimited processes
# RSS max resident set size unlimited unlimited bytes
# RTPRIO max real-time priority 0 0
# Instead of the system-wide sane 1024:524288, 15615:15615
cat > /etc/docker/daemon.json << EOF
{
"default-ulimits": {
"nofile": {
"Name": "nofile",
"Soft": 1024,
"Hard": 2048
},
"nproc": {
"Name": "nproc",
"Soft": 15615,
"Hard": 15615
}
}
}
EOF
systemctl enable --now docker
gpasswd -a vagrant docker
(docker images |grep -q '^archlinux ') || su vagrant -c 'docker docker-buildx build -t archlinux /vagrant/machines/archlinux'
# Use vsyscall=emulate on the command line, for Debian 7 Wheezy
if [ -e /boot/syslinux/syslinux.cfg ] && ! grep vsyscall=emulate /boot/syslinux/syslinux.cfg > /dev/null
then
sed -i -e 's/^\\(\\s*APPEND\\s.*\\)/\\1 vsyscall=emulate/' /boot/syslinux/syslinux.cfg
syslinux-install_update -i -a -m
fi
# Make sure that the number of kernel file handles stays reasonable by defining
# a limit in /proc/sys/fs/file-max
echo 'fs.file-max = 10000' > /etc/sysctl.d/99-sane-open-files-limit.conf
SCRIPT
# Install an ARM chroot with Debian sid
$arm_chroot_script = <<SCRIPT
# Install Qemu static, in order to run foreign architectures on Arch Linux
if ! pacman -Qqi qemu-user-static > /dev/null
then
pacman -Qqi git > /dev/null || pacman --noconfirm -S git
pacman -Qqi patch > /dev/null || pacman --noconfirm -S patch
pacman -Qqi fakeroot > /dev/null || pacman --noconfirm -S fakeroot
# Install its dependencies
if ! pacman -Qqi glib2-static > /dev/null
then
sudo -u vagrant git clone https://aur.archlinux.org/glib2-static.git AUR_glib2-static
(cd AUR_glib2-static && sudo -u vagrant makepkg -si --noconfirm --nocheck) && rm -rf AUR_glib2-static
fi
if ! pacman -Qqi pcre-static > /dev/null
then
sudo -u vagrant git clone https://aur.archlinux.org/pcre-static.git AUR_pcre-static
(cd AUR_pcre-static && sudo -u vagrant makepkg -si --noconfirm --skippgpcheck) && rm -rf AUR_pcre-static
fi
sudo -u vagrant git clone https://aur.archlinux.org/qemu-user-static.git AUR_qemu-user-static
(cd AUR_qemu-user-static && sudo -u vagrant makepkg -si --noconfirm --skippgpcheck) && rm -rf AUR_qemu-user-static
fi
# Install a binfmt handler for ARM
# cf. https://aur.archlinux.org/cgit/aur.git/tree/qemu-static.conf?h=binfmt-qemu-static
if ! [ -f /etc/binfmt.d/qemu-arm.conf ]
then
echo ':qemu-arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:/usr/bin/qemu-arm-static:' > /etc/binfmt.d/qemu-arm.conf
systemctl restart systemd-binfmt.service
fi
# Install debootstrap and Debian keyring
pacman -Qqi debootstrap > /dev/null || pacman --noconfirm -S debootstrap
pacman -Qqi debian-archive-keyring > /dev/null || pacman --noconfirm -S debian-archive-keyring
# Install arch-install-scripts for "arch-chroot"
pacman -Qqi arch-install-scripts > /dev/null || pacman --noconfirm -S arch-install-scripts
if ! [ -d arm-debian ]
then
# Bootstrap the ARM-Debian chroot, copying qemu-arm-static inside too
mkdir -p arm-debian/usr/bin
cp -v /usr/bin/qemu-arm-static arm-debian/usr/bin/
debootstrap --arch=armel --force-check-gpg sid arm-debian
# Add a helper to enter the chroot
[ -d bin ] || sudo -u vagrant mkdir bin
sudo -u vagrant tee bin/enter-arm-debian > /dev/null << EOF
#!/bin/bash
if [ "\\\$(id -u)" != 0 ]
then
# Change to vagrant user inside the chroot
if [ "\\\$#" -eq 0 ]
then
set su vagrant
else
set su vagrant -c "\\\$*"
fi
elif [ "\\\$#" -eq 0 ]
then
# Run bash by default, as root
set bash
fi
exec sudo arch-chroot /home/vagrant/arm-debian /usr/bin/env PATH=/usr/sbin:/usr/bin:/sbin:/bin "\\\$@"
EOF
chmod +x bin/enter-arm-debian
# Install the same packages as the last Debian machine, but without the x86-specific packages
sed -n '/^RUN \\\\/,/[^\\\\]\$/{p}' /vagrant/machines/Dockerfile-debian13-trixie | \\
tail -n +2 | \\
sed 's/dpkg --add-architecture i386/true/' | \\
sed 's/ coq / /g' | \\
sed 's/ gcc-mingw-w64 / /g' | \\
sed 's/ gcc-multilib / gcc /g' | \\
sed 's/ libc6-dev-i386 / /g' | \\
sed 's/ libomp-dev / /g' | \\
sed 's/ linux-headers-amd64 / /g' | \\
sed 's/ wine / /g' | \\
sed 's/ wine32 / /g' | \\
sed 's/ wine64 / /g' | \\
arch-chroot arm-debian /usr/bin/env PATH=/usr/sbin:/usr/bin:/sbin:/bin DEBIAN_FRONTEND=noninteractive sh -x
# Add vagrant user
arch-chroot arm-debian /usr/bin/env PATH=/usr/sbin:/usr/bin:/sbin:/bin useradd -m --uid 1000 --user-group --shell /bin/bash vagrant
fi
# Bind-mount /vagrant
if ! grep -q '^/vagrant /home/vagrant/arm-debian/vagrant ' /etc/fstab
then
echo '/vagrant /home/vagrant/arm-debian/vagrant none bind 0 0' >> /etc/fstab
mkdir -p arm-debian/vagrant
mount arm-debian/vagrant
fi
# Upgrade Debian
arch-chroot arm-debian apt-get update
arch-chroot arm-debian /usr/bin/env PATH=/usr/sbin:/usr/bin:/sbin:/bin apt-get -y dist-upgrade
SCRIPT
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# Use Arch Linux Vagrant Base box
# https://wiki.archlinux.org/index.php/Vagrant#Base_Boxes_for_Vagrant
# For example with https://github.com/elasticdog/packer-arch and libvirt:
# cd packer-arch
# ./wrapacker -p libvirt
# vagrant box add archlinux output/packer_arch_libvirt.box
config.vm.box = "archlinux"
config.vm.provider :libvirt do |v|
v.cpus = 4
v.memory = 4096
end
# Run the provisioning scripts
config.vm.provision :shell, inline: $script
config.vm.provision :shell, inline: $arm_chroot_script
# Ensure the build system works fine, and show what would run
config.vm.provision :shell, inline: "make -C /vagrant list-nobuild"
end