├── main.go ├── .gitignore ├── LICENSE └── README.md /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/ustream/packer-builder-lxc/builder/lxc" 5 | "github.com/mitchellh/packer/packer/plugin" 6 | ) 7 | 8 | func main() { 9 | server, err := plugin.Server() 10 | if err != nil { 11 | panic(err) 12 | } 13 | server.RegisterBuilder(new(lxc.Builder)) 14 | server.Serve() 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | 25 | pkg 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Zsolt Takács 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | packer-builder-lxc 2 | ================== 3 | 4 | Lxc builder for [Packer](https://www.packer.io/), with working provisioning. 5 | 6 | 7 | # OS Support 8 | 9 | As building platform only Linux is supported, at this point Ubuntu and Debian is tested. Please consult your lxc templates so you can pass the right parameters. All OSes should be buildable if they are supported by your lxc templates. 10 | 11 | ## Debian 12 | 13 | Wheezy is supported with lxc 1.0.0. An older version is shipped, with a broken lxc-attach command, so it's not supported. A backport deb can be created easily following [this guide](https://wiki.debian.org/SimpleBackportCreation). Debian does not ship network support by default for lxc, you have to configure it manually. See the [vagrant-lxc wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Usage-on-debian-hosts#network-configuration) for a detailed howto. 14 | 15 | If you want to do anything during provisioning that needs network access, you'll need to edit `/etc/lxc/default.conf` to bring the network up on new containers: 16 | 17 | ``` 18 | lxc.network.type=veth 19 | lxc.network.link=lxcbr0 20 | lxc.network.flags=up 21 | ``` 22 | 23 | If your containers do not get an ip address from dhcp you need to turn off checksum offloading on the bridge: 24 | 25 | ```bash 26 | /sbin/ethtool -K lxcbr0 tx off 27 | ``` 28 | 29 | If you're done with all of these you are ready to build containers on wheezy! 30 | 31 | ## Ubuntu 32 | 33 | Everything above saucy should be supported (saucy is tested). The default configuration is good to go! 34 | 35 | If your containers do not get an ip address from dhcp you need to turn off checksum offloading on the bridge: 36 | 37 | ```bash 38 | /sbin/ethtool -K lxcbr0 tx off 39 | ``` 40 | 41 | 42 | Building from source 43 | ==================== 44 | Install golang-go: 45 | ```bash 46 | sudo apt-get install golang-go 47 | ``` 48 | 49 | Install dependencies: 50 | * [gox](https://github.com/mitchellh/gox) 51 | * [go-fs](https://github.com/mitchellh/go-fs) 52 | * [multistep](https://github.com/mitchellh/multistep) 53 | * [packer-guilder-lxc](https://github.com/ustream/packer-builder-lxc) 54 | 55 | ```bash 56 | go get github.com/mitchellh/gox 57 | go get github.com/mitchellh/go-fs 58 | go get github.com/mitchellh/multistep 59 | go get github.com/ustream/packer-builder-lxc 60 | ``` 61 | Go to the source directory, usually it is in `~/gopath/src/github.com/ustream/packer-builder-lxc` 62 | ```bash 63 | cd ~/gopath/src/github.com/ustream/packer-builder-lxc 64 | ``` 65 | 66 | Build binary file with `gox` for desired platform: 67 | ```bash 68 | gox -os=linux -arch=amd64 -output=pkg/{{.OS}}_{{.Arch}}/packer-builder-lxc 69 | ``` 70 | 71 | Copy output binary file to desired location, for example to `/vagrant/packer`: 72 | ```bash 73 | cp pkg/linux_amd64/packer-builder-lxc /vagrant/packer 74 | ``` 75 | 76 | Installation 77 | ============ 78 | 79 | Add the executable to your `.packerconfig` [Core Config](https://www.packer.io/docs/other/core-configuration.html), if you use custom path like `/vagrant/packer/packer-builder-lxc`: 80 | ```json 81 | { 82 | "builders": { 83 | "lxc": "/vagrant/packer/packer-builder-lxc" 84 | } 85 | } 86 | ``` 87 | From now you should be able to use `lxc` in packer builders. 88 | 89 | Example packer templates 90 | ======================== 91 | 92 | Building wheezy on saucy: 93 | 94 | ```json 95 | { 96 | "builders": [ 97 | { 98 | "type": "lxc", 99 | "config_file": "lxc/config", 100 | "template_name": "debian", 101 | "template_environment_vars": [ 102 | "MIRROR=http://http.debian.net/debian/", 103 | "SUITE=wheezy" 104 | ], 105 | "target_runlevel": 3 106 | } 107 | ] 108 | } 109 | ``` 110 | 111 | The `config_file` is an lxc config file which will be bundled with the machine. You can create your own or just grab the `debian` or `ubuntu` from [vagrant-lxc-base-boxes](https://github.com/fgrehm/vagrant-lxc-base-boxes/tree/master/conf). 112 | 113 | 114 | Building wheezy on wheezy: 115 | 116 | ```json 117 | { 118 | "builders": [ 119 | { 120 | "type": "lxc", 121 | "config_file": "lxc/config", 122 | "template_name": "debian", 123 | "template_parameters": ["--arch", "amd64", "--release", "wheezy"], 124 | "template_environment_vars": [ 125 | "MIRROR=http://http.debian.net/debian/" 126 | ], 127 | "target_runlevel": 3 128 | } 129 | ], 130 | "provisioners": [ 131 | { 132 | "type": "shell", 133 | "only": ["lxc"], 134 | "environment_vars": [ 135 | "DISTRIBUTION=debian", 136 | "RELEASE=wheezy" 137 | ], 138 | "scripts": [ 139 | "scripts/lxc/base.sh", 140 | "scripts/lxc/vagrant-lxc-fixes.sh" 141 | ] 142 | } 143 | ], 144 | "post-processors": [ 145 | { 146 | "type": "compress", 147 | "output": "output-vagrant/wheezy64-lxc.box" 148 | } 149 | ], 150 | } 151 | ``` 152 | 153 | Note the differences in template parameters/envvars! 154 | 155 | Vagrant publishing 156 | ================== 157 | 158 | The output artifact can be compressed with the compress publisher to create a working vagrant box (see example). 159 | --------------------------------------------------------------------------------