-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-apt-install.sh
More file actions
executable file
·73 lines (64 loc) · 2.21 KB
/
Copy pathdocker-apt-install.sh
File metadata and controls
executable file
·73 lines (64 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Useful utility to install system packages from a file
# It does so in the lowest footprint way possible, in a single RUN command.
set -euo pipefail
set -x
pro_attached=0
pro_token_file=/run/secrets/ubuntu_pro_token
if grep -q 'VERSION_ID="20.04"' /etc/os-release; then
# enable ubuntu pro, based on the example in the Canonical docs:
# https://documentation.ubuntu.com/pro-client/en/docs/howtoguides/enable_in_dockerfile/
# A file is used rather than an env var which would leak into the docker metadata.
#
# We do it in this helper script, rather than in the Dockerfile, so that
# downstream docker images can also re-use this logic and enable esm
# installations.
#
# We enable two additional archives:
# - esm-infra: core infra packages
# - esm-apps: applications and server packages
if test -s "$pro_token_file"; then
apt-get update
apt-get install --no-install-recommends -y ubuntu-pro-client ca-certificates
cat > /tmp/pro-attach-config.yaml <<EOF
token: $(cat "$pro_token_file")
enable_services:
- esm-infra
- esm-apps
EOF
pro attach --attach-config /tmp/pro-attach-config.yaml
rm -f /tmp/pro-attach-config.yaml
pro_attached=1
else
echo "ubuntu_pro_token secret is required for 20.04 build"
exit 1
fi
fi
# ensure apt lists are populated
apt-get update
# do we want to upgrade too?
test "${UPGRADE:-}" = "yes" && apt-get upgrade --yes
PACKAGES=
for arg in "$@"; do
if test -f "$arg"; then
# argument is a file
# strip any comments and install every package listed in the file
sed 's/^#.*//' "$arg" | xargs apt-get install --yes --no-install-recommends
else
# argument is a package name, add to install list
PACKAGES="$PACKAGES $arg"
fi
done
if test -n "$PACKAGES"; then
# shellcheck disable=SC2086
apt-get install --yes --no-install-recommends $PACKAGES
fi
if test "$pro_attached" = "1"; then
# remove the ubuntu pro, so it will not persist in the final layer
pro detach --assume-yes
apt-get purge --auto-remove -y ubuntu-pro-client
fi
# clean up if we've upgraded
if test "${UPGRADE:-}" = "yes"; then
apt-get autoremove --yes
fi