This repository was archived by the owner on Aug 26, 2023. It is now read-only.
forked from maslow/experiment-setup-k8s-in-actions
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.sh
More file actions
executable file
·138 lines (125 loc) · 3.96 KB
/
action.sh
File metadata and controls
executable file
·138 lines (125 loc) · 3.96 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
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
#!/bin/bash
set -ex
set -o noglob
readonly SEALOS_CMD=${cmd:-install}
###
readonly INSTALL_SEALOS_VERSION=${sealos_version:-4.1.4}
readonly INSTALL_SEALOS_GIT=${sealosGit:-https://github.com/labring/sealos.git}
readonly INSTALL_SEALOS_GIT_BRANCH=${sealosGitBranch:-main}
readonly PRUNE_CRI=${pruneCRI:-true}
readonly AUTO_FETCH=${autoFetch:-true}
INSTALL_GO_ADDR=${goAddr:-}
# --- helper functions for logs ---
info()
{
echo '[INFO] ' "$@"
}
fatal()
{
echo '[ERROR] ' "$@" >&2
exit 1
}
# --- set arch and suffix, fatal if architecture not supported ---
setup_verify_arch() {
if [ -z "$ARCH" ]; then
ARCH=$(uname -m)
fi
case $ARCH in
amd64)
ARCH=amd64
SUFFIX=
;;
x86_64)
ARCH=amd64
SUFFIX=
;;
arm64)
ARCH=arm64
SUFFIX=-${ARCH}
;;
aarch64)
ARCH=arm64
SUFFIX=-${ARCH}
;;
*)
fatal "Unsupported architecture $ARCH"
esac
}
setup_go_addr() {
if [[ $INSTALL_GO_ADDR == '' ]]; then
INSTALL_GO_ADDR="https://go.dev/dl/go1.20.linux-${ARCH}.tar.gz"
fi
}
install_buildah() {
info "download buildah in https://github.com/labring/cluster-image/releases/download/depend/buildah.linux.${ARCH}"
wget -qO "buildah" "https://github.com/labring/cluster-image/releases/download/depend/buildah.linux.${ARCH}"
chmod a+x buildah
sudo mv buildah /usr/bin
}
prune_cri() {
if [[ $PRUNE_CRI == 'true' && $SEALOS_CMD != 'prune' ]]; then
{
info "prune cri doing...."
sudo apt-get remove -y docker docker-engine docker.io containerd runc > /dev/null
sudo apt-get purge docker-ce docker-ce-cli containerd.io > /dev/null # docker-compose-plugin
sudo apt-get remove -y moby-engine moby-cli moby-buildx moby-compose > /dev/null
}
fi
}
install_by_version() {
info "download sealos sealctl in https://github.com/labring/sealos/releases/download/v${INSTALL_SEALOS_VERSION}/sealos_${INSTALL_SEALOS_VERSION}_linux_${ARCH}.tar.gz"
sudo wget -q https://github.com/labring/sealos/releases/download/v${INSTALL_SEALOS_VERSION}/sealos_${INSTALL_SEALOS_VERSION}_linux_${ARCH}.tar.gz
sudo tar -zxvf sealos_${INSTALL_SEALOS_VERSION}_linux_${ARCH}.tar.gz sealos && chmod +x sealos && sudo mv sealos /usr/bin
sudo tar -zxvf sealos_${INSTALL_SEALOS_VERSION}_linux_${ARCH}.tar.gz sealctl && chmod +x sealctl && sudo mv sealctl /usr/bin
}
install_by_build() {
info "install sealos in main code...."
{
wget -qO goNew.tgz ${INSTALL_GO_ADDR} && tar -zxf goNew.tgz && rm -rf goNew.tgz
mkdir -p /tmp/golang && mv go /tmp/golang
export PATH="/tmp/golang/go/bin:${PATH}"
go version
}
sudo apt update > /dev/null && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev > /dev/null
if [[ $AUTO_FETCH == 'true' ]]; then
info "clone git branch $INSTALL_SEALOS_GIT_BRANCH for repo $INSTALL_SEALOS_GIT"
git clone -b $INSTALL_SEALOS_GIT_BRANCH $INSTALL_SEALOS_GIT
cd sealos
fi
BINS=sealos make build
BINS=sealctl make build
sudo chmod a+x bin/linux_${ARCH}/{sealos,sealctl}
sudo mv bin/linux_${ARCH}/{sealos,sealctl} /usr/bin
}
prune_all() {
info "prune all doing...."
dpkg-query --search "$(command -v containerd)" "$(command -v docker)" || true
sudo apt-get remove -y moby-buildx moby-cli moby-compose moby-containerd moby-engine &>/dev/null
CRI_TYPE=containerd
sudo systemctl unmask "${CRI_TYPE//-/}" || true
CRI_TYPE=docker
sudo systemctl unmask "${CRI_TYPE//-/}" || true
sudo mkdir -p /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd || true
}
{
setup_verify_arch
install_buildah
prune_cri
case $SEALOS_CMD in
install)
install_by_version
;;
install-dev)
setup_go_addr
install_by_build
;;
prune)
prune_all
;;
*)
echo "unknown cmd"
exit 1
;;
esac
}