Skip to content

Commit 6155f06

Browse files
committed
[self-hosted] Gitpod local preview install method
Fixes #9075 This PR adds a new install method called `preview` under the `install` directory. This includes a sh script i.e `entrypoint.sh` that gets loaded into a docker container in the `Dockerfile`. This `entrypoint.sh` does the following: - Checks for minimum system requirements - Generates a root certificate using `mkcerts`, and loads into the host's `/tmp/gitpod/gitpod-ca.crt`. - Renders `cert-manager` resources, self-signed Gitpod into `/var/lib/rancher/k3s/server/manifests`. - Initialises `k3s` inside the container. Signed-off-by: Tarun Pothulapati <[email protected]>
1 parent 7d6a91c commit 6155f06

File tree

6 files changed

+213
-0
lines changed

6 files changed

+213
-0
lines changed

components/BUILD.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ packages:
1313
- :publish-api
1414
- dev:all-app
1515
- install/installer:docker
16+
- install/preview:docker
1617
- install/kots:lint
1718
- components/gitpod-protocol:all
1819
- operations/observability/mixins:lint

install/preview/BUILD.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packages:
2+
- name: docker
3+
type: docker
4+
deps:
5+
- install/installer:app
6+
argdeps:
7+
- imageRepoBase
8+
srcs:
9+
- "entrypoint.sh"
10+
- "manifests/*.yaml"
11+
config:
12+
dockerfile: leeway.Dockerfile
13+
image:
14+
- ${imageRepoBase}/preview-install:${version}

install/preview/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Gitpod Preview Installation
2+
3+
This repo helps users to try out and preview self-hosted Gitpod **locally** without all the things
4+
needed for a production instance. The aim is to provide an installation mechanism as minimal and
5+
simple as possible.
6+
7+
## Installation
8+
9+
# @Pothulapati Update the image tag before merge
10+
```bash
11+
docker run --privileged --name gitpod --rm -it -v /tmp/gitpod:/var/gitpod https://5000-gitpodio-gitpod-csz4okmot5t.ws-us47.gitpod.io/gitpod-preview:latest
12+
```
13+
14+
Once the above command starts running and the pods are ready (can be checked by running `docker exec gitpod kubectl get pods`),
15+
The URL to access your gitpod instance can be retrieved by running
16+
17+
```
18+
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' gitpod | sed -r 's/[.]+/-/g' | sed 's/$/.nip.io/g'
19+
```
20+
21+
[nip.io](https://nip.io/) is just wildcard DNS for local addresses, So all off this is local, and cannot be accessed over the internet.
22+
23+
As the `self-hosted` instance is self-signed, The root certificate to upload into your browser trust store to access the URL is available at
24+
`/tmp/gitpod/gitpod-ca.crt`.
25+
26+
## Known Issues
27+
28+
- Prebuilds don't work as they require webhooks support over the internet.

install/preview/entrypoint.sh

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/bin/sh
2+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.
4+
5+
6+
set -ex
7+
8+
# check for minimum requirements
9+
REQUIRED_MEM_KB=$((6 * 1024 * 1024))
10+
total_mem_kb=$(awk '/MemTotal:/ {print $2}' /proc/meminfo)
11+
if [ "${total_mem_kb}" -lt "${REQUIRED_MEM_KB}" ]; then
12+
echo "Preview installation of Gitpod requires a system with at least 6GB of memory"
13+
exit 1
14+
fi
15+
16+
REQUIRED_CORES=4
17+
total_cores=$(nproc)
18+
if [ "${total_cores}" -lt "${REQUIRED_CORES}" ]; then
19+
echo "Preview installation of Gitpod requires a system with at least 4 CPU Cores"
20+
exit 1
21+
fi
22+
23+
# Get container's IP address
24+
if [ -z "${DOMAIN}" ]; then
25+
NODE_IP=$(hostname -i)
26+
DOMAIN_STRING=$(echo "${NODE_IP}" | sed "s/\./-/g")
27+
DOMAIN="${DOMAIN_STRING}.nip.io"
28+
fi
29+
30+
echo "Gitpod Domain: $DOMAIN"
31+
32+
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
33+
echo "[$(date -Iseconds)] [CgroupV2 Fix] Evacuating Root Cgroup ..."
34+
# move the processes from the root group to the /init group,
35+
# otherwise writing subtree_control fails with EBUSY.
36+
mkdir -p /sys/fs/cgroup/init
37+
busybox xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /sys/fs/cgroup/init/cgroup.procs || :
38+
# enable controllers
39+
sed -e 's/ / +/g' -e 's/^/+/' <"/sys/fs/cgroup/cgroup.controllers" >"/sys/fs/cgroup/cgroup.subtree_control"
40+
echo "[$(date -Iseconds)] [CgroupV2 Fix] Done"
41+
fi
42+
43+
mount --make-shared /sys/fs/cgroup
44+
mount --make-shared /proc
45+
mount --make-shared /var/gitpod
46+
47+
# install in local store
48+
mkcert -install
49+
cat "${HOME}"/.local/share/mkcert/rootCA.pem >> /etc/ssl/certs/ca-certificates.crt
50+
# also send root cert into a volume
51+
cat "${HOME}"/.local/share/mkcert/rootCA.pem > /var/gitpod/gitpod-ca.crt
52+
53+
cat << EOF > /var/lib/rancher/k3s/server/manifests/ca-pair.yaml
54+
apiVersion: v1
55+
kind: Secret
56+
metadata:
57+
name: ca-key-pair
58+
data:
59+
ca.crt: $(base64 -w0 "${HOME}"/.local/share/mkcert/rootCA.pem)
60+
tls.crt: $(base64 -w0 "${HOME}"/.local/share/mkcert/rootCA.pem)
61+
tls.key: $(base64 -w0 "${HOME}"/.local/share/mkcert/rootCA-key.pem)
62+
EOF
63+
64+
cat << EOF > /var/lib/rancher/k3s/server/manifests/issuer.yaml
65+
apiVersion: cert-manager.io/v1
66+
kind: Issuer
67+
metadata:
68+
name: ca-issuer
69+
spec:
70+
ca:
71+
secretName: ca-key-pair
72+
EOF
73+
74+
echo "creating Gitpod SSL secret..."
75+
cat << EOF > /var/lib/rancher/k3s/server/manifests/https-cert.yaml
76+
apiVersion: cert-manager.io/v1
77+
kind: Certificate
78+
metadata:
79+
name: https-cert
80+
spec:
81+
secretName: https-certificates
82+
issuerRef:
83+
name: ca-issuer
84+
kind: Issuer
85+
dnsNames:
86+
- "$DOMAIN"
87+
- "*.$DOMAIN"
88+
- "*.ws.$DOMAIN"
89+
EOF
90+
91+
mkdir -p /var/lib/rancher/k3s/server/manifests/gitpod
92+
93+
/gitpod-installer init > config.yaml
94+
yq e -i '.domain = "'"${DOMAIN}"'"' config.yaml
95+
yq e -i '.certificate.name = "https-certificates"' config.yaml
96+
yq e -i '.certificate.kind = "secret"' config.yaml
97+
yq e -i '.customCACert.name = "ca-key-pair"' config.yaml
98+
yq e -i '.customCACert.kind = "secret"' config.yaml
99+
yq e -i '.observability.logLevel = "debug"' config.yaml
100+
yq e -i '.workspace.runtime.containerdSocket = "/run/k3s/containerd/containerd.sock"' config.yaml
101+
yq e -i '.workspace.runtime.containerdRuntimeDir = "/var/lib/rancher/k3s/agent/containerd/io.containerd.runtime.v2.task/k8s.io/"' config.yaml
102+
103+
echo "extracting images to download ahead..."
104+
/gitpod-installer render --config config.yaml | grep 'image:' | sed 's/ *//g' | sed 's/image://g' | sed 's/\"//g' | sed 's/^-//g' | sort | uniq > /gitpod-images.txt
105+
echo "downloading images..."
106+
while read -r image "$(cat /gitpod-images.txt)"; do
107+
# shellcheck disable=SC2154
108+
ctr images pull "$image" >/dev/null &
109+
done
110+
111+
ctr images pull "docker.io/gitpod/workspace-full:latest" >/dev/null &
112+
113+
/gitpod-installer render --config config.yaml --output-split-files /var/lib/rancher/k3s/server/manifests/gitpod
114+
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*.yaml; do (cat "$f"; echo) >> /var/lib/rancher/k3s/server/gitpod.debug; done
115+
rm /var/lib/rancher/k3s/server/manifests/gitpod/*NetworkPolicy*
116+
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*PersistentVolumeClaim*.yaml; do yq e -i '.spec.storageClassName="local-path"' "$f"; done
117+
yq eval-all -i ". as \$item ireduce ({}; . *+ \$item)" /var/lib/rancher/k3s/server/manifests/gitpod/*_StatefulSet_messagebus.yaml /app/manifests/messagebus.yaml
118+
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*StatefulSet*.yaml; do yq e -i '.spec.volumeClaimTemplates[0].spec.storageClassName="local-path"' "$f"; done
119+
120+
# removing init container from ws-daemon (systemd and Ubuntu)
121+
yq eval-all -i 'del(.spec.template.spec.initContainers[0])' /var/lib/rancher/k3s/server/manifests/gitpod/*_DaemonSet_ws-daemon.yaml
122+
123+
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*.yaml; do (cat "$f"; echo) >> /var/lib/rancher/k3s/server/manifests/gitpod.yaml; done
124+
rm -rf /var/lib/rancher/k3s/server/manifests/gitpod
125+
126+
/bin/k3s server --disable traefik \
127+
--node-label gitpod.io/workload_meta=true \
128+
--node-label gitpod.io/workload_ide=true \
129+
--node-label gitpod.io/workload_workspace_services=true \
130+
--node-label gitpod.io/workload_workspace_regular=true \
131+
--node-label gitpod.io/workload_workspace_headless=true

install/preview/leeway.Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.
3+
4+
FROM rancher/k3s:v1.21.12-k3s1
5+
6+
ADD https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-amd64 /bin/mkcert
7+
RUN chmod +x /bin/mkcert
8+
9+
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static /tini
10+
RUN chmod +x /tini
11+
12+
ADD https://github.com/cert-manager/cert-manager/releases/download/v1.8.0/cert-manager.yaml /var/lib/rancher/k3s/server/manifests/cert-manager.yaml
13+
14+
ADD https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64 /bin/yq
15+
RUN chmod +x /bin/yq
16+
17+
COPY manifests/* /app/manifests/
18+
COPY install-installer--app/installer /gitpod-installer
19+
20+
COPY entrypoint.sh /entrypoint.sh
21+
22+
ENTRYPOINT [ "/tini", "--", "/entrypoint.sh" ]
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.
3+
4+
spec:
5+
volumeClaimTemplates:
6+
- metadata:
7+
creationTimestamp: null
8+
labels:
9+
app: gitpod
10+
component: messagebus
11+
name: messagebus
12+
spec:
13+
accessModes:
14+
- ReadWriteOnce
15+
resources:
16+
requests:
17+
storage: 1Gi

0 commit comments

Comments
 (0)