Update of Packer builder for Vagrant and various clouds
[osm/devops.git] / packer / README.md
1 # Creation of standard VM images with Packer
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14
15 ## Reference
16
17 These Packer templates are derived from the templates for building Vagrant boxes for various OS produced by the [Bento Project](https://github.com/chef/bento), produced under Apache 2 license.
18
19 ## How to build images from Packer templates
20
21 Example 1: How to build an OSM box just for the VirtualBox provider:
22
23 ```bash
24 cd packer_templates/osm
25 packer build -only=virtualbox-iso osm-7.0.1-amd64.json
26 ```
27
28 Example 2: How to build an OSM VM with the OpenStack provider:
29
30 ```bash
31 source openrc.sh    # This is only needed the first time
32 jq 'del(."post-processors")' osm-7.0.1-amd64.json > tmp.json
33 packer build -only=openstack tmp.json
34 rm tmp.json
35 ```
36
37 As it can be seen, this type of build needs some additional details and commands, since:
38
39 - We need to source the **OpenStack credentials**, besides **additional environment variables** that are required to pass cloud-dependent parameters to Packer.
40 - We must **rip the `post-processors` part** of the template, since it is likely to be incompatible with the `openstack` builder. This rip can be made easily `jq` but, unfortunately, Packer does not work reliably with piped inputs, so we need to use an intermediate temporary file.
41
42 ## How to test Vagrant boxes produced by Packer
43
44 1. Import the local box into Packer:
45    ```bash
46    cd ../../builds
47    vagrant box add --name osm/osm-rel7 osm-7.0.1.virtualbox.box
48    ```
49 2. Use the example at `vagrant_tests` to test it:
50    ```bash
51    cd ../vagrant_tests/
52    # Edit the box name in `Vagrantfile` as appropriate
53    vagrant up
54    ```
55 3. In case the local image is no longer needed, it can be removed by:
56    ```bash
57    vagrant destroy
58    vagrant box remove osm/osm-rel7
59    ```
60
61 ## How to upload boxes to Vagrant Cloud
62
63 You need to use the [Vagrant web page](https://app.vagrantup.com/boxes/search).
64
65 Here there is a [step-by-step guide](https://blog.ycshao.com/2017/09/16/how-to-upload-vagrant-box-to-vagrant-cloud/) with screenshots.