From 364fbbc399f0d90951a1b5b23b6614ba0f631b2d Mon Sep 17 00:00:00 2001 From: Moritz Heiber Date: Sun, 22 Apr 2018 12:02:18 +0200 Subject: [PATCH] Updated to newest Packer definitions; removed Atlas integration (deprecated) --- .gitignore | 1 + LICENSE.md | 2 +- README.md | 20 +++--- packer.atlas.json => packer.json | 27 ++++---- packer.local.json | 106 ------------------------------- 5 files changed, 25 insertions(+), 131 deletions(-) rename packer.atlas.json => packer.json (89%) delete mode 100644 packer.local.json diff --git a/.gitignore b/.gitignore index b4fd43a..10d5ae4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /builds /packer_cache /.vagrant +/output-virtualbox-iso diff --git a/LICENSE.md b/LICENSE.md index 971572c..b2bd1f3 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ The MIT License (MIT) ===================== -Copyright © 2017 Moritz Heiber +Copyright © 2017-2018 Moritz Heiber Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README.md b/README.md index 2b1c6df..2da9c5e 100644 --- a/README.md +++ b/README.md @@ -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= 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 diff --git a/packer.atlas.json b/packer.json similarity index 89% rename from packer.atlas.json rename to packer.json index 46a0667..a30e2ee 100644 --- a/packer.atlas.json +++ b/packer.json @@ -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", diff --git a/packer.local.json b/packer.local.json deleted file mode 100644 index fa04b8f..0000000 --- a/packer.local.json +++ /dev/null @@ -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": [ - "", - "", - "", - "", - "/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", - " -- ", - "" - ], - "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" - } - ] -}