From 8ac0f088f6d30ee030f1ef6fe768da2f242c5046 Mon Sep 17 00:00:00 2001 From: ramonsalguer Date: Wed, 3 Jun 2020 20:13:34 +0200 Subject: [PATCH] Update of Packer builder for Vagrant and various clouds Change-Id: I71d3a6fb21ce2b3c54993072f42749a5869fae96 Signed-off-by: ramonsalguer --- packer/.gitignore | 30 ++ packer/README.md | 65 ++++ packer/TEMPLATE-openrc.sh | 22 ++ packer/{ => old_releases}/http/preseed.cfg | 12 + packer/old_releases/scripts/cleanup.sh | 26 ++ .../old_releases/scripts/get-install-osm.sh | 27 ++ .../old_releases/scripts/install_packages.sh | 23 ++ packer/old_releases/scripts/juju-setup.sh | 16 + packer/{ => old_releases}/scripts/lxd-bridge | 12 + packer/old_releases/scripts/lxd-setup.sh | 22 ++ packer/old_releases/scripts/setup.sh | 17 + packer/{ => old_releases}/scripts/vimemu.sh | 13 + .../{ => old_releases}/ubuntu1604-juju.json | 0 .../ubuntu1604-ovf-osm-dev.json | 0 .../ubuntu1604-ovf-osm.json | 0 .../_common/check_vagrant_user.sh | 26 ++ packer/packer_templates/_common/metadata.sh | 18 + packer/packer_templates/_common/minimize.sh | 48 +++ packer/packer_templates/_common/motd.sh | 32 ++ packer/packer_templates/_common/parallels.sh | 47 +++ packer/packer_templates/_common/sshd.sh | 32 ++ packer/packer_templates/_common/vagrant.sh | 31 ++ packer/packer_templates/_common/virtualbox.sh | 31 ++ packer/packer_templates/_common/vmware.sh | 46 +++ packer/packer_templates/osm/README.md | 25 ++ .../osm/http/preseed-hyperv.cfg | 50 +++ packer/packer_templates/osm/http/preseed.cfg | 47 +++ .../osm/osm-7.0.1-amd64-volume.json | 356 ++++++++++++++++++ .../packer_templates/osm/osm-7.0.1-amd64.json | 353 +++++++++++++++++ .../packer_templates/osm/scripts/cleanup.sh | 93 +++++ packer/packer_templates/osm/scripts/hyperv.sh | 25 ++ .../osm/scripts/install_osm.sh | 164 ++++++++ .../osm/scripts/networking.sh | 37 ++ .../packer_templates/osm/scripts/sudoers.sh | 19 + packer/packer_templates/osm/scripts/update.sh | 56 +++ .../osm/scripts/update_osm_info_docker.sh | 79 ++++ .../packer_templates/osm/scripts/vagrant.sh | 26 ++ packer/packer_templates/osm/scripts/vmware.sh | 22 ++ packer/scripts/cleanup.sh | 14 - packer/scripts/get-install-osm.sh | 14 - packer/scripts/install_packages.sh | 10 - packer/scripts/juju-setup.sh | 3 - packer/scripts/lxd-setup.sh | 10 - packer/scripts/setup.sh | 5 - packer/vagrant_tests/Vagrantfile | 38 ++ packer/vagrant_tests/Vagrantfile - Commented | 106 ++++++ 46 files changed, 2092 insertions(+), 56 deletions(-) create mode 100644 packer/README.md create mode 100644 packer/TEMPLATE-openrc.sh rename packer/{ => old_releases}/http/preseed.cfg (75%) create mode 100644 packer/old_releases/scripts/cleanup.sh create mode 100644 packer/old_releases/scripts/get-install-osm.sh create mode 100644 packer/old_releases/scripts/install_packages.sh create mode 100644 packer/old_releases/scripts/juju-setup.sh rename packer/{ => old_releases}/scripts/lxd-bridge (68%) create mode 100644 packer/old_releases/scripts/lxd-setup.sh create mode 100644 packer/old_releases/scripts/setup.sh rename packer/{ => old_releases}/scripts/vimemu.sh (71%) mode change 100755 => 100644 rename packer/{ => old_releases}/ubuntu1604-juju.json (100%) rename packer/{ => old_releases}/ubuntu1604-ovf-osm-dev.json (100%) rename packer/{ => old_releases}/ubuntu1604-ovf-osm.json (100%) create mode 100644 packer/packer_templates/_common/check_vagrant_user.sh create mode 100644 packer/packer_templates/_common/metadata.sh create mode 100644 packer/packer_templates/_common/minimize.sh create mode 100644 packer/packer_templates/_common/motd.sh create mode 100644 packer/packer_templates/_common/parallels.sh create mode 100644 packer/packer_templates/_common/sshd.sh create mode 100644 packer/packer_templates/_common/vagrant.sh create mode 100644 packer/packer_templates/_common/virtualbox.sh create mode 100644 packer/packer_templates/_common/vmware.sh create mode 100644 packer/packer_templates/osm/README.md create mode 100644 packer/packer_templates/osm/http/preseed-hyperv.cfg create mode 100644 packer/packer_templates/osm/http/preseed.cfg create mode 100644 packer/packer_templates/osm/osm-7.0.1-amd64-volume.json create mode 100644 packer/packer_templates/osm/osm-7.0.1-amd64.json create mode 100644 packer/packer_templates/osm/scripts/cleanup.sh create mode 100644 packer/packer_templates/osm/scripts/hyperv.sh create mode 100644 packer/packer_templates/osm/scripts/install_osm.sh create mode 100644 packer/packer_templates/osm/scripts/networking.sh create mode 100644 packer/packer_templates/osm/scripts/sudoers.sh create mode 100644 packer/packer_templates/osm/scripts/update.sh create mode 100644 packer/packer_templates/osm/scripts/update_osm_info_docker.sh create mode 100644 packer/packer_templates/osm/scripts/vagrant.sh create mode 100644 packer/packer_templates/osm/scripts/vmware.sh delete mode 100644 packer/scripts/cleanup.sh delete mode 100755 packer/scripts/get-install-osm.sh delete mode 100644 packer/scripts/install_packages.sh delete mode 100755 packer/scripts/juju-setup.sh delete mode 100644 packer/scripts/lxd-setup.sh delete mode 100644 packer/scripts/setup.sh create mode 100644 packer/vagrant_tests/Vagrantfile create mode 100644 packer/vagrant_tests/Vagrantfile - Commented diff --git a/packer/.gitignore b/packer/.gitignore index bf86b4f3..7ac7b998 100644 --- a/packer/.gitignore +++ b/packer/.gitignore @@ -1,5 +1,35 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + output-virtualbox-iso/ packer_cache/ builds/ jujubase*/ osm-*/ +*.iso +*.box +*.ovf +*.vmdk +*.vdi +virtualfloppy.vfd +packer_cache +packer.log +.DS_Store +/packer-*/ +*.variables.json +/builds/ +vagrant_tests/.vagrant +clouds.yaml +clouds.yml +openstack.rc +openrc* +*.pem \ No newline at end of file diff --git a/packer/README.md b/packer/README.md new file mode 100644 index 00000000..267d9aca --- /dev/null +++ b/packer/README.md @@ -0,0 +1,65 @@ +# Creation of standard VM images with Packer + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +## Reference + +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. + +## How to build images from Packer templates + +Example 1: How to build an OSM box just for the VirtualBox provider: + +```bash +cd packer_templates/osm +packer build -only=virtualbox-iso osm-7.0.1-amd64.json +``` + +Example 2: How to build an OSM VM with the OpenStack provider: + +```bash +source openrc.sh # This is only needed the first time +jq 'del(."post-processors")' osm-7.0.1-amd64.json > tmp.json +packer build -only=openstack tmp.json +rm tmp.json +``` + +As it can be seen, this type of build needs some additional details and commands, since: + +- We need to source the **OpenStack credentials**, besides **additional environment variables** that are required to pass cloud-dependent parameters to Packer. +- 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. + +## How to test Vagrant boxes produced by Packer + +1. Import the local box into Packer: + ```bash + cd ../../builds + vagrant box add --name osm/osm-rel7 osm-7.0.1.virtualbox.box + ``` +2. Use the example at `vagrant_tests` to test it: + ```bash + cd ../vagrant_tests/ + # Edit the box name in `Vagrantfile` as appropriate + vagrant up + ``` +3. In case the local image is no longer needed, it can be removed by: + ```bash + vagrant destroy + vagrant box remove osm/osm-rel7 + ``` + +## How to upload boxes to Vagrant Cloud + +You need to use the [Vagrant web page](https://app.vagrantup.com/boxes/search). + +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. diff --git a/packer/TEMPLATE-openrc.sh b/packer/TEMPLATE-openrc.sh new file mode 100644 index 00000000..7f79ec1b --- /dev/null +++ b/packer/TEMPLATE-openrc.sh @@ -0,0 +1,22 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +export OS_CLOUD=nameofmyopenstack +export VIM_MGMT_NET="internal" # Internal network to attach the VM +export VIM_EXT_NET="ext-net" # External network providing floating IP addresses + +# Converts the name of the internal network to UUID, so that Packer can use it +export NETWORK_ID=`openstack network list -f json | jq -r ".[] | select(.Name == \"${VIM_MGMT_NET}\") | .ID"` + +# Other environment variables for Packer +export FLAVOR_NAME=flavorname +export SOURCE_IMAGE_NAME=sourceimagename diff --git a/packer/http/preseed.cfg b/packer/old_releases/http/preseed.cfg similarity index 75% rename from packer/http/preseed.cfg rename to packer/old_releases/http/preseed.cfg index c2d3d41f..4783d393 100644 --- a/packer/http/preseed.cfg +++ b/packer/old_releases/http/preseed.cfg @@ -1,3 +1,15 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + choose-mirror-bin mirror/http/proxy string d-i base-installer/kernel/override-image string linux-server d-i clock-setup/utc boolean true diff --git a/packer/old_releases/scripts/cleanup.sh b/packer/old_releases/scripts/cleanup.sh new file mode 100644 index 00000000..c51b077d --- /dev/null +++ b/packer/old_releases/scripts/cleanup.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apt autoremove +apt update + +rm -f /home/vagrant/*.sh + +wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys +chmod 0600 /home/vagrant/.ssh/authorized_keys +chown -R vagrant:vagrant /home/vagrant/.ssh + +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY +sync diff --git a/packer/old_releases/scripts/get-install-osm.sh b/packer/old_releases/scripts/get-install-osm.sh new file mode 100644 index 00000000..6c8cfbcf --- /dev/null +++ b/packer/old_releases/scripts/get-install-osm.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +export PATH=$PATH:/snap/bin +echo "PATH=$PATH" +juju status + +wget https://osm-download.etsi.org/ftp/osm-5.0-five/install_osm.sh +chmod +x install_osm.sh +./install_osm.sh --nolxd --nojuju -y + +cat >> ~/.bashrc <<-EOF +export OSM_HOSTNAME=127.0.0.1 +export OSM_SOL005=True + +EOF diff --git a/packer/old_releases/scripts/install_packages.sh b/packer/old_releases/scripts/install_packages.sh new file mode 100644 index 00000000..2846f715 --- /dev/null +++ b/packer/old_releases/scripts/install_packages.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +sudo apt -y update && apt-get -y upgrade +sudo apt -y install git wget curl vim snapd lxd software-properties-common +sudo apt-get install -y apt-transport-https ca-certificates +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" +sudo apt-get -qq update +sudo apt-get install -y docker-ce +sudo groupadd -f docker +sudo usermod -aG docker $USER diff --git a/packer/old_releases/scripts/juju-setup.sh b/packer/old_releases/scripts/juju-setup.sh new file mode 100644 index 00000000..bc415b64 --- /dev/null +++ b/packer/old_releases/scripts/juju-setup.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +sudo snap install juju --classic +/snap/bin/juju bootstrap --bootstrap-series=xenial localhost osm diff --git a/packer/scripts/lxd-bridge b/packer/old_releases/scripts/lxd-bridge similarity index 68% rename from packer/scripts/lxd-bridge rename to packer/old_releases/scripts/lxd-bridge index ff421502..0826da7f 100644 --- a/packer/scripts/lxd-bridge +++ b/packer/old_releases/scripts/lxd-bridge @@ -1,3 +1,15 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # WARNING: This file is generated by a debconf template! # It is recommended to update it by using "dpkg-reconfigure -p medium lxd" diff --git a/packer/old_releases/scripts/lxd-setup.sh b/packer/old_releases/scripts/lxd-setup.sh new file mode 100644 index 00000000..03d23a76 --- /dev/null +++ b/packer/old_releases/scripts/lxd-setup.sh @@ -0,0 +1,22 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +sudo lxd init --auto --storage-backend zfs --storage-pool lxdpool --storage-create-loop 20 + +sudo systemctl stop lxd-bridge +sudo systemctl --system daemon-reload + +sudo cp -f /tmp/lxd-bridge /etc/default/lxd-bridge +sudo systemctl enable lxd-bridge +sudo systemctl start lxd-bridge + +sudo usermod -a -G lxd $(whoami) diff --git a/packer/old_releases/scripts/setup.sh b/packer/old_releases/scripts/setup.sh new file mode 100644 index 00000000..abcff29e --- /dev/null +++ b/packer/old_releases/scripts/setup.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers +echo 'APT::Periodic::Enable "0";' >> /etc/apt/apt.conf.d/10periodic diff --git a/packer/scripts/vimemu.sh b/packer/old_releases/scripts/vimemu.sh old mode 100755 new mode 100644 similarity index 71% rename from packer/scripts/vimemu.sh rename to packer/old_releases/scripts/vimemu.sh index d7313bae..d7a044e7 --- a/packer/scripts/vimemu.sh +++ b/packer/old_releases/scripts/vimemu.sh @@ -1,4 +1,17 @@ #!/bin/sh + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + mkdir -p /etc/systemd/system/scripts cat > /etc/systemd/system/scripts/osm-vimemu-startup.sh <<-'EOF' #!/bin/sh diff --git a/packer/ubuntu1604-juju.json b/packer/old_releases/ubuntu1604-juju.json similarity index 100% rename from packer/ubuntu1604-juju.json rename to packer/old_releases/ubuntu1604-juju.json diff --git a/packer/ubuntu1604-ovf-osm-dev.json b/packer/old_releases/ubuntu1604-ovf-osm-dev.json similarity index 100% rename from packer/ubuntu1604-ovf-osm-dev.json rename to packer/old_releases/ubuntu1604-ovf-osm-dev.json diff --git a/packer/ubuntu1604-ovf-osm.json b/packer/old_releases/ubuntu1604-ovf-osm.json similarity index 100% rename from packer/ubuntu1604-ovf-osm.json rename to packer/old_releases/ubuntu1604-ovf-osm.json diff --git a/packer/packer_templates/_common/check_vagrant_user.sh b/packer/packer_templates/_common/check_vagrant_user.sh new file mode 100644 index 00000000..bd832a08 --- /dev/null +++ b/packer/packer_templates/_common/check_vagrant_user.sh @@ -0,0 +1,26 @@ +#!/bin/bash -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script is intended for VIMs-type builders such as OpenStack, which +# use cloud images where the `vagrant` user does not exist by default + +USER=vagrant +USER_NAME=vagrant +PASSWORD=vagrant + +# If the `vagrant` user does not exist, it is created +(id ${USER} >/dev/null 2>&1) || adduser --disabled-password --gecos "${USER_NAME}" "${USER}" + +# Comment if no password should be set +echo "${USER}:${PASSWORD}" | sudo chpasswd diff --git a/packer/packer_templates/_common/metadata.sh b/packer/packer_templates/_common/metadata.sh new file mode 100644 index 00000000..4721aece --- /dev/null +++ b/packer/packer_templates/_common/metadata.sh @@ -0,0 +1,18 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +mkdir -p /etc; +cp /tmp/bento-metadata.json /etc/bento-metadata.json; +chmod 0444 /etc/bento-metadata.json; +rm -f /tmp/bento-metadata.json; diff --git a/packer/packer_templates/_common/minimize.sh b/packer/packer_templates/_common/minimize.sh new file mode 100644 index 00000000..0b0e4769 --- /dev/null +++ b/packer/packer_templates/_common/minimize.sh @@ -0,0 +1,48 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +case "$PACKER_BUILDER_TYPE" in + qemu) exit 0 ;; +esac + +# Whiteout root +count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}') +count=$(($count-1)) +dd if=/dev/zero of=/tmp/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed"; +rm /tmp/whitespace + +# Whiteout /boot +count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}') +count=$(($count-1)) +dd if=/dev/zero of=/boot/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed"; +rm /boot/whitespace + +set +e +swapuuid="`/sbin/blkid -o value -l -s UUID -t TYPE=swap`"; +case "$?" in + 2|0) ;; + *) exit 1 ;; +esac +set -e + +if [ "x${swapuuid}" != "x" ]; then + # Whiteout the swap partition to reduce box size + # Swap is disabled till reboot + swappart="`readlink -f /dev/disk/by-uuid/$swapuuid`"; + /sbin/swapoff "$swappart"; + dd if=/dev/zero of="$swappart" bs=1M || echo "dd exit code $? is suppressed"; + /sbin/mkswap -U "$swapuuid" "$swappart"; +fi + +sync; diff --git a/packer/packer_templates/_common/motd.sh b/packer/packer_templates/_common/motd.sh new file mode 100644 index 00000000..72016da2 --- /dev/null +++ b/packer/packer_templates/_common/motd.sh @@ -0,0 +1,32 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +my_custom_motd=' +This system was built by Telefónica I+D for ETSI Open Source MANO (ETSI OSM)' + +if [ -d /etc/update-motd.d ]; then + MOTD_CONFIG='/etc/update-motd.d/99-custom' + + cat >> "$MOTD_CONFIG" <> /etc/motd +fi diff --git a/packer/packer_templates/_common/parallels.sh b/packer/packer_templates/_common/parallels.sh new file mode 100644 index 00000000..3010df1c --- /dev/null +++ b/packer/packer_templates/_common/parallels.sh @@ -0,0 +1,47 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# set a default HOME_DIR environment variable if not set +HOME_DIR="${HOME_DIR:-/home/vagrant}"; + +case "$PACKER_BUILDER_TYPE" in +parallels-iso|parallels-pvm) + mkdir -p /tmp/parallels; + mount -o loop $HOME_DIR/prl-tools-lin.iso /tmp/parallels; + VER="`cat /tmp/parallels/version`"; + + echo "Parallels Tools Version: $VER"; + + /tmp/parallels/install --install-unattended-with-deps \ + || (code="$?"; \ + echo "Parallels tools installation exited $code, attempting" \ + "to output /var/log/parallels-tools-install.log"; \ + cat /var/log/parallels-tools-install.log; \ + exit $code); + umount /tmp/parallels; + rm -rf /tmp/parallels; + rm -f $HOME_DIR/*.iso; + + # Parallels Tools for Linux includes native auto-mount script, + # which causes losing some of Vagrant-relative shared folders. + # So, we should disable this behavior. + # https://github.com/Parallels/vagrant-parallels/issues/325#issuecomment-418727113 + auto_mount_script='/usr/bin/prlfsmountd' + if [ -f "${auto_mount_script}" ]; then + echo -e '#!/bin/sh\n'\ + '# Shared folders auto-mount is disabled by Vagrant ' \ + > "${auto_mount_script}" + fi + ;; +esac diff --git a/packer/packer_templates/_common/sshd.sh b/packer/packer_templates/_common/sshd.sh new file mode 100644 index 00000000..2c379066 --- /dev/null +++ b/packer/packer_templates/_common/sshd.sh @@ -0,0 +1,32 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SSHD_CONFIG="/etc/ssh/sshd_config" + +# ensure that there is a trailing newline before attempting to concatenate +sed -i -e '$a\' "$SSHD_CONFIG" + +USEDNS="UseDNS no" +if grep -q -E "^[[:space:]]*UseDNS" "$SSHD_CONFIG"; then + sed -i "s/^\s*UseDNS.*/${USEDNS}/" "$SSHD_CONFIG" +else + echo "$USEDNS" >>"$SSHD_CONFIG" +fi + +GSSAPI="GSSAPIAuthentication no" +if grep -q -E "^[[:space:]]*GSSAPIAuthentication" "$SSHD_CONFIG"; then + sed -i "s/^\s*GSSAPIAuthentication.*/${GSSAPI}/" "$SSHD_CONFIG" +else + echo "$GSSAPI" >>"$SSHD_CONFIG" +fi diff --git a/packer/packer_templates/_common/vagrant.sh b/packer/packer_templates/_common/vagrant.sh new file mode 100644 index 00000000..36b533aa --- /dev/null +++ b/packer/packer_templates/_common/vagrant.sh @@ -0,0 +1,31 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# set a default HOME_DIR environment variable if not set +HOME_DIR="${HOME_DIR:-/home/vagrant}"; + +pubkey_url="https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub"; +mkdir -p $HOME_DIR/.ssh; +if command -v wget >/dev/null 2>&1; then + wget --no-check-certificate "$pubkey_url" -O $HOME_DIR/.ssh/authorized_keys; +elif command -v curl >/dev/null 2>&1; then + curl --insecure --location "$pubkey_url" > $HOME_DIR/.ssh/authorized_keys; +elif command -v fetch >/dev/null 2>&1; then + fetch -am -o $HOME_DIR/.ssh/authorized_keys "$pubkey_url"; +else + echo "Cannot download vagrant public key"; + exit 1; +fi +chown -R vagrant $HOME_DIR/.ssh; +chmod -R go-rwsx $HOME_DIR/.ssh; diff --git a/packer/packer_templates/_common/virtualbox.sh b/packer/packer_templates/_common/virtualbox.sh new file mode 100644 index 00000000..943ea564 --- /dev/null +++ b/packer/packer_templates/_common/virtualbox.sh @@ -0,0 +1,31 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# set a default HOME_DIR environment variable if not set +HOME_DIR="${HOME_DIR:-/home/vagrant}"; + +case "$PACKER_BUILDER_TYPE" in +virtualbox-iso|virtualbox-ovf) + VER="`cat $HOME_DIR/.vbox_version`"; + ISO="VBoxGuestAdditions_$VER.iso"; + mkdir -p /tmp/vbox; + mount -o loop $HOME_DIR/$ISO /tmp/vbox; + sh /tmp/vbox/VBoxLinuxAdditions.run \ + || echo "VBoxLinuxAdditions.run exited $? and is suppressed." \ + "For more read https://www.virtualbox.org/ticket/12479"; + umount /tmp/vbox; + rm -rf /tmp/vbox; + rm -f $HOME_DIR/*.iso; + ;; +esac diff --git a/packer/packer_templates/_common/vmware.sh b/packer/packer_templates/_common/vmware.sh new file mode 100644 index 00000000..2fc524c8 --- /dev/null +++ b/packer/packer_templates/_common/vmware.sh @@ -0,0 +1,46 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# set a default HOME_DIR environment variable if not set +HOME_DIR="${HOME_DIR:-/home/vagrant}"; + +case "$PACKER_BUILDER_TYPE" in +vmware-iso|vmware-vmx) + + # make sure we have /sbin in our path. RHEL systems lack this + PATH=/sbin:$PATH + export PATH + + mkdir -p /tmp/vmware; + mkdir -p /tmp/vmware-archive; + mount -o loop $HOME_DIR/linux.iso /tmp/vmware; + + TOOLS_PATH="`ls /tmp/vmware/VMwareTools-*.tar.gz`"; + VER="`echo "${TOOLS_PATH}" | cut -f2 -d'-'`"; + MAJ_VER="`echo ${VER} | cut -d '.' -f 1`"; + + echo "VMware Tools Version: $VER"; + + tar xzf ${TOOLS_PATH} -C /tmp/vmware-archive; + if [ "${MAJ_VER}" -lt "10" ]; then + /tmp/vmware-archive/vmware-tools-distrib/vmware-install.pl --default; + else + /tmp/vmware-archive/vmware-tools-distrib/vmware-install.pl --force-install; + fi + umount /tmp/vmware; + rm -rf /tmp/vmware; + rm -rf /tmp/vmware-archive; + rm -f $HOME_DIR/*.iso; + ;; +esac diff --git a/packer/packer_templates/osm/README.md b/packer/packer_templates/osm/README.md new file mode 100644 index 00000000..6699621c --- /dev/null +++ b/packer/packer_templates/osm/README.md @@ -0,0 +1,25 @@ +# How to generate OSM images + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +## Virtualbox for Vagrant + +```bash +PACKER_LOG=1 packer build -only=virtualbox-iso osm-7.0.1-amd64.json 2>&1 | tee osm_install_log.txt +``` + +## OpenStack + +```bash +(jq 'del(."post-processors")' osm-7.0.1-amd64.json > temp.json) && (PACKER_LOG=1 packer build -only=openstack temp.json 2>&1 | tee osm_install_log.txt) +``` diff --git a/packer/packer_templates/osm/http/preseed-hyperv.cfg b/packer/packer_templates/osm/http/preseed-hyperv.cfg new file mode 100644 index 00000000..c4ab6e32 --- /dev/null +++ b/packer/packer_templates/osm/http/preseed-hyperv.cfg @@ -0,0 +1,50 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +choose-mirror-bin mirror/http/proxy string +d-i base-installer/kernel/override-image string linux-server +d-i clock-setup/utc boolean true +d-i clock-setup/utc-auto boolean true +d-i finish-install/reboot_in_progress note +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i mirror/country string manual +d-i mirror/http/directory string /ubuntu/ +d-i mirror/http/hostname string archive.ubuntu.com +d-i mirror/http/proxy string +d-i partman-auto-lvm/guided_size string max +d-i partman-auto/choose_recipe select atomic +d-i partman-auto/method string lvm +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-lvm/device_remove_lvm boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman/confirm_write_new_label boolean true +d-i partman-partitioning/no_bootable_gpt_biosgrub boolean false +d-i partman-partitioning/no_bootable_gpt_efi boolean false +d-i partman-efi/non_efi_system boolean true +d-i passwd/user-fullname string vagrant +d-i passwd/user-uid string 1000 +d-i passwd/user-password password vagrant +d-i passwd/user-password-again password vagrant +d-i passwd/username string vagrant +d-i pkgsel/include string openssh-server ntp linux-tools-$(uname -r) linux-cloud-tools-$(uname -r) linux-cloud-tools-common cifs-utils software-properties-common ifupdown +d-i pkgsel/install-language-support boolean false +d-i pkgsel/update-policy select none +d-i pkgsel/upgrade select full-upgrade +d-i time/zone string UTC +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false +tasksel tasksel/first multiselect standard, server diff --git a/packer/packer_templates/osm/http/preseed.cfg b/packer/packer_templates/osm/http/preseed.cfg new file mode 100644 index 00000000..0ce72131 --- /dev/null +++ b/packer/packer_templates/osm/http/preseed.cfg @@ -0,0 +1,47 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +choose-mirror-bin mirror/http/proxy string +d-i base-installer/kernel/override-image string linux-server +d-i clock-setup/utc boolean true +d-i clock-setup/utc-auto boolean true +d-i finish-install/reboot_in_progress note +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i mirror/country string manual +d-i mirror/http/directory string /ubuntu/ +d-i mirror/http/hostname string archive.ubuntu.com +d-i mirror/http/proxy string +d-i partman-auto-lvm/guided_size string max +d-i partman-auto/choose_recipe select atomic +d-i partman-auto/method string lvm +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-lvm/device_remove_lvm boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman/confirm_write_new_label boolean true +d-i passwd/user-fullname string vagrant +d-i passwd/user-uid string 1000 +d-i passwd/user-password password vagrant +d-i passwd/user-password-again password vagrant +d-i passwd/username string vagrant +d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common linux-headers-$(uname -r) perl cifs-utils software-properties-common rsync ifupdown +d-i pkgsel/install-language-support boolean false +d-i pkgsel/update-policy select none +d-i pkgsel/upgrade select full-upgrade +d-i time/zone string UTC +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false +tasksel tasksel/first multiselect standard, server diff --git a/packer/packer_templates/osm/osm-7.0.1-amd64-volume.json b/packer/packer_templates/osm/osm-7.0.1-amd64-volume.json new file mode 100644 index 00000000..31f884cb --- /dev/null +++ b/packer/packer_templates/osm/osm-7.0.1-amd64-volume.json @@ -0,0 +1,356 @@ +{ + "builders": [ + { + "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 }}/{{user `preseed_path`}}", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "guest_additions_url": "{{ user `guest_additions_url` }}", + "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", + "guest_os_type": "Ubuntu_64", + "hard_drive_interface": "sata", + "headless": "{{ user `headless` }}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-virtualbox", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_timeout": "10000s", + "type": "virtualbox-iso", + "memory": "{{ user `memory` }}", + "cpus": "{{ user `cpus` }}", + "virtualbox_version_file": ".vbox_version", + "vm_name": "{{ user `template` }}" + }, + { + "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 }}/{{user `preseed_path`}}", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "guest_os_type": "ubuntu-64", + "headless": "{{ user `headless` }}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-vmware", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_timeout": "10000s", + "tools_upload_flavor": "linux", + "type": "vmware-iso", + "vm_name": "{{ user `template` }}", + "memory": "{{ user `memory` }}", + "cpus": "{{ user `cpus` }}", + "vmx_data": { + "cpuid.coresPerSocket": "1", + "ethernet0.pciSlotNumber": "32" + }, + "vmx_remove_ethernet_interfaces": true + }, + { + "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 }}/{{user `preseed_path`}}", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "guest_os_type": "ubuntu", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-parallels", + "parallels_tools_flavor": "lin", + "memory": "{{ user `memory` }}", + "cpus": "{{ user `cpus` }}", + "prlctl_version_file": ".prlctl_version", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_timeout": "10000s", + "type": "parallels-iso", + "vm_name": "{{ user `template` }}" + }, + { + "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/vda", + " noapic", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `preseed_path`}}", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "headless": "{{ user `headless` }}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-qemu", + "memory": "{{ user `memory` }}", + "cpus": "{{ user `cpus` }}", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_timeout": "10000s", + "type": "qemu", + "vm_name": "{{ user `template` }}" + }, + { + "type": "openstack", + "source_image_name": "{{ user `openstack_image` }}", + "ssh_username": "ubuntu", + "ssh_port": 22, + "ssh_timeout": "10000s", + "flavor": "{{ user `openstack_flavor` }}", + "image_name": "{{ user `template` }}", + "networks": [ "{{ user `openstack_internal_net` }}" ], + "floating_ip_network": "{{ user `openstack_floating_net` }}", + "image_disk_format": "qcow2", + "use_blockstorage_volume": true, + "volume_size": "80" + }, + { + "boot_command": [ + "", + "set gfxpayload=1024x768", + "linux /install/vmlinuz ", + "preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed-hyperv.cfg ", + "debian-installer=en_US.UTF-8 auto locale=en_US.UTF-8 kbd-chooser/method=us ", + "hostname={{.Name}} ", + "fb=false debconf/frontend=noninteractive ", + "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", + "keyboard-configuration/variant=USA console-setup/ask_detect=false ", + "initrd /install/initrd.gz", + "boot" + ], + "boot_wait": "10s", + "communicator": "ssh", + "cpus": "{{ user `cpus` }}", + "disk_size": "{{user `disk_size`}}", + "enable_secure_boot": false, + "generation": "{{user `hyperv_generation`}}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "memory": "{{user `memory`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-hyperv", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_timeout": "10000s", + "ssh_username": "vagrant", + "switch_name": "{{user `hyperv_switch`}}", + "type": "hyperv-iso", + "vm_name": "{{ user `template` }}" + } + ], + "post-processors": [ + { + "output": "{{ user `build_directory` }}/{{user `box_basename`}}.{{.Provider}}.box", + "type": "vagrant" + } + ], + "provisioners": [ + { + "environment_vars": [ + "HOME_DIR=/home/vagrant", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "no_proxy={{user `no_proxy`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'", + "expect_disconnect": true, + "scripts": [ + "{{template_dir}}/../_common/check_vagrant_user.sh", + "{{template_dir}}/scripts/update.sh", + "{{template_dir}}/../_common/motd.sh", + "{{template_dir}}/../_common/sshd.sh", + "{{template_dir}}/scripts/networking.sh", + "{{template_dir}}/scripts/sudoers.sh", + "{{template_dir}}/scripts/vagrant.sh", + "{{template_dir}}/../_common/virtualbox.sh", + "{{template_dir}}/scripts/vmware.sh", + "{{template_dir}}/../_common/parallels.sh", + "{{template_dir}}/scripts/hyperv.sh" + ], + "type": "shell" + }, + { + "environment_vars": [ + "HOME_DIR=/home/vagrant", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "no_proxy={{user `no_proxy`}}", + "STATE_FOLDER={{user `state_folder`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S su - vagrant -c '{{.Vars}} {{.Path}}'", + "expect_disconnect": "true", + "scripts": [ + "{{template_dir}}/scripts/install_osm.sh" + ], + "type": "shell" + }, + { + "type": "file", + "source": "{{template_dir}}/scripts/update_osm_info_docker.sh", + "destination": "/tmp/update_osm_info_docker.sh" + }, + { + "environment_vars": [ + "HOME_DIR=/home/vagrant", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "no_proxy={{user `no_proxy`}}", + "STATE_FOLDER={{user `state_folder`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S su - vagrant -c '{{.Vars}} {{.Path}}'", + "expect_disconnect": "true", + "inline": [ + "sudo mv /tmp/update_osm_info_docker.sh ${STATE_FOLDER}/", + "sudo chmod a+rx ${STATE_FOLDER}/update_osm_info_docker.sh" + ], + "type": "shell" + }, + { + "environment_vars": [ + "HOME_DIR=/home/vagrant", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "no_proxy={{user `no_proxy`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'", + "expect_disconnect": true, + "scripts": [ + "{{template_dir}}/scripts/cleanup.sh", + "{{template_dir}}/../_common/minimize.sh" + ], + "type": "shell" + } + ], + "variables": { + "box_basename": "osm-7.0.1", + "build_directory": "../../builds", + "http_directory": "{{template_dir}}/http", + "build_timestamp": "{{isotime \"20060102150405\"}}", + "cpus": "1", + "disk_size": "65536", + "git_revision": "__unknown_git_revision__", + "headless": "", + "http_proxy": "{{env `http_proxy`}}", + "https_proxy": "{{env `https_proxy`}}", + "hyperv_generation": "2", + "openstack_internal_net": "{{env `NETWORK_ID`}}", + "openstack_floating_net": "{{env `VIM_EXT_NET`}}", + "openstack_flavor": "{{env `FLAVOR_NAME`}}", + "openstack_image": "{{env `SOURCE_IMAGE_NAME`}}", + "guest_additions_url": "", + "iso_checksum": "e2ecdace33c939527cbc9e8d23576381c493b071107207d2040af72595f8990b", + "iso_checksum_type": "sha256", + "iso_name": "ubuntu-18.04.4-server-amd64.iso", + "memory": "6144", + "mirror": "http://cdimage.ubuntu.com", + "mirror_directory": "ubuntu/releases/18.04.4/release", + "name": "osm-7.0.1", + "no_proxy": "{{env `no_proxy`}}", + "preseed_path": "preseed.cfg", + "template": "osm-7.0.1-amd64", + "state_folder": "/etc/osm", + "version": "TIMESTAMP" + } +} diff --git a/packer/packer_templates/osm/osm-7.0.1-amd64.json b/packer/packer_templates/osm/osm-7.0.1-amd64.json new file mode 100644 index 00000000..488cd904 --- /dev/null +++ b/packer/packer_templates/osm/osm-7.0.1-amd64.json @@ -0,0 +1,353 @@ +{ + "builders": [ + { + "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 }}/{{user `preseed_path`}}", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "guest_additions_url": "{{ user `guest_additions_url` }}", + "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", + "guest_os_type": "Ubuntu_64", + "hard_drive_interface": "sata", + "headless": "{{ user `headless` }}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-virtualbox", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_timeout": "10000s", + "type": "virtualbox-iso", + "memory": "{{ user `memory` }}", + "cpus": "{{ user `cpus` }}", + "virtualbox_version_file": ".vbox_version", + "vm_name": "{{ user `template` }}" + }, + { + "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 }}/{{user `preseed_path`}}", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "guest_os_type": "ubuntu-64", + "headless": "{{ user `headless` }}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-vmware", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_timeout": "10000s", + "tools_upload_flavor": "linux", + "type": "vmware-iso", + "vm_name": "{{ user `template` }}", + "memory": "{{ user `memory` }}", + "cpus": "{{ user `cpus` }}", + "vmx_data": { + "cpuid.coresPerSocket": "1", + "ethernet0.pciSlotNumber": "32" + }, + "vmx_remove_ethernet_interfaces": true + }, + { + "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 }}/{{user `preseed_path`}}", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "guest_os_type": "ubuntu", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-parallels", + "parallels_tools_flavor": "lin", + "memory": "{{ user `memory` }}", + "cpus": "{{ user `cpus` }}", + "prlctl_version_file": ".prlctl_version", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_timeout": "10000s", + "type": "parallels-iso", + "vm_name": "{{ user `template` }}" + }, + { + "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/vda", + " noapic", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `preseed_path`}}", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "headless": "{{ user `headless` }}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-qemu", + "memory": "{{ user `memory` }}", + "cpus": "{{ user `cpus` }}", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_timeout": "10000s", + "type": "qemu", + "vm_name": "{{ user `template` }}" + }, + { + "type": "openstack", + "source_image_name": "{{ user `openstack_image` }}", + "ssh_username": "ubuntu", + "ssh_port": 22, + "ssh_timeout": "10000s", + "flavor": "{{ user `openstack_flavor` }}", + "image_name": "{{ user `template` }}", + "networks": [ "{{ user `openstack_internal_net` }}" ], + "floating_ip_network": "{{ user `openstack_floating_net` }}" + }, + { + "boot_command": [ + "", + "set gfxpayload=1024x768", + "linux /install/vmlinuz ", + "preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed-hyperv.cfg ", + "debian-installer=en_US.UTF-8 auto locale=en_US.UTF-8 kbd-chooser/method=us ", + "hostname={{.Name}} ", + "fb=false debconf/frontend=noninteractive ", + "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", + "keyboard-configuration/variant=USA console-setup/ask_detect=false ", + "initrd /install/initrd.gz", + "boot" + ], + "boot_wait": "10s", + "communicator": "ssh", + "cpus": "{{ user `cpus` }}", + "disk_size": "{{user `disk_size`}}", + "enable_secure_boot": false, + "generation": "{{user `hyperv_generation`}}", + "http_directory": "{{user `http_directory`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "memory": "{{user `memory`}}", + "output_directory": "{{ user `build_directory` }}/packer-{{user `template`}}-hyperv", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_timeout": "10000s", + "ssh_username": "vagrant", + "switch_name": "{{user `hyperv_switch`}}", + "type": "hyperv-iso", + "vm_name": "{{ user `template` }}" + } + ], + "post-processors": [ + { + "output": "{{ user `build_directory` }}/{{user `box_basename`}}.{{.Provider}}.box", + "type": "vagrant" + } + ], + "provisioners": [ + { + "environment_vars": [ + "HOME_DIR=/home/vagrant", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "no_proxy={{user `no_proxy`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'", + "expect_disconnect": true, + "scripts": [ + "{{template_dir}}/../_common/check_vagrant_user.sh", + "{{template_dir}}/scripts/update.sh", + "{{template_dir}}/../_common/motd.sh", + "{{template_dir}}/../_common/sshd.sh", + "{{template_dir}}/scripts/networking.sh", + "{{template_dir}}/scripts/sudoers.sh", + "{{template_dir}}/scripts/vagrant.sh", + "{{template_dir}}/../_common/virtualbox.sh", + "{{template_dir}}/scripts/vmware.sh", + "{{template_dir}}/../_common/parallels.sh", + "{{template_dir}}/scripts/hyperv.sh" + ], + "type": "shell" + }, + { + "environment_vars": [ + "HOME_DIR=/home/vagrant", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "no_proxy={{user `no_proxy`}}", + "STATE_FOLDER={{user `state_folder`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S su - vagrant -c '{{.Vars}} {{.Path}}'", + "expect_disconnect": "true", + "scripts": [ + "{{template_dir}}/scripts/install_osm.sh" + ], + "type": "shell" + }, + { + "type": "file", + "source": "{{template_dir}}/scripts/update_osm_info_docker.sh", + "destination": "/tmp/update_osm_info_docker.sh" + }, + { + "environment_vars": [ + "HOME_DIR=/home/vagrant", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "no_proxy={{user `no_proxy`}}", + "STATE_FOLDER={{user `state_folder`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S su - vagrant -c '{{.Vars}} {{.Path}}'", + "expect_disconnect": "true", + "inline": [ + "sudo mv /tmp/update_osm_info_docker.sh ${STATE_FOLDER}/", + "sudo chmod a+rx ${STATE_FOLDER}/update_osm_info_docker.sh" + ], + "type": "shell" + }, + { + "environment_vars": [ + "HOME_DIR=/home/vagrant", + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "no_proxy={{user `no_proxy`}}" + ], + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'", + "expect_disconnect": true, + "scripts": [ + "{{template_dir}}/scripts/cleanup.sh", + "{{template_dir}}/../_common/minimize.sh" + ], + "type": "shell" + } + ], + "variables": { + "box_basename": "osm-7.0.1", + "build_directory": "../../builds", + "http_directory": "{{template_dir}}/http", + "build_timestamp": "{{isotime \"20060102150405\"}}", + "cpus": "1", + "disk_size": "65536", + "git_revision": "__unknown_git_revision__", + "headless": "", + "http_proxy": "{{env `http_proxy`}}", + "https_proxy": "{{env `https_proxy`}}", + "hyperv_generation": "2", + "openstack_internal_net": "{{env `NETWORK_ID`}}", + "openstack_floating_net": "{{env `VIM_EXT_NET`}}", + "openstack_flavor": "{{env `FLAVOR_NAME`}}", + "openstack_image": "{{env `SOURCE_IMAGE_NAME`}}", + "guest_additions_url": "", + "iso_checksum": "e2ecdace33c939527cbc9e8d23576381c493b071107207d2040af72595f8990b", + "iso_checksum_type": "sha256", + "iso_name": "ubuntu-18.04.4-server-amd64.iso", + "memory": "6144", + "mirror": "http://cdimage.ubuntu.com", + "mirror_directory": "ubuntu/releases/18.04.4/release", + "name": "osm-7.0.1", + "no_proxy": "{{env `no_proxy`}}", + "preseed_path": "preseed.cfg", + "template": "osm-7.0.1-amd64", + "state_folder": "/etc/osm", + "version": "TIMESTAMP" + } +} diff --git a/packer/packer_templates/osm/scripts/cleanup.sh b/packer/packer_templates/osm/scripts/cleanup.sh new file mode 100644 index 00000000..477eb831 --- /dev/null +++ b/packer/packer_templates/osm/scripts/cleanup.sh @@ -0,0 +1,93 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Delete all Linux headers +dpkg --list \ + | awk '{ print $2 }' \ + | grep 'linux-headers' \ + | xargs apt-get -y purge; + +# Remove specific Linux kernels, such as linux-image-3.11.0-15-generic but +# keeps the current kernel and does not touch the virtual packages, +# e.g. 'linux-image-generic', etc. +dpkg --list \ + | awk '{ print $2 }' \ + | grep 'linux-image-.*-generic' \ + | grep -v `uname -r` \ + | xargs apt-get -y purge; + +# Delete Linux source +dpkg --list \ + | awk '{ print $2 }' \ + | grep linux-source \ + | xargs apt-get -y purge; + +# Delete development packages +dpkg --list \ + | awk '{ print $2 }' \ + | grep -- '-dev$' \ + | xargs apt-get -y purge; + +# delete docs packages +dpkg --list \ + | awk '{ print $2 }' \ + | grep -- '-doc$' \ + | xargs apt-get -y purge; + +# Delete X11 libraries +apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6; + +# Delete obsolete networking +apt-get -y purge ppp pppconfig pppoeconf; + +# Delete oddities +apt-get -y purge popularity-contest installation-report command-not-found friendly-recovery bash-completion fonts-ubuntu-font-family-console laptop-detect; + +# 19.10+ don't have this package so fail gracefully +apt-get -y purge command-not-found-data || true; + +# Exlude the files we don't need w/o uninstalling linux-firmware +echo "==> Setup dpkg excludes for linux-firmware" +cat <<_EOF_ | cat >> /etc/dpkg/dpkg.cfg.d/excludes +#BEGIN +path-exclude=/lib/firmware/* +path-exclude=/usr/share/doc/linux-firmware/* +#END +_EOF_ + +# Delete the massive firmware packages +rm -rf /lib/firmware/* +rm -rf /usr/share/doc/linux-firmware/* + +apt-get -y autoremove; +apt-get -y clean; + +# Remove docs +rm -rf /usr/share/doc/* + +# Remove caches +find /var/cache -type f -exec rm -rf {} \; + +# truncate any logs that have built up during the install +find /var/log -type f -exec truncate --size=0 {} \; + +# Blank netplan machine-id (DUID) so machines get unique ID generated on boot. +truncate -s 0 /etc/machine-id + +# remove the contents of /tmp and /var/tmp +rm -rf /tmp/* /var/tmp/* + +# clear the history so our install isn't there +export HISTSIZE=0 +rm -f /root/.wget-hsts \ No newline at end of file diff --git a/packer/packer_templates/osm/scripts/hyperv.sh b/packer/packer_templates/osm/scripts/hyperv.sh new file mode 100644 index 00000000..53e4752e --- /dev/null +++ b/packer/packer_templates/osm/scripts/hyperv.sh @@ -0,0 +1,25 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ubuntu_version="`lsb_release -r | awk '{print $2}'`"; +major_version="`echo $ubuntu_version | awk -F. '{print $1}'`"; + +case "$PACKER_BUILDER_TYPE" in +hyperv-iso) + if [ "$major_version" -eq "16" ]; then + apt-get install -y linux-tools-virtual-lts-xenial linux-cloud-tools-virtual-lts-xenial; + else + apt-get -y install linux-image-virtual linux-tools-virtual linux-cloud-tools-virtual; + fi +esac diff --git a/packer/packer_templates/osm/scripts/install_osm.sh b/packer/packer_templates/osm/scripts/install_osm.sh new file mode 100644 index 00000000..b9024e8a --- /dev/null +++ b/packer/packer_templates/osm/scripts/install_osm.sh @@ -0,0 +1,164 @@ +#!/bin/bash +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +REPOSITORY_BASE=https://osm-download.etsi.org/repository/osm/debian +RELEASE=ReleaseSEVEN +REPOSITORY=stable +DOCKER_TAG=7 + +function usage(){ + echo -e "usage: $0 [OPTIONS]" + echo -e "Install OSM from binaries or source code (by default, from binaries)" + echo -e " OPTIONS" + echo -e " -r : use specified repository name for osm packages" + echo -e " -R : use specified release for osm binaries (deb packages, lxd images, ...)" + echo -e " -u : use specified repository url for osm packages" + echo -e " -k : use specified repository public key url" + echo -e " -b : install OSM from source code using a specific branch (master, v2.0, ...) or tag" + echo -e " -b master (main dev branch)" + echo -e " -b v2.0 (v2.0 branch)" + echo -e " -b tags/v1.1.0 (a specific tag)" + echo -e " ..." + echo -e " -s user defined stack name, default is osm" + echo -e " -H use specific juju host controller IP" + echo -e " -S use VCA/juju secret key" + echo -e " -P use VCA/juju public key file" + echo -e " -C use VCA/juju CA certificate file" + echo -e " -A use VCA/juju API proxy" + echo -e " --vimemu: additionally deploy the VIM emulator as a docker container" + echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging" + echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)" + echo -e " -m : install OSM but only rebuild the specified docker images (LW-UI, NBI, LCM, RO, MON, POL, KAFKA, MONGO, PROMETHEUS, KEYSTONE-DB, NONE)" + echo -e " -o : ONLY (un)installs one of the addons (vimemu, elk_stack, pm_stack)" + echo -e " -D use local devops installation path" + echo -e " -w Location to store runtime installation" + echo -e " -t specify osm docker tag (default is latest)" + echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)" + echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)" + echo -e " --nojuju: do not juju, assumes already installed" + echo -e " --nodockerbuild:do not build docker images (use existing locally cached images)" + echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)" + echo -e " --nohostclient: do not install the osmclient" + echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" + echo -e " --source: install OSM from source code using the latest stable tag" + echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch" + echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)" + echo -e " --lxdimages: (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch" + echo -e " --pullimages: pull/run osm images from docker.io/opensourcemano" + echo -e " -l : (only for Rel THREE with --soui) use specified repository url for lxd images" + echo -e " -p : (only for Rel THREE with --soui) use specified repository path for lxd images" + echo -e " --nat: (only for Rel THREE with --soui) install only NAT rules" + echo -e " --noconfigure: (only for Rel THREE with --soui) DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules" + echo -e " --showopts: print chosen options and exit (only for debugging)" + #echo -e " --clean_volumes To clear all the mounted volumes from docker swarm" + echo -e " -y: do not prompt for confirmation, assumes yes" + echo -e " -h / --help: print this help" +} + +add_repo() { + REPO_CHECK="^$1" + grep "${REPO_CHECK/\[arch=amd64\]/\\[arch=amd64\\]}" /etc/apt/sources.list > /dev/null 2>&1 + if [ $? -ne 0 ] + then + need_packages_lw="software-properties-common apt-transport-https" + echo -e "Checking required packages: $need_packages_lw" + dpkg -l $need_packages_lw &>/dev/null \ + || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \ + || sudo apt-get -q update \ + || ! echo "failed to run apt-get update" \ + || exit 1 + dpkg -l $need_packages_lw &>/dev/null \ + || ! echo -e "Installing $need_packages_lw requires root privileges." \ + || sudo apt-get install -y $need_packages_lw \ + || ! echo "failed to install $need_packages_lw" \ + || exit 1 + wget -qO - $REPOSITORY_BASE/$RELEASE/OSM%20ETSI%20Release%20Key.gpg | sudo apt-key add - + sudo DEBIAN_FRONTEND=noninteractive add-apt-repository -y "$1" && sudo DEBIAN_FRONTEND=noninteractive apt-get update + return 0 + fi + + return 1 +} + +clean_old_repo() { +dpkg -s 'osm-devops' &> /dev/null +if [ $? -eq 0 ]; then + # Clean the previous repos that might exist + sudo sed -i "/osm-download.etsi.org/d" /etc/apt/sources.list +fi +} + +while getopts ":b:r:c:k:u:R:l:p:D:o:m:H:S:s:w:t:U:P:A:-: hy" o; do + case "${o}" in + r) + REPOSITORY="${OPTARG}" + ;; + R) + RELEASE="${OPTARG}" + ;; + u) + REPOSITORY_BASE="${OPTARG}" + ;; + t) + DOCKER_TAG="${OPTARG}" + ;; + -) + [ "${OPTARG}" == "help" ] && usage && exit 0 + ;; + :) + echo "Option -$OPTARG requires an argument" >&2 + usage && exit 1 + ;; + \?) + echo -e "Invalid option: '-$OPTARG'\n" >&2 + usage && exit 1 + ;; + h) + usage && exit 0 + ;; + *) + ;; + esac +done + +clean_old_repo + +add_repo "deb [arch=amd64] $REPOSITORY_BASE/$RELEASE $REPOSITORY devops" +sudo DEBIAN_FRONTEND=noninteractive apt-get -q update +sudo DEBIAN_FRONTEND=noninteractive apt-get install osm-devops +#FIXME: sudo DEBIAN_FRONTEND=noninteractive apt-get install -y osm-devops + +#--- FIXME: Workaround until patch for unattended install comes with default installer +sudo wget -O /usr/share/osm-devops/installers/full_install_osm.sh "https://osm.etsi.org/gitweb/?p=osm/devops.git;a=blob_plain;f=installers/full_install_osm.sh;hb=4205c192a9b6c2e30459987491e02a44ca3695d6" +sudo chmod +x /usr/share/osm-devops/installers/full_install_osm.sh +#--- End of workaround + +/usr/share/osm-devops/installers/full_install_osm.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D /usr/share/osm-devops -t $DOCKER_TAG "$@" + +############################################ +# OSM Install without workarounds +############################################ +#wget https://osm-download.etsi.org/ftp/osm-7.0-seven/install_osm.sh +#chmod +x install_osm.sh +##./install_osm.sh -c k8s --k8s_monitor --elk_stack 2>&1 | tee osm_install_log.txt +##./install_osm.sh -c k8s --k8s_monitor 2>&1 | tee osm_install_log.txt +#./install_osm.sh 2>&1 | tee osm_install_log.txt +############################################ + +# Saves the IP address used during install, in case the VM needed to be reinstantiated later with a different IP address +sudo mkdir -p ${STATE_FOLDER} +sudo chmod a+r ${STATE_FOLDER} +DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8}') +DEFAULT_IP=$(ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}') +sudo su - -c "echo ${DEFAULT_IP} > ${STATE_FOLDER}/oldIPaddress.txt" diff --git a/packer/packer_templates/osm/scripts/networking.sh b/packer/packer_templates/osm/scripts/networking.sh new file mode 100644 index 00000000..05f574fb --- /dev/null +++ b/packer/packer_templates/osm/scripts/networking.sh @@ -0,0 +1,37 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ubuntu_version="`lsb_release -r | awk '{print $2}'`"; +major_version="`echo $ubuntu_version | awk -F. '{print $1}'`"; + +if [ "$major_version" -ge "18" ]; then +echo "Create netplan config for eth0" +cat </etc/netplan/01-netcfg.yaml; +network: + version: 2 + ethernets: + eth0: + dhcp4: true +EOF +else + # Adding a 2 sec delay to the interface up, to make the dhclient happy + echo "pre-up sleep 2" >> /etc/network/interfaces; +fi + +if [ "$major_version" -ge "16" ]; then + # Disable Predictable Network Interface names and use eth0 + sed -i 's/en[[:alnum:]]*/eth0/g' /etc/network/interfaces; + sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 \1"/g' /etc/default/grub; + update-grub; +fi diff --git a/packer/packer_templates/osm/scripts/sudoers.sh b/packer/packer_templates/osm/scripts/sudoers.sh new file mode 100644 index 00000000..4600fbb3 --- /dev/null +++ b/packer/packer_templates/osm/scripts/sudoers.sh @@ -0,0 +1,19 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=sudo' /etc/sudoers; + +# Set up password-less sudo for the vagrant user +echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/99_vagrant; +chmod 440 /etc/sudoers.d/99_vagrant; diff --git a/packer/packer_templates/osm/scripts/update.sh b/packer/packer_templates/osm/scripts/update.sh new file mode 100644 index 00000000..457ed1c4 --- /dev/null +++ b/packer/packer_templates/osm/scripts/update.sh @@ -0,0 +1,56 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +export DEBIAN_FRONTEND=noninteractive + +ubuntu_version="`lsb_release -r | awk '{print $2}'`"; +major_version="`echo $ubuntu_version | awk -F. '{print $1}'`"; + +# Disable release-upgrades +sed -i.bak 's/^Prompt=.*$/Prompt=never/' /etc/update-manager/release-upgrades; + +# Disable systemd apt timers/services +if [ "$major_version" -ge "16" ]; then + systemctl stop apt-daily.timer; + systemctl stop apt-daily-upgrade.timer; + systemctl disable apt-daily.timer; + systemctl disable apt-daily-upgrade.timer; + systemctl mask apt-daily.service; + systemctl mask apt-daily-upgrade.service; + systemctl daemon-reload; +fi + +# Disable periodic activities of apt to be safe +cat </etc/apt/apt.conf.d/10periodic; +APT::Periodic::Enable "0"; +APT::Periodic::Update-Package-Lists "0"; +APT::Periodic::Download-Upgradeable-Packages "0"; +APT::Periodic::AutocleanInterval "0"; +APT::Periodic::Unattended-Upgrade "0"; +EOF + +# Clean and nuke the package from orbit +rm -rf /var/log/unattended-upgrades; +apt-get -y purge unattended-upgrades; + +# Update the package list +apt-get -y update; + +# Upgrade all installed packages +#DEBIAN_FRONTEND=noninteractive sudo apt-get -y upgrade; + +# Upgrade all installed packages incl. kernel and kernel headers +apt-get -y dist-upgrade -o Dpkg::Options::="--force-confnew"; + +reboot diff --git a/packer/packer_templates/osm/scripts/update_osm_info_docker.sh b/packer/packer_templates/osm/scripts/update_osm_info_docker.sh new file mode 100644 index 00000000..69f2de48 --- /dev/null +++ b/packer/packer_templates/osm/scripts/update_osm_info_docker.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function usage(){ + echo -e "usage: $0 (OPTIONS)" + echo -e "Replaces original host IP address (typically saved at /home/vagrant/oldIPaddress.txt) where VCA listens in OSM configuration by a new one. Also used by docker swarm." + echo -e " OPTIONS" + echo -e " -n : new host ip address (default: current IP address)" + echo -e " -o : old host ip address during initial install (default: content of /etc/osm/oldIPaddress.txt)" + echo -e " -h / --help: print this help" +} + +while getopts ":n:o:-:h" o; do + case "${o}" in + n) + CURRENT_IP_ADDRESS="${OPTARG}" + ;; + o) + OLD_IP_ADDRESS="${OPTARG}" + ;; + -) + [ "${OPTARG}" == "help" ] && usage && exit 0 + ;; + :) + echo "Option -$OPTARG ip address required" >&2 + usage && exit 1 + ;; + \?) + echo -e "Invalid option: '-$OPTARG'\n" >&2 + usage && exit 1 + ;; + h) + usage && exit 0 + ;; + *) + usage && exit 1 + ;; + esac +done + +if [ -z "$CURRENT_IP_ADDRESS" ] +then + DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8}') + CURRENT_IP_ADDRESS=$(ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}') +fi +[ -z "$OLD_IP_ADDRESS" ] && OLD_IP_ADDRESS=$(cat /etc/osm/oldIPaddress.txt) + +VCA_HOST=$(cat /etc/osm/docker/lcm.env | grep OSMLCM_VCA_HOST | cut -f2 -d=) + +sudo sed -i "s/$OLD_IP_ADDRESS/$CURRENT_IP_ADDRESS/g" /etc/osm/docker/lcm.env +sudo sed -i "s/$OLD_IP_ADDRESS/$CURRENT_IP_ADDRESS/g" /etc/osm/docker/mon.env +docker stack rm osm +sleep 20 + +# Clean previous ip address info from Docker Swarm and reinitialize +docker swarm leave --force +docker swarm init --advertise-addr $CURRENT_IP_ADDRESS +sudo systemctl restart docker +docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=1500 netosm + +# Deploy docker stack +source /etc/osm/docker/osm_ports.sh +docker stack deploy -c /etc/osm/docker/docker-compose.yaml osm + +sudo iptables -t nat -D PREROUTING -p tcp -m tcp -d $OLD_IP_ADDRESS --dport 17070 -j DNAT --to-destination $VCA_HOST +sudo iptables -t nat -A PREROUTING -p tcp -m tcp -d $CURRENT_IP_ADDRESS --dport 17070 -j DNAT --to-destination $VCA_HOST + +echo "[DONE]" diff --git a/packer/packer_templates/osm/scripts/vagrant.sh b/packer/packer_templates/osm/scripts/vagrant.sh new file mode 100644 index 00000000..9154a37c --- /dev/null +++ b/packer/packer_templates/osm/scripts/vagrant.sh @@ -0,0 +1,26 @@ +#!/bin/bash -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +pubkey_url="https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub"; +mkdir -p $HOME_DIR/.ssh; +if command -v wget >/dev/null 2>&1; then + wget --no-check-certificate "$pubkey_url" -O $HOME_DIR/.ssh/authorized_keys; +elif command -v curl >/dev/null 2>&1; then + curl --insecure --location "$pubkey_url" > $HOME_DIR/.ssh/authorized_keys; +else + echo "Cannot download vagrant public key"; + exit 1; +fi +chown -R vagrant $HOME_DIR/.ssh; +chmod -R go-rwsx $HOME_DIR/.ssh; diff --git a/packer/packer_templates/osm/scripts/vmware.sh b/packer/packer_templates/osm/scripts/vmware.sh new file mode 100644 index 00000000..4e7aaaf4 --- /dev/null +++ b/packer/packer_templates/osm/scripts/vmware.sh @@ -0,0 +1,22 @@ +#!/bin/sh -eux + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +case "$PACKER_BUILDER_TYPE" in +vmware-iso|vmware-vmx) + apt-get install -y open-vm-tools; + mkdir /mnt/hgfs; + systemctl enable open-vm-tools + systemctl start open-vm-tools + echo "platform specific vmware.sh executed"; +esac diff --git a/packer/scripts/cleanup.sh b/packer/scripts/cleanup.sh deleted file mode 100644 index cc09a976..00000000 --- a/packer/scripts/cleanup.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -apt autoremove -apt update - -rm -f /home/vagrant/*.sh - -wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys -chmod 0600 /home/vagrant/.ssh/authorized_keys -chown -R vagrant:vagrant /home/vagrant/.ssh - -dd if=/dev/zero of=/EMPTY bs=1M -rm -f /EMPTY -sync diff --git a/packer/scripts/get-install-osm.sh b/packer/scripts/get-install-osm.sh deleted file mode 100755 index 04b107c7..00000000 --- a/packer/scripts/get-install-osm.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -export PATH=$PATH:/snap/bin -echo "PATH=$PATH" -juju status - -wget https://osm-download.etsi.org/ftp/osm-5.0-five/install_osm.sh -chmod +x install_osm.sh -./install_osm.sh --nolxd --nojuju -y - -cat >> ~/.bashrc <<-EOF -export OSM_HOSTNAME=127.0.0.1 -export OSM_SOL005=True - -EOF diff --git a/packer/scripts/install_packages.sh b/packer/scripts/install_packages.sh deleted file mode 100644 index 36445197..00000000 --- a/packer/scripts/install_packages.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -sudo apt -y update && apt-get -y upgrade -sudo apt -y install git wget curl vim snapd lxd software-properties-common -sudo apt-get install -y apt-transport-https ca-certificates -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -sudo apt-get -qq update -sudo apt-get install -y docker-ce -sudo groupadd -f docker -sudo usermod -aG docker $USER diff --git a/packer/scripts/juju-setup.sh b/packer/scripts/juju-setup.sh deleted file mode 100755 index 8685b48f..00000000 --- a/packer/scripts/juju-setup.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -sudo snap install juju --classic -/snap/bin/juju bootstrap --bootstrap-series=xenial localhost osm diff --git a/packer/scripts/lxd-setup.sh b/packer/scripts/lxd-setup.sh deleted file mode 100644 index a92dd170..00000000 --- a/packer/scripts/lxd-setup.sh +++ /dev/null @@ -1,10 +0,0 @@ -sudo lxd init --auto --storage-backend zfs --storage-pool lxdpool --storage-create-loop 20 - -sudo systemctl stop lxd-bridge -sudo systemctl --system daemon-reload - -sudo cp -f /tmp/lxd-bridge /etc/default/lxd-bridge -sudo systemctl enable lxd-bridge -sudo systemctl start lxd-bridge - -sudo usermod -a -G lxd $(whoami) diff --git a/packer/scripts/setup.sh b/packer/scripts/setup.sh deleted file mode 100644 index de27aa72..00000000 --- a/packer/scripts/setup.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers -sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers -echo 'APT::Periodic::Enable "0";' >> /etc/apt/apt.conf.d/10periodic diff --git a/packer/vagrant_tests/Vagrantfile b/packer/vagrant_tests/Vagrantfile new file mode 100644 index 00000000..b75a23ae --- /dev/null +++ b/packer/vagrant_tests/Vagrantfile @@ -0,0 +1,38 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +Vagrant.configure("2") do |config| + required_plugins = %w( vagrant-vbguest vagrant-disksize ) + _retry = false + required_plugins.each do |plugin| + unless Vagrant.has_plugin? plugin + system "vagrant plugin install #{plugin}" + _retry=true + end + end + if (_retry) + exec "vagrant " + ARGV.join(' ') + end + config.disksize.size = "40GB" + config.vm.box = "osm/osm-rel7" + config.vm.network "forwarded_port", guest: 80, host: 8080 + config.vm.provider "virtualbox" do |vb| + vb.memory = "6144" + vb.cpus = 2 + end + config.vm.provision "shell", name: "Post-provisión", privileged: false, inline: <<-SHELL + /etc/osm/update_osm_info_docker.sh # Updates IP address for Docker Swarm + SHELL +end diff --git a/packer/vagrant_tests/Vagrantfile - Commented b/packer/vagrant_tests/Vagrantfile - Commented new file mode 100644 index 00000000..ebf174d7 --- /dev/null +++ b/packer/vagrant_tests/Vagrantfile - Commented @@ -0,0 +1,106 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # Installs necessary plugins, if available + required_plugins = %w( vagrant-vbguest vagrant-disksize ) + _retry = false + required_plugins.each do |plugin| + unless Vagrant.has_plugin? plugin + system "vagrant plugin install #{plugin}" + _retry=true + end + end + + if (_retry) + exec "vagrant " + ARGV.join(' ') + end + + # 40 GB HDD + config.disksize.size = "40GB" + + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.box = "osm/osm-rel7" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + vb.memory = "6144" + vb.cpus = 2 + end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + # config.vm.provision "shell", inline: <<-SHELL + # apt-get update + # apt-get install -y apache2 + # SHELL + config.vm.provision "shell", name: "Post-provisión", privileged: false, inline: <<-SHELL + # Updates the IP address used by Docker Swarm + /etc/osm/update_osm_info_docker.sh + SHELL + +end -- 2.17.1