Commit 6a594122 authored by Alain Takoudjou's avatar Alain Takoudjou

packer: generate vm-bootstrap images with set of sizes in a new playbook

parent 13759d82
Pipeline #4639 skipped
...@@ -22,3 +22,5 @@ archive.tar.gz* ...@@ -22,3 +22,5 @@ archive.tar.gz*
packer/shacache/*.crt packer/shacache/*.crt
packer/shacache/*.key packer/shacache/*.key
packer/SHA512SUM.txt packer/SHA512SUM.txt
packer/URL.txt
packer/MD5SUM.txt
...@@ -3,11 +3,49 @@ vm-bootstrap Image ...@@ -3,11 +3,49 @@ vm-bootstrap Image
packer vm-boostrap image contain a vm-bootstrap script (see: scripts/vm-bootstrap.sh) which will run in specific bootstrap script when VM boot for the first time. packer vm-boostrap image contain a vm-bootstrap script (see: scripts/vm-bootstrap.sh) which will run in specific bootstrap script when VM boot for the first time.
How to build VM with differents images size?
--------------------------------------------
How it works 1) Install Packer locally by https://www.packer.io/downloads.html, like (exemple):
------------
Boostrap script is downloaded from a static URL http://10.0.2.100/vm-bootstrap. The script will be executed until it succeed (exit with 0) or until the maximum execution count is reached. By default, the maximum exucution number is 10. To change this value you can write the new value in /root/bootstrap/bootstrap-max-retry.
mkdir /opt/packer/
cd /opt/packer/
wget https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_linux_amd64.zip
unzip packer_0.10.1_linux_amd64.zip
2) Check and install qemu
Packer use qemu to build vm images, you need to install it first.
apt-get install qemu
3) Use ansible to build all VMs and compress them in local folder
ansible-playbook build-vm-bootstrap.yml -i hosts
After build, images are generated in folder output-DISTRO-XXG-vm-boostrapn, they are gziped to reduce the size when downloading images.
The file SHA512SUM.txt contain the SHA512SUM of each vm image.
The file MD5SUM.txt contain the MD5SUM of each vm image.
How to upload images to shacache
--------------------------------
To build and upload images to shacache, use this ansible command
UPLOAD=yes ansible-playbook build-vm-bootstrap.yml -i hosts
A file URL.txt will be generated with url as well as MD5SUM to download each image from shacache.
How to use Images
-----------------
Boostrap script is downloaded into the VM from a static URL http://10.0.2.100/vm-bootstrap. The script will be executed until it succeed (exit with 0) or until the maximum execution count is reached. By default, the maximum exucution number is 10. To change this value you can write the new value in /root/bootstrap/bootstrap-max-retry.
#!/bin/bash #!/bin/bash
echo 1 > /root/bootstrap/bootstrap-max-retry echo 1 > /root/bootstrap/bootstrap-max-retry
...@@ -35,3 +73,4 @@ Bootstrap script called 'vm-bootstrap' should be placed in and external http ser ...@@ -35,3 +73,4 @@ Bootstrap script called 'vm-bootstrap' should be placed in and external http ser
qemu -net 'user,guestfwd=tcp:10.0.2.100:80-cmd:netcat server_ip server_port' qemu -net 'user,guestfwd=tcp:10.0.2.100:80-cmd:netcat server_ip server_port'
for more information, see qemu 'user network' documentation. for more information, see qemu 'user network' documentation.
This diff is collapsed.
...@@ -2,23 +2,25 @@ ...@@ -2,23 +2,25 @@
"variables": { "variables": {
"user": "slapos", "user": "slapos",
"password": "slapos", "password": "slapos",
"disk_size": "100000", "domain": "",
"domain": "" "disk_size": "200",
"name": "image",
"custom_script": ""
}, },
"builders": "builders":
[ [
{ {
"name": "centos67", "name": "centos-6-{{ user `disk_size`}}G-{{ user `name`}}",
"type": "qemu", "type": "qemu",
"format": "qcow2", "format": "qcow2",
"accelerator": "kvm", "accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}", "disk_size": "{{ user `disk_size`}}000",
"iso_url": "http://mirrors.kernel.org/centos/6.7/isos/x86_64/CentOS-6.7-x86_64-minimal.iso", "iso_url": "http://mirrors.kernel.org/centos/6.8/isos/x86_64/CentOS-6.8-x86_64-minimal.iso",
"iso_checksum": "9d3fec5897be6b3fed4d3dda80b8fa7bb62c616bbfd4bdcd27295ca9b764f498", "iso_checksum": "0ca12fe5f28c2ceed4f4084b41ff8a0b",
"iso_checksum_type": "sha256", "iso_checksum_type": "md5",
"http_directory": "http", "http_directory": "http",
...@@ -46,8 +48,11 @@ ...@@ -46,8 +48,11 @@
"scripts": [ "scripts": [
"scripts/update-centos.sh", "scripts/update-centos.sh",
"scripts/packages-centos.sh", "scripts/packages-centos.sh",
"scripts/cleanup-centos.sh" "scripts/cleanup-centos.sh",
"scripts/centos6-install-base.sh",
"{{ user `custom_script` }}"
] ]
} }
] ]
} }
...@@ -2,20 +2,21 @@ ...@@ -2,20 +2,21 @@
"variables": { "variables": {
"user": "slapos", "user": "slapos",
"password": "slapos", "password": "slapos",
"disk_size": "100000", "domain": "",
"domain": "" "disk_size": "200",
"name": "image",
"custom_script": ""
}, },
"builders": "builders":
[ [
{ {
"name": "centos72", "name": "centos7.2-{{ user `disk_size`}}G-{{ user `name`}}",
"type": "qemu", "type": "qemu",
"format": "qcow2", "format": "qcow2",
"accelerator": "kvm", "accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}", "disk_size": "{{ user `disk_size`}}000",
"iso_url": "http://mirrors.kernel.org/centos/7.2.1511/isos/x86_64/CentOS-7-x86_64-NetInstall-1511.iso", "iso_url": "http://mirrors.kernel.org/centos/7.2.1511/isos/x86_64/CentOS-7-x86_64-NetInstall-1511.iso",
"iso_checksum": "9ed9ffb5d89ab8cca834afce354daa70a21dcb410f58287d6316259ff89758f5", "iso_checksum": "9ed9ffb5d89ab8cca834afce354daa70a21dcb410f58287d6316259ff89758f5",
...@@ -46,8 +47,11 @@ ...@@ -46,8 +47,11 @@
"scripts": [ "scripts": [
"scripts/update-centos.sh", "scripts/update-centos.sh",
"scripts/packages-centos.sh", "scripts/packages-centos.sh",
"scripts/cleanup-centos.sh" "scripts/cleanup-centos.sh",
"scripts/centos7-install-base.sh",
"{{ user `custom_script` }}"
] ]
} }
] ]
} }
...@@ -2,22 +2,24 @@ ...@@ -2,22 +2,24 @@
"variables": { "variables": {
"user": "slapos", "user": "slapos",
"password": "slapos", "password": "slapos",
"disk_size": "100000", "domain": "",
"domain": "" "disk_size": "200",
"name": "image",
"custom_script": ""
}, },
"builders": "builders":
[ [
{ {
"name": "debian7", "name": "debian7-{{ user `disk_size`}}G-{{ user `name`}}",
"type": "qemu", "type": "qemu",
"format": "qcow2", "format": "qcow2",
"accelerator": "kvm", "accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}", "disk_size": "{{ user `disk_size`}}000",
"iso_url": "http://cdimage.debian.org/mirror/cdimage/archive/7.9.0/amd64/iso-cd/debian-7.9.0-amd64-netinst.iso", "iso_url": "http://cdimage.debian.org/mirror/cdimage/archive/7.11.0/amd64/iso-cd/debian-7.11.0-amd64-netinst.iso",
"iso_checksum": "774d1fc8c5364e63b22242c33a89c1a3", "iso_checksum": "096c1c18b44c269808bd815d58c53c8f",
"iso_checksum_type": "md5", "iso_checksum_type": "md5",
"http_directory": "http", "http_directory": "http",
...@@ -33,7 +35,7 @@ ...@@ -33,7 +35,7 @@
"<esc><wait><wait>", "<esc><wait><wait>",
"install auto ", "install auto ",
"preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-debian7.cfg ", "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-debian7.cfg ",
"debian-installer=en_US locale=en_US keymap=us ", "debian-installer=en_US locale=en_US keymap=fr ",
"netcfg/get_hostname={{ .Name }} ", "netcfg/get_hostname={{ .Name }} ",
"netcfg/get_domain={{ user `domain`}} ", "netcfg/get_domain={{ user `domain`}} ",
...@@ -56,8 +58,10 @@ ...@@ -56,8 +58,10 @@
"scripts": [ "scripts": [
"scripts/update.sh", "scripts/update.sh",
"scripts/packages.sh", "scripts/packages.sh",
"scripts/cleanup.sh" "scripts/cleanup.sh",
"{{ user `custom_script` }}"
] ]
} }
] ]
} }
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
"accelerator": "kvm", "accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}", "disk_size": "{{ user `disk_size`}}",
"iso_url": "http://cdimage.debian.org/debian-cd/8.5.0/amd64/iso-cd/debian-8.5.0-amd64-netinst.iso", "iso_url": "http://cdimage.debian.org/debian-cd/8.6.0/amd64/iso-cd/debian-8.6.0-amd64-netinst.iso",
"iso_checksum": "3e1b9029a0cf188730646c379d15073f", "iso_checksum": "e9f61bf327db6d8f7cee05a99f2353cc",
"iso_checksum_type": "md5", "iso_checksum_type": "md5",
"http_directory": "http", "http_directory": "http",
......
...@@ -2,22 +2,24 @@ ...@@ -2,22 +2,24 @@
"variables": { "variables": {
"user": "slapos", "user": "slapos",
"password": "slapos", "password": "slapos",
"disk_size": "100000", "domain": "",
"domain": "" "disk_size": "200",
"name": "image",
"custom_script": ""
}, },
"builders": "builders":
[ [
{ {
"name": "debian8", "name": "debian8-{{ user `disk_size`}}G-{{ user `name`}}",
"type": "qemu", "type": "qemu",
"format": "qcow2", "format": "qcow2",
"accelerator": "kvm", "accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}", "disk_size": "{{ user `disk_size`}}000",
"iso_url": "http://cdimage.debian.org/debian-cd/8.3.0/amd64/iso-cd/debian-8.3.0-amd64-netinst.iso", "iso_url": "http://cdimage.debian.org/debian-cd/8.6.0/amd64/iso-cd/debian-8.6.0-amd64-netinst.iso",
"iso_checksum": "a9b490b4215d1e72e876b031dafa7184", "iso_checksum": "e9f61bf327db6d8f7cee05a99f2353cc",
"iso_checksum_type": "md5", "iso_checksum_type": "md5",
"http_directory": "http", "http_directory": "http",
...@@ -33,7 +35,7 @@ ...@@ -33,7 +35,7 @@
"<esc><wait><wait>", "<esc><wait><wait>",
"install auto ", "install auto ",
"preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-debian8.cfg ", "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-debian8.cfg ",
"debian-installer=en_US locale=en_US keymap=us ", "debian-installer=en_US locale=en_US keymap=fr ",
"netcfg/get_hostname={{ .Name }} ", "netcfg/get_hostname={{ .Name }} ",
"netcfg/get_domain={{ user `domain`}} ", "netcfg/get_domain={{ user `domain`}} ",
...@@ -56,8 +58,10 @@ ...@@ -56,8 +58,10 @@
"scripts": [ "scripts": [
"scripts/update.sh", "scripts/update.sh",
"scripts/packages.sh", "scripts/packages.sh",
"scripts/cleanup.sh" "scripts/cleanup.sh",
"{{ user `custom_script` }}"
] ]
} }
] ]
} }
[targets]
localhost ansible_connection=local
127.0.0.1 ansible_connection=local
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select fr d-i keyboard-configuration/xkb-keymap select fr
choose-mirror-bin mirror/http/proxy string choose-mirror-bin mirror/http/proxy string
d-i debian-installer/framebuffer boolean false d-i debian-installer/framebuffer boolean false
......
# Update the box # Update the box
apt-get -y update apt-get -y update
apt-get -y upgrade apt-get -y upgrade
# Make sure keyboard language is french
sed -i 's#XKBLAYOUT=.*#XKBLAYOUT="fr"#' /etc/default/keyboard
...@@ -7,6 +7,8 @@ touch /root/bootstrap/start-bootstrap ...@@ -7,6 +7,8 @@ touch /root/bootstrap/start-bootstrap
# Put cron task to bootstrap vm # Put cron task to bootstrap vm
cat << EOF > /etc/cron.d/vm-boostrap cat << EOF > /etc/cron.d/vm-boostrap
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Bootstrap vm every minutes until it succeed # Bootstrap vm every minutes until it succeed
* * * * * root bash -lc /root/bootstrap/vm-bootstrap >> /var/log/vm-bootstrap.log 2>&1 * * * * * root bash -lc /root/bootstrap/vm-bootstrap >> /var/log/vm-bootstrap.log 2>&1
EOF EOF
......
...@@ -2,19 +2,23 @@ ...@@ -2,19 +2,23 @@
"variables": { "variables": {
"user": "slapos", "user": "slapos",
"password": "slapos", "password": "slapos",
"disk_size": "100000" "domain": "",
"disk_size": "200",
"name": "image",
"custom_script": ""
}, },
"builders": "builders":
[ [
{ {
"name": "ubuntu-14-04-server", "name": "ubuntu-14-server-amd64-{{ user `disk_size`}}G-{{ user `name`}}",
"type": "qemu", "type": "qemu",
"format": "qcow2", "format": "qcow2",
"accelerator": "kvm", "accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}", "disk_size": "{{ user `disk_size`}}000",
"headless": true, "headless": true,
"iso_url": "http://releases.ubuntu.com/14.04/ubuntu-14.04.4-server-amd64.iso", "iso_url": "http://releases.ubuntu.com/14.04/ubuntu-14.04.4-server-amd64.iso",
"iso_checksum": "2ac1f3e0de626e54d05065d6f549fa3a", "iso_checksum": "2ac1f3e0de626e54d05065d6f549fa3a",
"iso_checksum_type": "md5", "iso_checksum_type": "md5",
...@@ -30,12 +34,11 @@ ...@@ -30,12 +34,11 @@
"boot_command": [ "boot_command": [
"<esc><esc><enter><wait>", "<esc><esc><enter><wait>",
"/install/vmlinuz url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-ubuntu.cfg ", "/install/vmlinuz url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-ubuntu.cfg ",
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", "debian-installer=en_US auto locale=en_US kbd-chooser/method=fr ",
"hostname={{ .Name }} ", "hostname={{ .Name }} ",
"keyboard-configuration/modelcode=SKIP ", "keyboard-configuration/modelcode=pc101 ",
"keyboard-configuration/layout=USA ", "keyboard-configuration/layoutcode=fr ",
"keyboard-configuration/variant=USA ",
"passwd/user-fullname={{user `user`}} ", "passwd/user-fullname={{user `user`}} ",
"passwd/user-password-again={{user `password`}} ", "passwd/user-password-again={{user `password`}} ",
...@@ -54,8 +57,10 @@ ...@@ -54,8 +57,10 @@
"scripts": [ "scripts": [
"scripts/update-ubuntu.sh", "scripts/update-ubuntu.sh",
"scripts/packages-ubuntu.sh", "scripts/packages-ubuntu.sh",
"scripts/network-ubuntu.sh" "scripts/network-ubuntu.sh",
"{{ user `custom_script` }}"
] ]
} }
] ]
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"variables": { "variables": {
"user": "slapos", "user": "slapos",
"password": "slapos", "password": "slapos",
"disk_size": "100000" "disk_size": "100"
}, },
"builders": "builders":
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"type": "qemu", "type": "qemu",
"format": "qcow2", "format": "qcow2",
"accelerator": "kvm", "accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}", "disk_size": "{{ user `disk_size`}}000",
"headless": true, "headless": true,
"iso_url": "http://releases.ubuntu.com/15.04/ubuntu-15.04-server-amd64.iso", "iso_url": "http://releases.ubuntu.com/15.04/ubuntu-15.04-server-amd64.iso",
"iso_checksum": "487f4a81f22f8597503db3d51a1b502e", "iso_checksum": "487f4a81f22f8597503db3d51a1b502e",
...@@ -30,12 +30,11 @@ ...@@ -30,12 +30,11 @@
"boot_command": [ "boot_command": [
"<esc><esc><enter><wait>", "<esc><esc><enter><wait>",
"/install/vmlinuz url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-ubuntu.cfg ", "/install/vmlinuz url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-ubuntu.cfg ",
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", "debian-installer=en_US auto locale=en_US kbd-chooser/method=fr ",
"hostname={{ .Name }} ", "hostname={{ .Name }} ",
"keyboard-configuration/modelcode=SKIP ", "keyboard-configuration/modelcode=pc101 ",
"keyboard-configuration/layout=USA ", "keyboard-configuration/layoutcode=fr ",
"keyboard-configuration/variant=USA ",
"passwd/user-fullname={{user `user`}} ", "passwd/user-fullname={{user `user`}} ",
"passwd/user-password-again={{user `password`}} ", "passwd/user-password-again={{user `password`}} ",
......
{
"variables": {
"user": "slapos",
"password": "slapos",
"domain": "",
"disk_size": "200",
"name": "image",
"custom_script": ""
},
"builders":
[
{
"name": "ubuntu-16-server-amd64-{{ user `disk_size`}}G-{{ user `name`}}",
"type": "qemu",
"format": "qcow2",
"accelerator": "kvm",
"disk_size": "{{ user `disk_size`}}000",
"headless": true,
"iso_url": "http://releases.ubuntu.com/16.10/ubuntu-16.10-server-amd64.iso",
"iso_checksum": "7d6de832aee348bacc894f0a2ab1170d",
"iso_checksum_type": "md5",
"http_directory": "http",
"ssh_username": "{{user `user`}}",
"ssh_password": "{{user `password`}}",
"ssh_wait_timeout": "1800s",
"shutdown_command": "echo '{{user `password`}}'|sudo -S shutdown -P now",
"boot_wait": "2s",
"boot_command": [
"<esc><esc><enter><wait>",
"/install/vmlinuz url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed-ubuntu.cfg ",
"debian-installer=en_US auto locale=en_US kbd-chooser/method=fr ",
"hostname={{ .Name }} ",
"keyboard-configuration/modelcode=pc101 ",
"keyboard-configuration/layoutcode=fr ",
"passwd/user-fullname={{user `user`}} ",
"passwd/user-password-again={{user `password`}} ",
"passwd/user-password={{user `password`}} ",
"passwd/username={{user `user`}} ",
"initrd=/install/initrd.gz -- <enter>"
]
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "echo '{{user `password`}}' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"scripts": [
"scripts/update-ubuntu.sh",
"scripts/packages-ubuntu.sh",
"scripts/network-ubuntu.sh",
"{{ user `custom_script` }}"
]
}
]
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment