tylert / packer-build

Packer Automated VM Image and Vagrant Box Builds

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pretty useful

joeblew99 opened this issue · comments

I have not used packer yet , and am on OSX, not Linux.
Would you be able to comment on the use case I have below, so I can get a high level view of if this code could help me ??

I need to create USB bootable thumb drives of 3 types:

Windows 10, with some programs already installed

Raspberry pi.
Same software on it as the windows 10 box

Ubuntu 16.04 server. With postresql and some golang executables.

It would be super awesome if I could make vagrant boxes / qemu boxes of the same also. Then I can test in a vm, then make the bootable USB images as needed or maybe even as part of CI

Thanks in advance

That's quite the large collection of requirements...

Getting started is pretty easy if you have http://brew.sh/ installed...

brew install packer

I use Packer on Mac OSX and Linux with VirtualBox on both and qemu on Linux. If you're trying to get qemu working, you'll probably want to consider setting yourself up a Linux machine on a spare x86_64 machine.

Something to remember... Vagrant box files are tar.gz archives containing: box.ovf, name_of_machine-disk1.vmdk, Vagrantfile, metadata.json and OVA files are tar archives containing the same box.ovf file renamed to name_of_machine.ovf and the same vmdk file. The qemu-img convert can be used to convert the vmdk file to a qemu raw file but I haven't tested it yet.

I haven't touched Windows for nearly 2 decades now so I won't be able to help you there. Perhaps you should do a search for packer Windows projects on GitHub (I know there are a few).

You won't be able to boot your Raspberry Pi from USB but you can put your root filesystem there and boot from uSD or SD. If all you want to do is make sure you have the same software on there, there are other ways of doing that.

I have starred a few Raspberry Pi image builder GitHub projects with the intention of eventually building my own images from scratch to add a few packages. The idea that you are suggesting trying to make non-bootable root filesystems for Raspberry Pi using Packer is something I have also considered trying.

I'll try to answer a bit more when I have some more time.

Doing the Ubuntu server build will be very easy to generate both a qemu and vagrant image using the same template--I do this already in my packer templates.

I just added a Xenial Xerus template for you to try. I haven't tested it yet but I'm pretty confident it's mostly ok. You'd likely just change one line d-i pkgsel/include string openssh-server, postgresql to add another entry to the package list in the base-64.seed file or else apt-get install postgresql sometime later (in another shell provisioner perhaps).

As for adding Go, you'd probably want to grab a more recent binary rather than use the old crufty one packaged in Ubuntu. I just added a similar thing for packer in their vagrant file recently. It basically is just does (using sudo)...

# Fetch from https://golang.org/dl
TARBALL="https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz"

UNTARPATH="/opt"
GOROOT="${UNTARPATH}/go"
GOPATH="${UNTARPATH}/gopath"

# Install Go
if [ ! -d ${GOROOT} ]; then
  sudo wget --progress=bar:force --output-document - ${TARBALL} |\
    tar xfz - -C ${UNTARPATH}
fi

# Setup the GOPATH
sudo mkdir -p ${GOPATH}
cat <<EOF >/tmp/gopath.sh
export GOROOT="${GOROOT}"
export GOPATH="${GOPATH}"
export PATH="${GOROOT}/bin:${GOPATH}/bin:\$PATH"
EOF
sudo mv /tmp/gopath.sh /etc/profile.d/gopath.sh

The more I think about it, I think the Raspberry Pi stuff is going to likely require a totally different toolchain and build environment.

I'd just build your Raspberry Pi images using something designed for building such images such as one of the following projects:

Thanks for the hugely thorough answer.

Ubuntu Core is my favourite target for an OS. I am working on Snaps etc, and also the Transactional OS updates stuff in a vagrant machine.

I was thinking about this, and there are really two fundamental approaches:
1 - try to build images with all the stuff you need in them, and BURN it
2 - just boot the OS, and have a script to install the other bits.

Your seed file looks pretty cool.

About getting a Linux box in order to do QEMU. Yep makes sense. I saw some googlings about running QEMU on OSX, but have not tried yet.

I will play around and see how far i get.