From c6bf6c3b7bfd405d3ad1b65c821bf3707f2e9a58 Mon Sep 17 00:00:00 2001 From: Niels <12247711+nielsvbrecht@users.noreply.github.com> Date: Wed, 4 Mar 2020 15:42:36 +0100 Subject: [PATCH] Install packer on build agent - issue #280 (#295) * create packer.sh deployment file Copy from terraform.sh * add packer.sh to provisioner add packer.sh script to provisioner to install packer. * add packer.sh to provisioner Add packer.sh script to provisioner to install packer * remove blank lines removed blank lines as requested in feedback by alepauly. * remove additional blank lines * Add Install-Packer.ps1 This script installs packer on Windows through chocolatey * Create Validate-Packer.ps1 This script validates the installation of Packer from Install-Packer.ps1 and adds the software details to the markdown files. * Add Packer install and validate script Added Packer install script and validate script to provisioners. * Add Packer install script and validation script Add Packer install and validation script to provisioners. --- images/linux/scripts/installers/packer.sh | 25 +++++++++++++++++++ images/linux/ubuntu1604.json | 1 + images/linux/ubuntu1804.json | 1 + images/win/Windows2016-Azure.json | 12 +++++++++ images/win/Windows2019-Azure.json | 12 +++++++++ .../win/scripts/Installers/Install-Packer.ps1 | 6 +++++ .../scripts/Installers/Validate-Packer.ps1 | 24 ++++++++++++++++++ 7 files changed, 81 insertions(+) create mode 100644 images/linux/scripts/installers/packer.sh create mode 100644 images/win/scripts/Installers/Install-Packer.ps1 create mode 100644 images/win/scripts/Installers/Validate-Packer.ps1 diff --git a/images/linux/scripts/installers/packer.sh b/images/linux/scripts/installers/packer.sh new file mode 100644 index 000000000..cba8dfb7b --- /dev/null +++ b/images/linux/scripts/installers/packer.sh @@ -0,0 +1,25 @@ +#!/bin/bash +################################################################################ +## File: packer.sh +## Desc: Installs packer +################################################################################ +# Source the helpers for use with the script +source $HELPER_SCRIPTS/document.sh +source $HELPER_SCRIPTS/apt.sh + +# Install Packer +PACKER_VERSION=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/packer | jq -r .current_version) +curl -LO "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip" +unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d /usr/local/bin +rm -f "packer_${PACKER_VERSION}_linux_amd64.zip" + +# Run tests to determine that the software installed as expected +echo "Testing to make sure that script performed as expected, and basic scenarios work" +if ! command -v packer; then + echo "Packer was not installed or found on PATH" + exit 1 +fi + +# Document what was added to the image +echo "Lastly, documenting what we added to the metadata file" +DocumentInstalledItem "Packer ($(packer --version))" diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 7cedc0c8c..62700c4b9 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -166,6 +166,7 @@ "{{template_dir}}/scripts/installers/sphinx.sh", "{{template_dir}}/scripts/installers/subversion.sh", "{{template_dir}}/scripts/installers/terraform.sh", + "{{template_dir}}/scripts/installers/packer.sh", "{{template_dir}}/scripts/installers/vcpkg.sh", "{{template_dir}}/scripts/installers/zeit-now.sh", "{{template_dir}}/scripts/installers/updatepath.sh", diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index beec3c29f..d825cc858 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -169,6 +169,7 @@ "{{template_dir}}/scripts/installers/sphinx.sh", "{{template_dir}}/scripts/installers/subversion.sh", "{{template_dir}}/scripts/installers/terraform.sh", + "{{template_dir}}/scripts/installers/packer.sh", "{{template_dir}}/scripts/installers/vcpkg.sh", "{{template_dir}}/scripts/installers/zeit-now.sh", "{{template_dir}}/scripts/installers/updatepath.sh", diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index cef6db8db..f5632891c 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -282,6 +282,12 @@ "scripts":[ "{{ template_dir }}/scripts/Installers/Install-7zip.ps1" ] + }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-Packer.ps1" + ] }, { "type": "file", @@ -777,6 +783,12 @@ "{{ template_dir }}/scripts/Installers/Validate-7zip.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-Packer.ps1" + ] + }, { "type": "powershell", "scripts":[ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index f143d07bd..4bf69c257 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -252,6 +252,12 @@ "{{ template_dir }}/scripts/Installers/Install-7zip.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-Packer.ps1" + ] + }, { "type": "file", "source": "{{template_dir}}/toolcache-2019.json", @@ -745,6 +751,12 @@ "scripts":[ "{{ template_dir }}/scripts/Installers/Validate-7zip.ps1" ] + }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-Packer.ps1" + ] }, { "type": "powershell", diff --git a/images/win/scripts/Installers/Install-Packer.ps1 b/images/win/scripts/Installers/Install-Packer.ps1 new file mode 100644 index 000000000..4374175d1 --- /dev/null +++ b/images/win/scripts/Installers/Install-Packer.ps1 @@ -0,0 +1,6 @@ +################################################################################ +## File: Install-Packer.ps1 +## Desc: Install Packer +################################################################################ + +choco install packer -y diff --git a/images/win/scripts/Installers/Validate-Packer.ps1 b/images/win/scripts/Installers/Validate-Packer.ps1 new file mode 100644 index 000000000..250c6f696 --- /dev/null +++ b/images/win/scripts/Installers/Validate-Packer.ps1 @@ -0,0 +1,24 @@ +################################################################################ +## File: Validate-Packer.ps1 +## Desc: Validate Packer +################################################################################ + +if (Get-Command -Name 'packer') +{ + Write-Host "Packer is on path" +} +else +{ + Write-Host 'Packer is not on path' + exit 1 +} + +# Adding description of the software to Markdown +$SoftwareName = "Packer" +$PackerVersion = (packer version).Split("") + +$Description = @" +_Version:_ $PackerVersion.Item(1)
+"@ + +Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description