Updated to newest Packer definitions; removed Atlas integration (deprecated)

This commit is contained in:
Moritz Heiber 2018-04-22 12:02:18 +02:00
parent 469f5782e0
commit 364fbbc399
5 changed files with 25 additions and 131 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/builds
/packer_cache
/.vagrant
/output-virtualbox-iso

View File

@ -1,7 +1,7 @@
The MIT License (MIT)
=====================
Copyright © 2017 Moritz Heiber <hello@heiber.im>
Copyright © 2017-2018 Moritz Heiber <hello@heiber.im>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation

View File

@ -1,6 +1,6 @@
# A VirtualBox image for Mastodon development
This VirtualBox base image contains all the required packages and configuration for running/instantiating a Mastodon instance for development. It is build using [Hashicorp's Packer](https://packer.io), the provisioning is done with Ansible through a dedicated git submodule called [mastodon-ansible](https://github.com/moritzheiber/mastodon-ansible). The tests are using [ServerSpec](https://serverspec.org). The image is build continuously using [Hashicorp Atlas](https://atlas.hashicorp.com).
This VirtualBox base image contains all the required packages and configuration for running/instantiating a Mastodon instance for development. It is build using [Hashicorp's Packer](https://packer.io), the provisioning is done with Ansible through a dedicated git submodule called [mastodon-ansible](https://github.com/moritzheiber/mastodon-ansible). The tests are using [ServerSpec](https://serverspec.org). It's made available through [Hashicorp's Vagrant Cloud](https://app.vagrantup.com) at [`mastodon/ubuntu-xenial64`](https://app.vagrantup.com/mastodon/boxes/ubuntu-xenial64).
_Note: Some of the content of the scripts in `scripts/` is borrowed from the [Bento](https://github.com/chef/bento) project._
@ -13,7 +13,7 @@ _Note: Some of the content of the scripts in `scripts/` is borrowed from the [Be
for testing purposes:
- Vagrant >= 1.9.3
- Vagrant >= 2.0.3
## Setup
@ -28,7 +28,7 @@ $ pip install -r requirements.txt
Just execute:
```sh
$ packer build packer.local.json
$ packer build packer.json
```
_Note: It will take at least roughly 5 - 10 minutes for the ISO to get preseeded ("pre-provisioned") by the Debian installer, hence the rather long timeout/waiting period before packer actually starts provisioning. If you're unsure whether there is any progress change the values `headless` in the `packer.json` from `true` to `false` and re-run the process. This will give have VirtualBox show you the output of the console the ISO is running on._
@ -37,17 +37,15 @@ This will preseed the Ubuntu ISO image for Ubuntu Xenial 64bit with a couple of
In the end you should have a box in `builds/` with all the required components installed you can run directly in Vagrant.
## Submitting to Atlas
## Publishing to Vagrant Cloud
[HashiCorp](https://www.hashicorp.com)'s Atlas can be used to build new boxes. Usually it's either very difficult or impossible to build them on other SaaS offerings (because you need a fully virtualized environment to run VirtualBox). To push a new configuration to Atlas run:
_Note: You need a valid access token to submit new versions of the box to Vagrant Cloud. It will not work otherwise. There is a organization called `mastodon` which is responsible for the Vagrant boxes under the same namespace. If you think you can/want to contribute send me a message on @moritzheiber@mastodon.social and I'll add your to the organization._
If you have a valid `VAGRANT_CLOUD_TOKEN` you can use the `vagrant-cloud` post-processor to upload a new version to Vagrant Cloud. It'll be done automatically if the token is set:
```sh
$ packer push -token=<your-token> packer.atlas.json
```
Only files that are checked into git are uploaded/submitted to Packer Enterprise (i.e. everything in `.gitignore` stays where it is).
_Note: There is a organization within Packer Enterprise called `mastodon` which is responsible for the Vagrant boxes under the same namespace. If you think you can/want to contribute send me a message on @moritzheiber@mastodon.social and I'll add your to the organization. This GitHub repository is bound to the Packer Enterprise configuration `mastodon/ubuntu-xenial64` and will trigger a new build for each commit._
$ VAGRANT_CLOUD_TOKEN="my-token" packer build packer.json
```
## Testing

View File

@ -46,7 +46,7 @@
"environment_vars": ["ANSIBLE_REMOTE_TEMP=\"/tmp/mastodon/.ansible-tmp\"", "ANSIBLE_SSH_PIPELINING=True" ],
"inline": [
". venv/bin/activate",
"ansible-playbook -i /tmp/mastodon/ansible.hosts -v -b --extra-vars mastodon_db_password=CHANGEME /tmp/mastodon/ansible/playbook.yml"
"ansible-playbook -i /tmp/mastodon/ansible.hosts -v -b --extra-vars mastodon_db_password=CHANGEME /tmp/mastodon/ansible/bare/playbook.yml"
]
},
{
@ -89,11 +89,11 @@
"guest_os_type": "Ubuntu_64",
"headless": true,
"http_directory": "preseeds",
"iso_urls": "http://releases.ubuntu.com/16.04/ubuntu-16.04.3-server-amd64.iso",
"iso_urls": "http://releases.ubuntu.com/16.04/ubuntu-16.04.4-server-amd64.iso",
"iso_checksum_type": "sha256",
"iso_checksum": "a06cd926f5855d4f21fb4bc9978a35312f815fbda0d0ef7fdc846861f4fc4600",
"iso_checksum": "0a03608988cfd2e50567990dc8be96fb3c501e198e2e6efcb846d89efc7b89f2",
"ssh_username": "{{user `user`}}",
"ssh_password": "{{user `user`}}",
"ssh_password": "{{user `password`}}",
"ssh_wait_timeout": "20m",
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now",
"vm_name": "packer-ubuntu-16.04-amd64",
@ -114,16 +114,17 @@
}
],
"post-processors": [
{
"type": "atlas",
"artifact": "mastodon/ubuntu-xenial64",
"artifact_type": "vagrant.box",
"metadata": {
"created_at": "{{timestamp}}",
"description": "A Vagrant image for Mastodon development",
"provider": "virtualbox-iso"
[
{
"output": "builds/{{.Provider}}-mastodon-ubuntu1604.box",
"type": "vagrant"
},
{
"type": "vagrant-cloud",
"box_tag": "mastodon/ubuntu-xenial64",
"version": "0.5.{{timestamp}}"
}
}
]
],
"push": {
"name": "mastodon/ubuntu-xenial64",

View File

@ -1,106 +0,0 @@
{
"variables": {
"user": "vagrant",
"password": "vagrant"
},
"provisioners": [
{ "type": "shell",
"inline": [
"install -m0700 -o {{user `user`}} -g {{user `user`}} -d /home/{{user `user`}}/.ssh",
"curl -SsL https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -o /home/{{user `user`}}/.ssh/authorized_keys"
]
},
{ "type": "shell",
"execute_command": "{{ .Vars }} sudo -E -S sh '{{ .Path }}'",
"inline": [
"mount -o loop ${HOME}/VBoxGuestAdditions.iso /mnt",
"/mnt/VBoxLinuxAdditions.run install",
"ln -sf /usr/lib/VBoxGuestAdditions/mount.vboxsf /sbin/mount.vboxsf",
"umount /mnt",
"rm ${HOME}/VBoxGuestAdditions.iso"
]
},
{
"type": "ansible",
"playbook_file": "ansible/playbook.yml",
"extra_arguments": [ "--extra-vars", "mastodon_db_password=CHANGEME" ],
"ansible_env_vars": [
"ANSIBLE_REMOTE_TEMP=\"~/.ansible-tmp\"",
"ANSIBLE_SSH_PIPELINING=True"
]
},
{ "type": "shell",
"execute_command": "{{ .Vars }} sudo -E -S sh '{{ .Path }}'",
"script": "scripts/clean.sh"
},
{
"type": "shell",
"execute_command": "{{ .Vars }} sudo -E -S sh '{{ .Path }}'",
"script": "scripts/minimize.sh"
}
],
"builders": [
{
"type": "virtualbox-iso",
"boot_command": [
"<enter><wait><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"/install/vmlinuz ",
" auto ",
" console-setup/ask_detect=false ",
" console-setup/layoutcode=us ",
" console-setup/modelcode=pc105 ",
" debconf/frontend=noninteractive ",
" debian-installer=en_US.UTF-8 ",
" fb=false ",
" initrd=/install/initrd.gz ",
" kbd-chooser/method=us ",
" keyboard-configuration/layout=USA ",
" keyboard-configuration/variant=USA ",
" locale=en_US.UTF-8 ",
" netcfg/get_domain=vm ",
" netcfg/get_hostname=vagrant ",
" grub-installer/bootdev=/dev/sda ",
" noapic ",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
" -- <wait>",
"<enter><wait>"
],
"boot_wait": "10s",
"disk_size": 10000,
"guest_os_type": "Ubuntu_64",
"headless": true,
"http_directory": "preseeds",
"iso_urls": "http://releases.ubuntu.com/16.04/ubuntu-16.04.3-server-amd64.iso",
"iso_checksum_type": "sha256",
"iso_checksum": "a06cd926f5855d4f21fb4bc9978a35312f815fbda0d0ef7fdc846861f4fc4600",
"ssh_username": "{{user `user`}}",
"ssh_password": "{{user `user`}}",
"ssh_wait_timeout": "20m",
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now",
"vm_name": "packer-ubuntu-16.04-amd64",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"1024"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"1"
]
]
}
],
"post-processors": [
{
"output": "builds/{{.Provider}}-mastodon-ubuntu1604.box",
"type": "vagrant"
}
]
}