From b12baea32034b77b0dfeff46754bc770ab98769f Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Wed, 1 Jul 2020 18:34:36 +0300 Subject: [PATCH 1/9] change installation method --- .../linux/scripts/installers/aws-sam-cli.sh | 20 +++++++++++++--- images/linux/ubuntu1604.json | 24 +++++++++---------- images/linux/ubuntu1804.json | 23 +++++++++--------- images/linux/ubuntu2004.json | 24 +++++++++---------- 4 files changed, 52 insertions(+), 39 deletions(-) diff --git a/images/linux/scripts/installers/aws-sam-cli.sh b/images/linux/scripts/installers/aws-sam-cli.sh index 3cee6015..cac4cb43 100644 --- a/images/linux/scripts/installers/aws-sam-cli.sh +++ b/images/linux/scripts/installers/aws-sam-cli.sh @@ -2,15 +2,29 @@ ################################################################################ ## File: aws-sam-cli.sh ## Desc: Installs AWS SAM CLI -## Must be run as non-root user after homebrew and clang +## Must be run after toolset installation ################################################################################ # Source the helpers for use with the script source $HELPER_SCRIPTS/document.sh # Install aws sam cli -brew tap aws/tap -brew install aws-sam-cli +TarballUrl=$(curl -s https://api.github.com/repos/awslabs/aws-sam-cli/releases/latest | jq -r '.tarball_url') +TarballPath="/tmp/aws-sam-cli.tar.gz" +wget $TarballUrl -O $TarballPath +tar -xzvf $TarballPath -C /tmp +cd /tmp/awslabs-aws-sam-cli* +# Use python 3.7 from toolcache to install aws sam, setuptools module required for the installation +Python3Dir=$(echo ${AGENT_TOOLSDIRECTORY}/Python/3.7*/x64) +Python3BinDir=$(echo ${Python3Dir}/bin) +export PATH="$Python3Dir:$Python3BinDir:$PATH" +python3 -m pip install setuptools +python3 setup.py install +sudo ln -sf ${Python3BinDir}/sam /usr/local/bin/sam + +# Cleanup downloaded files +rm -rf $TarballPath +rm -rf /tmp/awslabs-aws-sam-cli* # Run tests to determine that the software installed as expected echo "Testing to make sure that script performed as expected, and basic scenarios work" diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 66184753..60aa3714 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -233,18 +233,6 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, - { - "type": "shell", - "scripts": [ - "{{template_dir}}/scripts/installers/aws-sam-cli.sh" - ], - "environment_vars": [ - "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "DEBIAN_FRONTEND=noninteractive" - ], - "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" - }, { "type": "file", "source": "{{template_dir}}/toolsets/toolcache-1604.json", @@ -288,6 +276,18 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" }, + { + "type": "shell", + "scripts": [ + "{{template_dir}}/scripts/installers/aws-sam-cli.sh" + ], + "environment_vars": [ + "METADATA_FILE={{user `metadata_file`}}", + "HELPER_SCRIPTS={{user `helper_script_folder`}}", + "DEBIAN_FRONTEND=noninteractive" + ], + "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" + }, { "type": "shell", "scripts":[ diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index 41cc8c52..8a2a1257 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -237,18 +237,6 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, - { - "type": "shell", - "scripts": [ - "{{template_dir}}/scripts/installers/aws-sam-cli.sh" - ], - "environment_vars": [ - "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "DEBIAN_FRONTEND=noninteractive" - ], - "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" - }, { "type": "file", "source": "{{template_dir}}/toolsets/toolcache-1804.json", @@ -292,6 +280,17 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" }, + { + "type": "shell", + "scripts": [ + "{{template_dir}}/scripts/installers/aws-sam-cli.sh" + ], + "environment_vars": [ + "METADATA_FILE={{user `metadata_file`}}", + "HELPER_SCRIPTS={{user `helper_script_folder`}}" + ], + "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" + }, { "type": "shell", "scripts":[ diff --git a/images/linux/ubuntu2004.json b/images/linux/ubuntu2004.json index 611fdc6b..436c7c04 100644 --- a/images/linux/ubuntu2004.json +++ b/images/linux/ubuntu2004.json @@ -238,18 +238,6 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, - { - "type": "shell", - "scripts": [ - "{{template_dir}}/scripts/installers/aws-sam-cli.sh" - ], - "environment_vars": [ - "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "DEBIAN_FRONTEND=noninteractive" - ], - "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" - }, { "type": "file", "source": "{{template_dir}}/toolsets/toolcache-2004.json", @@ -293,6 +281,18 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" }, + { + "type": "shell", + "scripts": [ + "{{template_dir}}/scripts/installers/aws-sam-cli.sh" + ], + "environment_vars": [ + "METADATA_FILE={{user `metadata_file`}}", + "HELPER_SCRIPTS={{user `helper_script_folder`}}", + "DEBIAN_FRONTEND=noninteractive" + ], + "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" + }, { "type": "shell", "scripts":[ From 9de5dfef44017c6c7ca12e2254c9978073546df5 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 2 Jul 2020 11:11:56 +0300 Subject: [PATCH 2/9] pretify script a bit --- images/linux/scripts/installers/aws-sam-cli.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/images/linux/scripts/installers/aws-sam-cli.sh b/images/linux/scripts/installers/aws-sam-cli.sh index cac4cb43..62fb0b10 100644 --- a/images/linux/scripts/installers/aws-sam-cli.sh +++ b/images/linux/scripts/installers/aws-sam-cli.sh @@ -2,29 +2,31 @@ ################################################################################ ## File: aws-sam-cli.sh ## Desc: Installs AWS SAM CLI -## Must be run after toolset installation +## Requires Pyton >=3.6, must be run after toolset installation ################################################################################ # Source the helpers for use with the script source $HELPER_SCRIPTS/document.sh -# Install aws sam cli +# Download latest aws sam cli sources TarballUrl=$(curl -s https://api.github.com/repos/awslabs/aws-sam-cli/releases/latest | jq -r '.tarball_url') TarballPath="/tmp/aws-sam-cli.tar.gz" wget $TarballUrl -O $TarballPath tar -xzvf $TarballPath -C /tmp -cd /tmp/awslabs-aws-sam-cli* +SourcesDir=$(echo /tmp/awslabs-aws-sam-cli*) + # Use python 3.7 from toolcache to install aws sam, setuptools module required for the installation Python3Dir=$(echo ${AGENT_TOOLSDIRECTORY}/Python/3.7*/x64) Python3BinDir=$(echo ${Python3Dir}/bin) export PATH="$Python3Dir:$Python3BinDir:$PATH" python3 -m pip install setuptools +cd $SourcesDir python3 setup.py install sudo ln -sf ${Python3BinDir}/sam /usr/local/bin/sam # Cleanup downloaded files rm -rf $TarballPath -rm -rf /tmp/awslabs-aws-sam-cli* +rm -rf $SourcesDir # Run tests to determine that the software installed as expected echo "Testing to make sure that script performed as expected, and basic scenarios work" From 1a582d083687001e362bf498f14a8e0fb86cc679 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 2 Jul 2020 11:22:58 +0300 Subject: [PATCH 3/9] change description and comments --- images/linux/scripts/installers/aws-sam-cli.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/linux/scripts/installers/aws-sam-cli.sh b/images/linux/scripts/installers/aws-sam-cli.sh index 62fb0b10..08063f4e 100644 --- a/images/linux/scripts/installers/aws-sam-cli.sh +++ b/images/linux/scripts/installers/aws-sam-cli.sh @@ -2,7 +2,7 @@ ################################################################################ ## File: aws-sam-cli.sh ## Desc: Installs AWS SAM CLI -## Requires Pyton >=3.6, must be run after toolset installation +## Requires Pyton >=3.6, must be run as non-root user after toolset installation ################################################################################ # Source the helpers for use with the script @@ -15,7 +15,7 @@ wget $TarballUrl -O $TarballPath tar -xzvf $TarballPath -C /tmp SourcesDir=$(echo /tmp/awslabs-aws-sam-cli*) -# Use python 3.7 from toolcache to install aws sam, setuptools module required for the installation +# Use python 3.7 from toolcache to install aws sam, setuptools package required for the installation Python3Dir=$(echo ${AGENT_TOOLSDIRECTORY}/Python/3.7*/x64) Python3BinDir=$(echo ${Python3Dir}/bin) export PATH="$Python3Dir:$Python3BinDir:$PATH" From 501633334393fb337b60371fdb8afd6e454d9d67 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 2 Jul 2020 11:35:06 +0300 Subject: [PATCH 4/9] remove not needed setting from ub20 template --- images/linux/ubuntu2004.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/images/linux/ubuntu2004.json b/images/linux/ubuntu2004.json index 436c7c04..eb958327 100644 --- a/images/linux/ubuntu2004.json +++ b/images/linux/ubuntu2004.json @@ -288,8 +288,7 @@ ], "environment_vars": [ "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "DEBIAN_FRONTEND=noninteractive" + "HELPER_SCRIPTS={{user `helper_script_folder`}}" ], "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" }, From 35f0938464199feeb1ba688dda2046ff4e3484e4 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 2 Jul 2020 11:59:16 +0300 Subject: [PATCH 5/9] remove setting from 16.04 template --- images/linux/ubuntu1604.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 60aa3714..33c29cc4 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -283,8 +283,7 @@ ], "environment_vars": [ "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "DEBIAN_FRONTEND=noninteractive" + "HELPER_SCRIPTS={{user `helper_script_folder`}}" ], "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" }, From ef11240bbdde6a5e463fb906241ccd04c04c5472 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 2 Jul 2020 12:00:16 +0300 Subject: [PATCH 6/9] simplify variable --- images/linux/scripts/installers/aws-sam-cli.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/linux/scripts/installers/aws-sam-cli.sh b/images/linux/scripts/installers/aws-sam-cli.sh index 08063f4e..4b80a316 100644 --- a/images/linux/scripts/installers/aws-sam-cli.sh +++ b/images/linux/scripts/installers/aws-sam-cli.sh @@ -17,7 +17,7 @@ SourcesDir=$(echo /tmp/awslabs-aws-sam-cli*) # Use python 3.7 from toolcache to install aws sam, setuptools package required for the installation Python3Dir=$(echo ${AGENT_TOOLSDIRECTORY}/Python/3.7*/x64) -Python3BinDir=$(echo ${Python3Dir}/bin) +Python3BinDir="${Python3Dir}/bin" export PATH="$Python3Dir:$Python3BinDir:$PATH" python3 -m pip install setuptools cd $SourcesDir From b46e9c7adb8f7a466bd22b4afb84aa50dd70ffdd Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 2 Jul 2020 12:13:44 +0300 Subject: [PATCH 7/9] remove SourcesDir variable --- images/linux/scripts/installers/aws-sam-cli.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/images/linux/scripts/installers/aws-sam-cli.sh b/images/linux/scripts/installers/aws-sam-cli.sh index 4b80a316..5fb7ee59 100644 --- a/images/linux/scripts/installers/aws-sam-cli.sh +++ b/images/linux/scripts/installers/aws-sam-cli.sh @@ -13,20 +13,19 @@ TarballUrl=$(curl -s https://api.github.com/repos/awslabs/aws-sam-cli/releases/l TarballPath="/tmp/aws-sam-cli.tar.gz" wget $TarballUrl -O $TarballPath tar -xzvf $TarballPath -C /tmp -SourcesDir=$(echo /tmp/awslabs-aws-sam-cli*) +cd /tmp/awslabs-aws-sam-cli* # Use python 3.7 from toolcache to install aws sam, setuptools package required for the installation Python3Dir=$(echo ${AGENT_TOOLSDIRECTORY}/Python/3.7*/x64) Python3BinDir="${Python3Dir}/bin" export PATH="$Python3Dir:$Python3BinDir:$PATH" python3 -m pip install setuptools -cd $SourcesDir python3 setup.py install sudo ln -sf ${Python3BinDir}/sam /usr/local/bin/sam # Cleanup downloaded files rm -rf $TarballPath -rm -rf $SourcesDir +rm -rf /tmp/awslabs-aws-sam-cli* # Run tests to determine that the software installed as expected echo "Testing to make sure that script performed as expected, and basic scenarios work" From ec297381e7a70f77783603eae9e9d63885c01b52 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 2 Jul 2020 12:15:03 +0300 Subject: [PATCH 8/9] remove cleanup --- images/linux/scripts/installers/aws-sam-cli.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/images/linux/scripts/installers/aws-sam-cli.sh b/images/linux/scripts/installers/aws-sam-cli.sh index 5fb7ee59..bd689fd0 100644 --- a/images/linux/scripts/installers/aws-sam-cli.sh +++ b/images/linux/scripts/installers/aws-sam-cli.sh @@ -23,10 +23,6 @@ python3 -m pip install setuptools python3 setup.py install sudo ln -sf ${Python3BinDir}/sam /usr/local/bin/sam -# Cleanup downloaded files -rm -rf $TarballPath -rm -rf /tmp/awslabs-aws-sam-cli* - # 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 ! sam --version; then From abf21e68d5a1bc8e87fc51af483e9c17bdbe1608 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 2 Jul 2020 13:41:14 +0300 Subject: [PATCH 9/9] fix typo in the description --- images/linux/scripts/installers/aws-sam-cli.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/linux/scripts/installers/aws-sam-cli.sh b/images/linux/scripts/installers/aws-sam-cli.sh index bd689fd0..f86a6871 100644 --- a/images/linux/scripts/installers/aws-sam-cli.sh +++ b/images/linux/scripts/installers/aws-sam-cli.sh @@ -2,7 +2,7 @@ ################################################################################ ## File: aws-sam-cli.sh ## Desc: Installs AWS SAM CLI -## Requires Pyton >=3.6, must be run as non-root user after toolset installation +## Requires Python >=3.6, must be run as non-root user after toolset installation ################################################################################ # Source the helpers for use with the script