Skip to content

Commit 65f9b7f

Browse files
Merge pull request #1726 from vsafonkin/v-vlsafo/add-pipx-ubuntu
[ubuntu] Add pipx and install yamllint and aws sam cli through it.
2 parents 1eb7113 + 58cf3bb commit 65f9b7f

9 files changed

+99
-11
lines changed

images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1

+4
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,8 @@ function Get-AptPackages {
245245
$apt = $toolsetJson.apt
246246
$pkgs = ($apt.common_packages + $apt.cmd_packages | Sort-Object) -join ", "
247247
return $pkgs
248+
}
249+
250+
function Get-PipxVersion {
251+
return "Pipx $(pipx --version 2> $null)"
248252
}

images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1

+11-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ $markdown += New-MDList -Style Unordered -Lines @(
5454
)
5555

5656
$markdown += New-MDHeader "Package Management" -Level 3
57-
$markdown += New-MDList -Style Unordered -Lines @(
57+
58+
$packageManagementList = @(
5859
(Get-HomebrewVersion),
5960
(Get-GemVersion),
6061
(Get-MinicondaVersion),
@@ -66,6 +67,14 @@ $markdown += New-MDList -Style Unordered -Lines @(
6667
(Get-VcpkgVersion)
6768
)
6869

70+
if (-not (Test-IsUbuntu16)) {
71+
$packageManagementList += @(
72+
(Get-PipxVersion)
73+
)
74+
}
75+
76+
$markdown += New-MDList -Style Unordered -Lines ($packageManagementList | Sort-Object)
77+
6978
$markdown += New-MDHeader "Project Management" -Level 3
7079
$markdown += New-MDList -Style Unordered -Lines @(
7180
(Get-AntVersion),
@@ -115,6 +124,7 @@ $toolsList = @(
115124
(Get-TerraformVersion),
116125
(Get-UnZipVersion),
117126
(Get-WgetVersion),
127+
(Get-YamllintVersion),
118128
(Get-ZipVersion),
119129
(Get-ZstdVersion)
120130
)

images/linux/scripts/SoftwareReport/SoftwareReport.Tools.psm1

+4
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,8 @@ function Get-RVersion {
275275
function Get-SphinxVersion {
276276
$sphinxVersion = searchd -h | Select-Object -First 1 | Take-OutputPart -Part 1 | Take-OutputPart -Part 0 -Delimiter "-"
277277
return "Sphinx Open Source Search Server $sphinxVersion"
278+
}
279+
280+
function Get-YamllintVersion {
281+
return "$(yamllint --version)"
278282
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
################################################################################
3+
## File: pipx-packages.sh
4+
## Desc: Install tools via pipx
5+
################################################################################
6+
7+
8+
export PATH="$PATH:/opt/pipx_bin"
9+
10+
toolset="$INSTALLER_SCRIPT_FOLDER/toolset.json"
11+
pipx_packages=$(jq -r ".pipx[] .package" $toolset)
12+
13+
for package in $pipx_packages; do
14+
python_version=$(jq -r ".pipx[] | select(.package == \"$package\") .python" $toolset)
15+
if [ "$python_version" != "null" ]; then
16+
python_path="/opt/hostedtoolcache/Python/$python_version*/x64/bin/python$python_version"
17+
echo "Install $package into python $python_path"
18+
pipx install $package --python $python_path
19+
else
20+
echo "Install $package into default python"
21+
pipx install $package
22+
fi
23+
24+
# Run tests to determine that the software installed as expected
25+
cmd=$(jq -r ".pipx[] | select(.package == \"$package\") .cmd" $toolset)
26+
if ! command -v $cmd; then
27+
echo "$package was not installed"
28+
exit 1
29+
fi
30+
done

images/linux/scripts/installers/python.sh

+24-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,40 @@
66

77
set -e
88
# Source the helpers for use with the script
9+
source $HELPER_SCRIPTS/etc-environment.sh
910
source $HELPER_SCRIPTS/os.sh
1011

1112
# Install Python, Python 3, pip, pip3
1213
if isUbuntu16 || isUbuntu18; then
13-
apt-get install -y --no-install-recommends python python-dev python-pip python3 python3-dev python3-pip
14+
apt-get install -y --no-install-recommends python python-dev python-pip python3 python3-dev python3-pip python3-venv
1415
fi
1516

1617
if isUbuntu20; then
17-
apt-get install -y --no-install-recommends python3 python3-dev python3-pip
18+
apt-get install -y --no-install-recommends python3 python3-dev python3-pip python3-venv
1819
ln -s /usr/bin/pip3 /usr/bin/pip
1920
fi
2021

22+
if isUbuntu18 || isUbuntu20 ; then
23+
# Install pipx
24+
# Set pipx custom directory
25+
export PIPX_BIN_DIR=/opt/pipx_bin
26+
export PIPX_HOME=/opt/pipx
27+
28+
python3 -m pip install pipx
29+
python3 -m pipx ensurepath
30+
31+
# Update /etc/environment
32+
setEtcEnvironmentVariable "PIPX_BIN_DIR" $PIPX_BIN_DIR
33+
setEtcEnvironmentVariable "PIPX_HOME" $PIPX_HOME
34+
prependEtcEnvironmentPath $PIPX_BIN_DIR
35+
36+
# Test pipx
37+
if ! command -v pipx; then
38+
echo "pipx was not installed or not found on PATH"
39+
exit 1
40+
fi
41+
fi
42+
2143
# Run tests to determine that the software installed as expected
2244
echo "Testing to make sure that script performed as expected, and basic scenarios work"
2345
for cmd in python pip python3 pip3; do

images/linux/toolsets/toolset-1804.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164
"time",
165165
"unzip",
166166
"wget",
167-
"yamllint",
168167
"zip"
169168
]
170169
},
@@ -186,5 +185,15 @@
186185
"node:12-alpine",
187186
"ubuntu:14.04"
188187
]
189-
}
188+
},
189+
"pipx": [
190+
{
191+
"package": "yamllint",
192+
"cmd": "yamllint"
193+
},
194+
{
195+
"package": "aws-sam-cli",
196+
"cmd": "sam"
197+
}
198+
]
190199
}

images/linux/toolsets/toolset-2004.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@
127127
"time",
128128
"unzip",
129129
"wget",
130-
"yamllint",
131130
"zip"
132131
]
133132
},
@@ -149,5 +148,15 @@
149148
"node:12-alpine",
150149
"ubuntu:14.04"
151150
]
152-
}
151+
},
152+
"pipx": [
153+
{
154+
"package": "yamllint",
155+
"cmd": "yamllint"
156+
},
157+
{
158+
"package": "aws-sam-cli",
159+
"cmd": "sam"
160+
}
161+
]
153162
}

images/linux/ubuntu1804.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@
238238
{
239239
"type": "shell",
240240
"scripts": [
241-
"{{template_dir}}/scripts/installers/aws-sam-cli.sh"
241+
"{{template_dir}}/scripts/installers/pipx-packages.sh"
242242
],
243243
"environment_vars": [
244-
"HELPER_SCRIPTS={{user `helper_script_folder`}}"
244+
"INSTALLER_SCRIPT_FOLDER={{user `installer_script_folder`}}"
245245
],
246246
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
247247
},

images/linux/ubuntu2004.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@
240240
{
241241
"type": "shell",
242242
"scripts": [
243-
"{{template_dir}}/scripts/installers/aws-sam-cli.sh"
243+
"{{template_dir}}/scripts/installers/pipx-packages.sh"
244244
],
245245
"environment_vars": [
246-
"HELPER_SCRIPTS={{user `helper_script_folder`}}"
246+
"INSTALLER_SCRIPT_FOLDER={{user `installer_script_folder`}}"
247247
],
248248
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
249249
},

0 commit comments

Comments
 (0)