-
Notifications
You must be signed in to change notification settings - Fork 82
/
act.sh
executable file
Β·173 lines (143 loc) Β· 4.84 KB
/
act.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# shellcheck disable=SC2174
set -Eeuxo pipefail
printf "\n\tπ Build started π\t\n"
# Remove '"' so it can be sourced by sh/bash
sed 's|"||g' -i "/etc/environment"
. /etc/os-release
node_arch() {
case "$(uname -m)" in
'aarch64') echo 'arm64' ;;
'x86_64') echo 'x64' ;;
'armv7l') echo 'armv7l' ;;
*) exit 1 ;;
esac
}
ImageOS=ubuntu$(echo "${VERSION_ID}" | cut -d'.' -f 1)
AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache
ACT_TOOLSDIRECTORY=/opt/acttoolcache
{
echo "IMAGE_OS=$ImageOS"
echo "ImageOS=$ImageOS"
echo "LSB_RELEASE=${VERSION_ID}"
echo "AGENT_TOOLSDIRECTORY=${AGENT_TOOLSDIRECTORY}"
echo "RUN_TOOL_CACHE=${AGENT_TOOLSDIRECTORY}"
echo "DEPLOYMENT_BASEPATH=/opt/runner"
echo "USER=$(whoami)"
echo "RUNNER_USER=$(whoami)"
echo "ACT_TOOLSDIRECTORY=${ACT_TOOLSDIRECTORY}"
} | tee -a "/etc/environment"
mkdir -m 0777 -p "${AGENT_TOOLSDIRECTORY}"
chown -R 1001:1000 "${AGENT_TOOLSDIRECTORY}"
mkdir -m 0777 -p "${ACT_TOOLSDIRECTORY}"
chown -R 1001:1000 "${ACT_TOOLSDIRECTORY}"
mkdir -m 0777 -p /github
chown -R 1001:1000 /github
printf "\n\tπ Installing packages π\t\n"
packages=(
ssh
gawk
curl
jq
wget
sudo
gnupg-agent
ca-certificates
software-properties-common
apt-transport-https
libyaml-0-2
zstd
zip
unzip
xz-utils
python3-pip
python3-venv
pipx
)
apt-get -yq update
apt-get -yq install --no-install-recommends --no-install-suggests "${packages[@]}"
ln -s "$(which python3)" "/usr/local/bin/python"
add-apt-repository ppa:git-core/ppa -y
apt-get update
apt-get install -y git
git --version
git config --system --add safe.directory '*'
wget https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh -qO- | bash
apt-get update
apt-get install -y git-lfs
LSB_OS_VERSION="${VERSION_ID//\./}"
echo "LSB_OS_VERSION=${LSB_OS_VERSION}" | tee -a "/etc/environment"
wget -qO "/imagegeneration/toolset.json" "https://raw.githubusercontent.com/actions/virtual-environments/main/images/ubuntu/toolsets/toolset-${LSB_OS_VERSION}.json" || echo "File not available"
wget -qO "/imagegeneration/LICENSE" "https://raw.githubusercontent.com/actions/virtual-environments/main/LICENSE"
if [ "$(uname -m)" = x86_64 ]; then
wget -qO "/usr/bin/jq" "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64"
chmod +x "/usr/bin/jq"
fi
printf "\n\tπ Updated apt lists and upgraded packages π\t\n"
printf "\n\tπ Creating ~/.ssh and adding 'github.com' π\t\n"
mkdir -m 0700 -p ~/.ssh
{
ssh-keyscan github.com
ssh-keyscan ssh.dev.azure.com
} >>/etc/ssh/ssh_known_hosts
printf "\n\tπ Installed base utils π\t\n"
printf "\n\tπ Installing docker cli π\t\n"
if [[ "${VERSION_ID}" == "18.04" ]]; then
echo "deb https://packages.microsoft.com/ubuntu/${VERSION_ID}/multiarch/prod ${VERSION_CODENAME} main" | tee /etc/apt/sources.list.d/microsoft-prod.list
else
echo "deb https://packages.microsoft.com/ubuntu/${VERSION_ID}/prod ${VERSION_CODENAME} main" | tee /etc/apt/sources.list.d/microsoft-prod.list
fi
wget -q https://packages.microsoft.com/keys/microsoft.asc
gpg --dearmor <microsoft.asc >/etc/apt/trusted.gpg.d/microsoft.gpg
apt-key add - <microsoft.asc
rm microsoft.asc
apt-get -yq update
apt-get -yq install --no-install-recommends --no-install-suggests moby-cli moby-buildx moby-compose
printf "\n\tπ Installed moby-cli π\t\n"
docker -v
printf "\n\tπ Installed moby-buildx π\t\n"
docker buildx version
IFS=' ' read -r -a NODE <<<"$NODE_VERSION"
for ver in "${NODE[@]}"; do
printf "\n\tπ Installing Node.JS=%s π\t\n" "${ver}"
VER=$(curl https://nodejs.org/download/release/index.json | jq "[.[] | select(.version|test(\"^v${ver}\"))][0].version" -r)
NODEPATH="${ACT_TOOLSDIRECTORY}/node/${VER:1}/$(node_arch)"
mkdir -v -m 0777 -p "$NODEPATH"
wget "https://nodejs.org/download/release/latest-v${ver}.x/node-$VER-linux-$(node_arch).tar.xz" -O "node-$VER-linux-$(node_arch).tar.xz"
tar -Jxf "node-$VER-linux-$(node_arch).tar.xz" --strip-components=1 -C "$NODEPATH"
rm "node-$VER-linux-$(node_arch).tar.xz"
if [[ "${ver}" == "18" ]]; then # make this version the default (latest LTS)
sed "s|^PATH=|PATH=$NODEPATH/bin:|mg" -i /etc/environment
fi
export PATH="$NODEPATH/bin:$PATH"
printf "\n\tπ Installed Node.JS π\t\n"
"${NODEPATH}"/bin/node -v
printf "\n\tπ Installed NPM π\t\n"
"${NODEPATH}"/bin/npm -v
done
case "$(uname -m)" in
'aarch64')
scripts=(
yq
)
;;
'x86_64')
scripts=(
yq
)
;;
'armv7l')
scripts=(
yq
)
;;
*) exit 1 ;;
esac
for SCRIPT in "${scripts[@]}"; do
printf "\n\t𧨠Executing %s.sh π§¨\t\n" "${SCRIPT}"
"/imagegeneration/installers/${SCRIPT}.sh"
done
printf "\n\tπ Cleaning image π\t\n"
apt-get clean
rm -rf /var/cache/* /var/log/* /var/lib/apt/lists/* /tmp/* || echo 'Failed to delete directories'
printf "\n\tπ Cleaned up image π\t\n"