Skip to content

Commit 1e86c37

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 1e86c37

File tree

6 files changed

+207
-0
lines changed

6 files changed

+207
-0
lines changed

Diff for: 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

Diff for: install/preview/BUILD.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
packages:
2+
- name: docker
3+
type: docker
4+
deps:
5+
- install/installer:docker
6+
argdeps:
7+
- imageRepoBase
8+
config:
9+
dockerfile: Dockerfile
10+
image:
11+
- ${imageRepoBase}/preview-install:${version}
12+
- ${imageRepoBase}/preview-install:commit-${__git_commit}

Diff for: install/preview/Dockerfile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 eu.gcr.io/gitpod-core-dev/build/installer:release-2022.05.0.5 AS installer
5+
6+
FROM rancher/k3s:v1.21.12-k3s1
7+
8+
ADD https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-amd64 /bin/mkcert
9+
RUN chmod +x /bin/mkcert
10+
11+
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static /tini
12+
RUN chmod +x /tini
13+
14+
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
15+
16+
ADD https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64 /bin/yq
17+
RUN chmod +x /bin/yq
18+
19+
COPY manifests/* /app/manifests/
20+
COPY --from=installer /app/installer /gitpod-installer
21+
22+
COPY entrypoint.sh /entrypoint.sh
23+
24+
ENTRYPOINT [ "/tini", "--", "/entrypoint.sh" ]

Diff for: 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.

Diff for: install/preview/entrypoint.sh

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

Diff for: install/preview/manifests/messagebus.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
spec:
2+
volumeClaimTemplates:
3+
- metadata:
4+
creationTimestamp: null
5+
labels:
6+
app: gitpod
7+
component: messagebus
8+
name: messagebus
9+
spec:
10+
accessModes:
11+
- ReadWriteOnce
12+
resources:
13+
requests:
14+
storage: 1Gi

0 commit comments

Comments
 (0)