|
| 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 |
0 commit comments