Skip to content

Commit 25ea6ed

Browse files
committed
Use installer
1 parent 35c7aa1 commit 25ea6ed

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

Dockerfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
FROM rancher/k3s:v1.18.4-k3s1
1+
FROM eu.gcr.io/gitpod-core-dev/build/installer:cw-misc-installer.0 AS installer
2+
3+
FROM rancher/k3s:v1.21.12-k3s1
24

35
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static /tini
46
RUN chmod +x /tini
57

6-
# This does not work because the helm timeout is to tight.
7-
#COPY gitpod-helm.yaml /var/lib/rancher/k3s/server/manifests/gitpod-helm-installer.yaml
8-
COPY gitpod-helm-installer.yaml /var/lib/rancher/k3s/server/manifests/
98

10-
COPY entrypoint.sh /entrypoint
9+
ADD https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64 /yq
10+
RUN chmod +x /yq
11+
12+
COPY --from=installer /app/installer /gitpod-installer
13+
14+
COPY entrypoint.sh /entrypoint.sh
1115

12-
ENTRYPOINT [ "/tini", "--", "/entrypoint" ]
16+
ENTRYPOINT [ "/tini", "--", "/entrypoint.sh" ]

entrypoint.sh

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,41 @@ set -eu
55
mount --make-shared /sys/fs/cgroup
66
mount --make-shared /var/gitpod/workspaces
77

8-
# prepare Gitpod helm installer
9-
if [ -f /var/lib/rancher/k3s/server/manifests/gitpod-helm-installer.yaml ]; then
10-
11-
if [ -z "$DOMAIN" ]; then
12-
>&2 echo "Error: Environment variable DOMAIN is missing."
13-
exit 1;
14-
fi
15-
16-
if [ -f /values.yaml ]; then
17-
sed 's/^/ /' /values.yaml >> /var/lib/rancher/k3s/server/manifests/gitpod-helm-installer.yaml
18-
else
19-
echo " hostname: gitpod.{{ DOMAIN }}" >> /var/lib/rancher/k3s/server/manifests/gitpod-helm-installer.yaml
20-
fi
21-
22-
sed -i "s/{{ DOMAIN }}/$DOMAIN/g" /var/lib/rancher/k3s/server/manifests/gitpod-helm-installer.yaml
23-
24-
# gitpod-helm-installer.yaml needs access to kubernetes by the public host IP.
25-
kubeconfig_replacip() {
26-
while [ ! -f /etc/rancher/k3s/k3s.yaml ]; do sleep 1; done
27-
HOSTIP=$(hostname -i)
28-
sed "s+127.0.0.1+$HOSTIP+g" /etc/rancher/k3s/k3s.yaml > /etc/rancher/k3s/k3s_.yaml
29-
}
30-
kubeconfig_replacip &
31-
32-
installation_completed_hook() {
33-
while [ -z "$(kubectl get pods | grep gitpod-helm-installer | grep Completed)" ]; do sleep 10; done
34-
35-
echo "Removing network policies ..."
36-
kubectl delete networkpolicies.networking.k8s.io --all
37-
38-
echo "Removing installer manifest ..."
39-
rm -f /var/lib/rancher/k3s/server/manifests/gitpod-helm-installer.yaml
40-
}
41-
installation_completed_hook &
42-
8+
if [ -z "$DOMAIN" ]; then
9+
>&2 echo "Error: Environment variable DOMAIN is missing."
10+
exit 1;
4311
fi
4412

13+
/gitpod-installer init > config.yaml
14+
/yq -i '.domain = "'"$DOMAIN"'"' config.yaml
15+
/yq -i '.workspace.runtime.containerdRuntimeDir = "/run/k3s/containerd/containerd.sock"' config.yaml
16+
17+
mkdir -p /var/lib/rancher/k3s/server/manifests/gitpod
18+
/gitpod-installer render --config config.yaml --output-split-files /var/lib/rancher/k3s/server/manifests/gitpod
19+
rm /var/lib/rancher/k3s/server/manifests/gitpod/*NetworkPolicy*
20+
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*PersistentVolumeClaim*.yaml; do /yq -i '.spec.storageClassName="local-path"' "$f"; done
21+
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*StatefulSet*.yaml; do /yq -i '.spec.volumeClaimTemplates[0].spec.storageClassName="local-path"' "$f"; done
22+
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*.yaml; do (cat "$f"; echo) >> /var/lib/rancher/k3s/server/manifests/gitpod.yaml; done
23+
rm -rf /var/lib/rancher/k3s/server/manifests/gitpod
24+
25+
# gitpod-helm-installer.yaml needs access to kubernetes by the public host IP.
26+
kubeconfig_replacip() {
27+
while [ ! -f /etc/rancher/k3s/k3s.yaml ]; do sleep 1; done
28+
HOSTIP=$(hostname -i)
29+
sed "s+127.0.0.1+$HOSTIP+g" /etc/rancher/k3s/k3s.yaml > /etc/rancher/k3s/k3s_.yaml
30+
}
31+
kubeconfig_replacip &
32+
33+
installation_completed_hook() {
34+
while [ -z "$(kubectl get pods | grep gitpod-helm-installer | grep Completed)" ]; do sleep 10; done
35+
36+
echo "Removing network policies ..."
37+
kubectl delete networkpolicies.networking.k8s.io --all
38+
39+
echo "Removing installer manifest ..."
40+
rm -f /var/lib/rancher/k3s/server/manifests/gitpod.yaml
41+
}
42+
installation_completed_hook &
4543

4644
# add HTTPS certs secret
4745
if [ -f /certs/chain.pem ] && [ -f /certs/dhparams.pem ] && [ -f /certs/fullchain.pem ] && [ -f /certs/privkey.pem ]; then
@@ -66,28 +64,33 @@ fi
6664

6765

6866
# patch DNS config
69-
if [ -n "$DOMAIN" ] && [ -n "$DNSSERVER" ]; then
70-
patchdns() {
71-
echo "Waiting for CoreDNS to patch config ..."
72-
while [ -z "$(kubectl get pods -n kube-system | grep coredns | grep Running)" ]; do sleep 10; done
73-
74-
DOMAIN=$1
75-
DNSSERVER=$2
76-
77-
if [ -z "$(kubectl get configmap -n kube-system coredns -o json | grep $DOMAIN)" ]; then
78-
echo "Patching CoreDNS config ..."
79-
80-
kubectl get configmap -n kube-system coredns -o json | \
81-
sed -e "s+.:53+$DOMAIN {\\\\n forward . $DNSSERVER\\\\n}\\\\n.:53+g" | \
82-
kubectl apply -f -
83-
echo "CoreDNS config patched."
84-
else
85-
echo "CoreDNS has been patched already."
86-
fi
87-
}
88-
patchdns "$DOMAIN" "$DNSSERVER" &
89-
fi
67+
# if [ -n "$DOMAIN" ] && [ -n "$DNSSERVER" ]; then
68+
# patchdns() {
69+
# echo "Waiting for CoreDNS to patch config ..."
70+
# while [ -z "$(kubectl get pods -n kube-system | grep coredns | grep Running)" ]; do sleep 10; done
71+
72+
# DOMAIN=$1
73+
# DNSSERVER=$2
74+
75+
# if [ -z "$(kubectl get configmap -n kube-system coredns -o json | grep $DOMAIN)" ]; then
76+
# echo "Patching CoreDNS config ..."
77+
78+
# kubectl get configmap -n kube-system coredns -o json | \
79+
# sed -e "s+.:53+$DOMAIN {\\\\n forward . $DNSSERVER\\\\n}\\\\n.:53+g" | \
80+
# kubectl apply -f -
81+
# echo "CoreDNS config patched."
82+
# else
83+
# echo "CoreDNS has been patched already."
84+
# fi
85+
# }
86+
# patchdns "$DOMAIN" "$DNSSERVER" &
87+
# fi
9088

9189

9290
# start k3s
93-
/bin/k3s server --disable traefik
91+
/bin/k3s server --disable traefik \
92+
--node-label gitpod.io/workload_meta=true \
93+
--node-label gitpod.io/workload_ide=true \
94+
--node-label gitpod.io/workload_workspace_services=true \
95+
--node-label gitpod.io/workload_workspace_regular=true \
96+
--node-label gitpod.io/workload_workspace_headless=true

0 commit comments

Comments
 (0)