Skip to content

Commit a55d4f9

Browse files
authored
Merge pull request #393 from vyadh/config-driven-install
Config driven install
2 parents 5615bd2 + b34e2f5 commit a55d4f9

4 files changed

Lines changed: 180 additions & 50 deletions

File tree

build/config.json

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"user": {
3+
"user-id": 1001,
4+
"group-id": 121
5+
},
6+
"install": [
7+
{
8+
"category": "aws",
9+
"source": "script",
10+
"packages": [
11+
"aws-cli"
12+
]
13+
},
14+
{
15+
"category": "development",
16+
"source": "apt",
17+
"packages": [
18+
"build-essential",
19+
"zlib1g-dev",
20+
"zstd",
21+
"gettext",
22+
"libcurl4-openssl-dev",
23+
"libpq-dev",
24+
"pkg-config",
25+
"software-properties-common"
26+
]
27+
},
28+
{
29+
"category": "container-tools",
30+
"source": "script",
31+
"packages": [
32+
"container-tools"
33+
]
34+
},
35+
{
36+
"category": "debugging",
37+
"source": "script",
38+
"packages": [
39+
"liblttng-ust"
40+
]
41+
},
42+
{
43+
"category": "docker-cli",
44+
"source": "script",
45+
"packages": [
46+
"docker-cli"
47+
]
48+
},
49+
{
50+
"category": "docker",
51+
"source": "script",
52+
"packages": [
53+
"docker"
54+
]
55+
},
56+
{
57+
"category": "git",
58+
"source": "script",
59+
"packages": [
60+
"git",
61+
"git-lfs"
62+
]
63+
},
64+
{
65+
"category": "github",
66+
"source": "script",
67+
"packages": [
68+
"github-cli"
69+
]
70+
},
71+
{
72+
"category": "network-tools",
73+
"source": "apt",
74+
"packages": [
75+
"inetutils-ping",
76+
"wget",
77+
"openssh-client",
78+
"rsync"
79+
]
80+
},
81+
{
82+
"category": "node",
83+
"source": "apt",
84+
"packages": [
85+
"nodejs"
86+
]
87+
},
88+
{
89+
"category": "powershell",
90+
"source": "script",
91+
"packages": [
92+
"powershell"
93+
]
94+
},
95+
{
96+
"category": "python",
97+
"source": "apt",
98+
"packages": [
99+
"python3",
100+
"python3-pip",
101+
"python3-setuptools",
102+
"python3-venv"
103+
]
104+
},
105+
{
106+
"category": "yq",
107+
"source": "script",
108+
"packages": [
109+
"yq"
110+
]
111+
}
112+
]
113+
}

build/config.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
function config_file() {
5+
echo "$(dirname "${BASH_SOURCE[0]}")/config.json"
6+
}
7+
8+
function user_id() {
9+
jq -r '.user."user-id"' "$(config_file)"
10+
}
11+
12+
function group_id() {
13+
jq -r '.user."group-id"' "$(config_file)"
14+
}
15+
16+
function apt_packages() {
17+
jq -r '.install[] | select(.source == "apt") | .packages[]' "$(config_file)" | paste -sd ' ' -
18+
}
19+
20+
function script_packages() {
21+
jq -r '.install[] | select(.source == "script") | .packages[]' "$(config_file)"
22+
}

build/install_base.sh

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,27 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
function bootstrap_sources() {
4+
# Required by the build or runner operation
5+
function install_essentials() {
56
apt-get install -y --no-install-recommends \
67
ca-certificates \
78
curl \
8-
gnupg
9+
jq \
10+
gnupg \
11+
tar \
12+
unzip \
13+
zip \
14+
apt-transport-https \
15+
sudo \
16+
dirmngr \
17+
locales \
18+
gosu \
19+
gpg-agent \
20+
dumb-init
921
}
1022

1123
function install_tools_apt() {
12-
apt-get install -y --no-install-recommends \
13-
tar \
14-
unzip \
15-
zip \
16-
apt-transport-https \
17-
sudo \
18-
gpg-agent \
19-
software-properties-common \
20-
jq \
21-
dirmngr \
22-
locales \
23-
dumb-init \
24-
gosu \
25-
build-essential \
26-
zlib1g-dev \
27-
zstd \
28-
gettext \
29-
libcurl4-openssl-dev \
30-
inetutils-ping \
31-
wget \
32-
openssh-client \
33-
python3-pip \
34-
python3-setuptools \
35-
python3-venv \
36-
python3 \
37-
nodejs \
38-
rsync \
39-
libpq-dev \
40-
pkg-config
24+
apt_packages | xargs apt-get install -y --no-install-recommends
4125
}
4226

4327
function remove_caches() {
@@ -57,19 +41,22 @@ scripts_dir=$(dirname "$0")
5741
source "$scripts_dir/sources.sh"
5842
# shellcheck source=/dev/null
5943
source "$scripts_dir/tools.sh"
44+
# shellcheck source=/dev/null
45+
source "$scripts_dir/config.sh"
6046

6147
apt-get update
62-
bootstrap_sources
48+
install_essentials
6349
configure_sources
6450

6551
apt-get update
6652
install_tools_apt
6753
install_tools
68-
remove_sources
69-
remove_caches
7054

7155
setup_sudoers
72-
groupadd -g 121 runner
73-
useradd -mr -d /home/runner -u 1001 -g 121 runner
56+
groupadd -g "$(group_id)" runner
57+
useradd -mr -d /home/runner -u "$(user_id)" -g "$(group_id)" runner
7458
usermod -aG sudo runner
7559
usermod -aG docker runner
60+
61+
remove_sources
62+
remove_caches

build/tools.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function install_git() {
66
|| apt-get install -t stable -y --no-install-recommends git )
77
}
88

9-
function install_liblttng_ust() {
9+
function install_liblttng-ust() {
1010
if [[ $(apt-cache search -n liblttng-ust0 | awk '{print $1}') == "liblttng-ust0" ]]; then
1111
apt-get install -y --no-install-recommends liblttng-ust0
1212
fi
@@ -16,7 +16,7 @@ function install_liblttng_ust() {
1616
fi
1717
}
1818

19-
function install_awscli() {
19+
function install_aws-cli() {
2020
( curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip" \
2121
&& unzip -q awscliv2.zip -d /tmp/ \
2222
&& /tmp/aws/install \
@@ -25,7 +25,7 @@ function install_awscli() {
2525
|| pip3 install --no-cache-dir awscli
2626
}
2727

28-
function install_gitlfs() {
28+
function install_git-lfs() {
2929
local DPKG_ARCH
3030
DPKG_ARCH="$(dpkg --print-architecture)"
3131

@@ -35,6 +35,10 @@ function install_gitlfs() {
3535
rm -rf /tmp/lfs.tar.gz "/tmp/git-lfs-${GIT_LFS_VERSION}"
3636
}
3737

38+
function install_docker-cli() {
39+
apt-get install -y docker-ce-cli --no-install-recommends --allow-unauthenticated
40+
}
41+
3842
function install_docker() {
3943
apt-get install -y docker-ce docker-ce-cli docker-buildx-plugin containerd.io docker-compose-plugin --no-install-recommends --allow-unauthenticated
4044

@@ -44,11 +48,11 @@ function install_docker() {
4448
sed -i 's/ulimit -Hn/# ulimit -Hn/g' /etc/init.d/docker
4549
}
4650

47-
function install_container_tools() {
51+
function install_container-tools() {
4852
( apt-get install -y --no-install-recommends podman buildah skopeo || : )
4953
}
5054

51-
function install_githubcli() {
55+
function install_github-cli() {
5256
local DPKG_ARCH GH_CLI_VERSION GH_CLI_DOWNLOAD_URL
5357

5458
DPKG_ARCH="$(dpkg --print-architecture)"
@@ -104,13 +108,17 @@ function install_powershell() {
104108
}
105109

106110
function install_tools() {
107-
install_git
108-
install_liblttng_ust
109-
install_awscli
110-
install_gitlfs
111-
install_docker
112-
install_container_tools
113-
install_githubcli
114-
install_yq
115-
install_powershell
111+
local function_name
112+
# shellcheck source=/dev/null
113+
source "$(dirname "${BASH_SOURCE[0]}")/config.sh"
114+
115+
script_packages | while read -r package; do
116+
function_name="install_${package}"
117+
if declare -f "${function_name}" > /dev/null; then
118+
"${function_name}"
119+
else
120+
echo "No install script found for package: ${package}"
121+
exit 1
122+
fi
123+
done
116124
}

0 commit comments

Comments
 (0)