Skip to content

Commit 9d9f04f

Browse files
author
Christian Rebischke
authored
Merge pull request #66 from shibumi/shibumi/official-cloud-images
add support for cloud images
2 parents ec46f71 + 4c03420 commit 9d9f04f

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

cloud.json

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"variables": {
3+
"iso_url": "https://mirror.pkgbuild.com/iso/latest/archlinux-2019.10.01-x86_64.iso",
4+
"iso_checksum_url": "https://mirror.pkgbuild.com/iso/latest/sha1sums.txt",
5+
"iso_checksum_type": "sha1",
6+
"disk_size": "20480",
7+
"memory": "1024",
8+
"cpus": "2",
9+
"headless": "true",
10+
"write_zeroes": "",
11+
"boot_wait": "60s"
12+
},
13+
"builders": [
14+
{
15+
"name": "Arch-Linux-cloudimg-amd64-{{isotime \"2006-01-02\"}}.img",
16+
"type": "qemu",
17+
"output_directory": "release",
18+
"boot_wait": "{{user `boot_wait`}}",
19+
"http_directory": "http",
20+
"disk_size": "{{user `disk_size`}}",
21+
"iso_checksum_url": "{{user `iso_checksum_url`}}",
22+
"iso_checksum_type": "{{user `iso_checksum_type`}}",
23+
"iso_url": "{{user `iso_url`}}",
24+
"ssh_username": "arch",
25+
"ssh_password": "arch",
26+
"ssh_port": 22,
27+
"ssh_wait_timeout": "10000s",
28+
"shutdown_command": "sudo systemctl poweroff",
29+
"headless": "{{user `headless`}}",
30+
"qemuargs": [
31+
[
32+
"-m",
33+
"{{user `memory`}}"
34+
],
35+
[
36+
"-smp",
37+
"{{user `cpus`}}"
38+
]
39+
],
40+
"boot_command": [
41+
"<enter><wait10><wait10><wait10><wait10><wait10><enter><enter>",
42+
"curl -O 'http://{{.HTTPIP}}:{{.HTTPPort}}/install{,-cloud}.sh'<enter><wait>",
43+
"bash install.sh < install-cloud.sh && systemctl reboot<enter>"
44+
]
45+
}
46+
],
47+
"provisioners": [
48+
{
49+
"type": "shell",
50+
"scripts": [
51+
"provision/postinstall.sh",
52+
"provision/qemu.sh",
53+
"provision/cloud-init.sh",
54+
"provision/cleanup.sh"
55+
],
56+
"execute_command": "echo 'arch'|sudo -S sh '{{.Path}}'"
57+
},
58+
{
59+
"type": "shell",
60+
"scripts": [
61+
"provision/write_zeroes.sh"
62+
],
63+
"execute_command": "if [ ! -z \"{{user `write_zeroes`}}\" ]; then echo 'arch'|sudo -S sh '{{.Path}}'; fi"
64+
}
65+
],
66+
"post-processors": [
67+
[
68+
{
69+
"type": "checksum",
70+
"checksum_types": [
71+
"sha256"
72+
],
73+
"output": "Arch-Linux-cloudimg-amd64-{{isotime \"2006-01-02\"}}.SHA256"
74+
},
75+
{
76+
"type": "shell-local",
77+
"inline": [
78+
"mv release/packer-Arch-Linux-cloudimg-amd64-{{isotime \"2006-01-02\"}}.img release/Arch-Linux-cloudimg-amd64-{{isotime \"2006-01-02\"}}.img",
79+
"sed -i 's/packer-//' Arch-Linux-cloudimg-amd64-{{isotime \"2006-01-02\"}}.SHA256",
80+
"gpg --sign --detach-sign Arch-Linux-cloudimg-amd64-{{isotime \"2006-01-02\"}}.SHA256"
81+
]
82+
}
83+
]
84+
]
85+
}

http/install-cloud.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
7+
sed -i -e 's/^#\(en_US.UTF-8\)/\1/' /etc/locale.gen
8+
locale-gen
9+
echo 'LANG=en_US.UTF-8' >/etc/locale.conf
10+
11+
# setting arch user credentials
12+
echo -e 'arch\narch' | passwd
13+
useradd -m -U arch
14+
echo -e 'arch\narch' | passwd arch
15+
16+
# setting automatic authentication for any action requiring admin rights via Polkit
17+
cat <<EOF >/etc/polkit-1/rules.d/49-nopasswd_global.rules
18+
polkit.addRule(function(action, subject) {
19+
if (subject.isInGroup("arch")) {
20+
return polkit.Result.YES;
21+
}
22+
});
23+
EOF
24+
25+
# setting sudo for arch user
26+
cat <<EOF >/etc/sudoers.d/arch
27+
Defaults:arch !requiretty
28+
arch ALL=(ALL) NOPASSWD: ALL
29+
EOF
30+
chmod 440 /etc/sudoers.d/arch
31+
32+
# setup unpredictable kernel names
33+
ln -s /dev/null /etc/systemd/network/99-default.link
34+
35+
# setup network
36+
cat <<EOF >/etc/systemd/network/eth0.network
37+
[Match]
38+
Name=eth0
39+
40+
[Network]
41+
DHCP=ipv4
42+
EOF
43+
44+
# Setup pacman-init.service for clean pacman keyring initialization
45+
cat <<EOF >/etc/systemd/system/pacman-init.service
46+
[Unit]
47+
Description=Initializes Pacman keyring
48+
Wants=haveged.service
49+
After=haveged.service
50+
Before=sshd.service
51+
ConditionFirstBoot=yes
52+
53+
[Service]
54+
Type=oneshot
55+
RemainAfterExit=yes
56+
ExecStart=/usr/bin/pacman-key --init
57+
ExecStart=/usr/bin/pacman-key --populate archlinux
58+
59+
[Install]
60+
WantedBy=multi-user.target
61+
EOF
62+
63+
# enabling important services
64+
systemctl daemon-reload
65+
systemctl enable sshd
66+
systemctl enable haveged
67+
systemctl enable systemd-networkd
68+
systemctl enable systemd-resolved
69+
systemctl enable pacman-init.service
70+
71+
if [ -b "/dev/sda" ]; then
72+
grub-install /dev/sda
73+
elif [ -b "/dev/vda" ]; then
74+
grub-install /dev/vda
75+
fi
76+
sed -i -e 's/^GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=1/' /etc/default/grub
77+
grub-mkconfig -o /boot/grub/grub.cfg

provision/cloud-init.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
sudo pacman -S --noconfirm cloud-init
7+
sudo systemctl enable cloud-init-local.service
8+
sudo systemctl enable cloud-init.service
9+
sudo systemctl enable cloud-config.service
10+
sudo systemctl enable cloud-final.service

0 commit comments

Comments
 (0)