Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[self-hosted] Gitpod local preview install method #10532

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[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 <tarun@gitpod.io>
  • Loading branch information
Pothulapati committed Jun 15, 2022
commit 6c5fdab45c573950c1710136b79a9111b84fb54a
1 change: 1 addition & 0 deletions components/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ packages:
- :publish-api
- dev:all-app
- install/installer:docker
- install/preview:docker
- install/kots:lint
- components/gitpod-protocol:all
- operations/observability/mixins:lint
Expand Down
14 changes: 14 additions & 0 deletions install/preview/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
packages:
- name: docker
type: docker
deps:
- install/installer:app
argdeps:
- imageRepoBase
srcs:
- "entrypoint.sh"
- "manifests/*.yaml"
config:
dockerfile: leeway.Dockerfile
image:
- ${imageRepoBase}/preview-install:${version}
27 changes: 27 additions & 0 deletions install/preview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Gitpod Preview Installation

This repo helps users to try out and preview self-hosted Gitpod **locally** without all the things
needed for a production instance. The aim is to provide an installation mechanism as minimal and
simple as possible.

## Installation

```bash
docker run --privileged --name gitpod --rm -it -v /tmp/gitpod:/var/gitpod eu.gcr.io/gitpod-core-dev/build/preview-install:tar-preview-install.4
```

Once the above command starts running and the pods are ready (can be checked by running `docker exec gitpod kubectl get pods`),
The URL to access your gitpod instance can be retrieved by running

```
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' gitpod | sed -r 's/[.]+/-/g' | sed 's/$/.nip.io/g'
```

[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.

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
`/tmp/gitpod/gitpod-ca.crt`.

## Known Issues

- Prebuilds don't work as they require webhooks support over the internet.
131 changes: 131 additions & 0 deletions install/preview/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/bin/sh
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.


set -ex

# check for minimum requirements
REQUIRED_MEM_KB=$((6 * 1024 * 1024))
total_mem_kb=$(awk '/MemTotal:/ {print $2}' /proc/meminfo)
if [ "${total_mem_kb}" -lt "${REQUIRED_MEM_KB}" ]; then
echo "Preview installation of Gitpod requires a system with at least 6GB of memory"
exit 1
fi

REQUIRED_CORES=4
total_cores=$(nproc)
if [ "${total_cores}" -lt "${REQUIRED_CORES}" ]; then
echo "Preview installation of Gitpod requires a system with at least 4 CPU Cores"
exit 1
fi

# Get container's IP address
if [ -z "${DOMAIN}" ]; then
NODE_IP=$(hostname -i)
DOMAIN_STRING=$(echo "${NODE_IP}" | sed "s/\./-/g")
DOMAIN="${DOMAIN_STRING}.nip.io"
fi

echo "Gitpod Domain: $DOMAIN"

if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
echo "[$(date -Iseconds)] [CgroupV2 Fix] Evacuating Root Cgroup ..."
# move the processes from the root group to the /init group,
# otherwise writing subtree_control fails with EBUSY.
mkdir -p /sys/fs/cgroup/init
busybox xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /sys/fs/cgroup/init/cgroup.procs || :
# enable controllers
sed -e 's/ / +/g' -e 's/^/+/' <"/sys/fs/cgroup/cgroup.controllers" >"/sys/fs/cgroup/cgroup.subtree_control"
echo "[$(date -Iseconds)] [CgroupV2 Fix] Done"
fi

mount --make-shared /sys/fs/cgroup
mount --make-shared /proc
mount --make-shared /var/gitpod

# install in local store
mkcert -install
cat "${HOME}"/.local/share/mkcert/rootCA.pem >> /etc/ssl/certs/ca-certificates.crt
# also send root cert into a volume
cat "${HOME}"/.local/share/mkcert/rootCA.pem > /var/gitpod/gitpod-ca.crt

cat << EOF > /var/lib/rancher/k3s/server/manifests/ca-pair.yaml
apiVersion: v1
kind: Secret
metadata:
name: ca-key-pair
data:
ca.crt: $(base64 -w0 "${HOME}"/.local/share/mkcert/rootCA.pem)
tls.crt: $(base64 -w0 "${HOME}"/.local/share/mkcert/rootCA.pem)
tls.key: $(base64 -w0 "${HOME}"/.local/share/mkcert/rootCA-key.pem)
EOF

cat << EOF > /var/lib/rancher/k3s/server/manifests/issuer.yaml
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: ca-issuer
spec:
ca:
secretName: ca-key-pair
EOF

echo "creating Gitpod SSL secret..."
cat << EOF > /var/lib/rancher/k3s/server/manifests/https-cert.yaml
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: https-cert
spec:
secretName: https-certificates
issuerRef:
name: ca-issuer
kind: Issuer
dnsNames:
- "$DOMAIN"
- "*.$DOMAIN"
- "*.ws.$DOMAIN"
EOF

mkdir -p /var/lib/rancher/k3s/server/manifests/gitpod

/gitpod-installer init > config.yaml
yq e -i '.domain = "'"${DOMAIN}"'"' config.yaml
yq e -i '.certificate.name = "https-certificates"' config.yaml
yq e -i '.certificate.kind = "secret"' config.yaml
yq e -i '.customCACert.name = "ca-key-pair"' config.yaml
yq e -i '.customCACert.kind = "secret"' config.yaml
yq e -i '.observability.logLevel = "debug"' config.yaml
yq e -i '.workspace.runtime.containerdSocket = "/run/k3s/containerd/containerd.sock"' config.yaml
yq e -i '.workspace.runtime.containerdRuntimeDir = "/var/lib/rancher/k3s/agent/containerd/io.containerd.runtime.v2.task/k8s.io/"' config.yaml

echo "extracting images to download ahead..."
/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
echo "downloading images..."
while read -r image "$(cat /gitpod-images.txt)"; do
# shellcheck disable=SC2154
ctr images pull "$image" >/dev/null &
done
Comment on lines +103 to +109
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rationale behind pulling the images ahead?

Copy link
Contributor Author

@Pothulapati Pothulapati Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the pods startup faster? 🤔

There's not a lot of gain here (as our main painpoint is the workspace image build) but I was able to see around 2-3 minutes when I added this 🤔


ctr images pull "docker.io/gitpod/workspace-full:latest" >/dev/null &

/gitpod-installer render --config config.yaml --output-split-files /var/lib/rancher/k3s/server/manifests/gitpod
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*.yaml; do (cat "$f"; echo) >> /var/lib/rancher/k3s/server/gitpod.debug; done
rm /var/lib/rancher/k3s/server/manifests/gitpod/*NetworkPolicy*
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*PersistentVolumeClaim*.yaml; do yq e -i '.spec.storageClassName="local-path"' "$f"; done
yq eval-all -i ". as \$item ireduce ({}; . *+ \$item)" /var/lib/rancher/k3s/server/manifests/gitpod/*_StatefulSet_messagebus.yaml /app/manifests/messagebus.yaml
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

# removing init container from ws-daemon (systemd and Ubuntu)
yq eval-all -i 'del(.spec.template.spec.initContainers[0])' /var/lib/rancher/k3s/server/manifests/gitpod/*_DaemonSet_ws-daemon.yaml
Comment on lines +113 to +121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a quite a lot of pre-processing. Could you add comments on why they are actually needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added them in #10695


for f in /var/lib/rancher/k3s/server/manifests/gitpod/*.yaml; do (cat "$f"; echo) >> /var/lib/rancher/k3s/server/manifests/gitpod.yaml; done
rm -rf /var/lib/rancher/k3s/server/manifests/gitpod

/bin/k3s server --disable traefik \
--node-label gitpod.io/workload_meta=true \
--node-label gitpod.io/workload_ide=true \
--node-label gitpod.io/workload_workspace_services=true \
--node-label gitpod.io/workload_workspace_regular=true \
--node-label gitpod.io/workload_workspace_headless=true
22 changes: 22 additions & 0 deletions install/preview/leeway.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.

FROM rancher/k3s:v1.21.12-k3s1

ADD https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-amd64 /bin/mkcert
RUN chmod +x /bin/mkcert

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

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

ADD https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64 /bin/yq
RUN chmod +x /bin/yq

COPY manifests/* /app/manifests/
COPY install-installer--app/installer /gitpod-installer

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT [ "/tini", "--", "/entrypoint.sh" ]
17 changes: 17 additions & 0 deletions install/preview/manifests/messagebus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.

spec:
volumeClaimTemplates:
- metadata:
creationTimestamp: null
labels:
app: gitpod
component: messagebus
name: messagebus
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi