Skip to content

Commit 3cdbae5

Browse files
authored
initial commit (#71)
1 parent 191037c commit 3cdbae5

16 files changed

+458
-0
lines changed

deploy-k8s/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
code-server/

deploy-k8s/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# deploy-k8s
2+
3+
Some helper scripts and example images for deploying to Kubernetes. These are still a work in progress and the images do not have CI/CD set up.
4+
5+
Note: This is a quick way to get up and running with code-server Helm charts. We recommend managing these workspaces with something other than bash scripts 😂
6+
7+
1. Ensure you have kubectl, helm, installed and your kube context is pointed at an active cluster.
8+
1. Clone this repo and run `init.sh` to clone code-server
9+
1. Build the images with `build-images.sh`.
10+
1. Edit the examples in `workspaces/` to use your images
11+
1. Run `provision-workspaces.sh` and then `get-deployments.sh`

deploy-k8s/build-images.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
# This will build and push public images in the images/ folder to
4+
# DockerHub based on your Docker username with the
5+
# format: $username/dev-env-$folder:latest
6+
7+
set -e
8+
9+
docker_username=$(docker-credential-$(jq -r .credsStore ~/.docker/config.json) list | jq -r '. | to_entries[] | select(.key | contains("docker.io")) | last(.value)')
10+
11+
build_and_push() {
12+
folder=$1
13+
basename=$(basename -- "$folder")
14+
name=${basename%.*}
15+
docker build $folder -t bencdr/dev-env-$name:latest
16+
docker push $docker_username/dev-env-$name:latest
17+
}
18+
19+
build_and_push "images/base"
20+
21+
# Build all other images in the images/ folder
22+
# note: if you have multiple base images or heirchal images
23+
# you'll want to build them in a controlled order above and
24+
# exclude them. can be comma or space seperated :)
25+
exclude="images/base"
26+
27+
for folder in images/*; do
28+
if [[ ! "$exclude" == *"$folder"* ]]; then
29+
build_and_push $folder
30+
fi
31+
done

deploy-k8s/extras/new-image.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# This creates a new image folder and opens it in
4+
# VS Code, if you have it installed
5+
6+
cp -r images/frontend images/new
7+
8+
if command -v code &> /dev/null; then
9+
code images/new/Dockerfile
10+
fi

deploy-k8s/extras/new-workspace.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# This creates a new workspace file and opens it in
4+
# VS Code, if you have it installed
5+
6+
cp workspaces/ben.yaml workspaces/new.yaml
7+
8+
if command -v code &> /dev/null; then
9+
code workspaces/new.yaml
10+
fi

deploy-k8s/get-deployments.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
# This will look in your workspaces/ folder and
4+
# look up the helm deployments in a basic manner
5+
6+
get_deployment() {
7+
name=$1
8+
ip=$(kubectl get svc $name-dev-code-server -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
9+
port=$(kubectl get svc $name-dev-code-server -o jsonpath='{.spec.ports[0].port}')
10+
image=$(helm get values $name-dev -o json | jq .image.repository)
11+
echo "$name (image: $image)"
12+
echo "http://$ip:$port"
13+
echo $(kubectl get secret $name-dev-code-server -o jsonpath="{.data.password}" | base64 --decode)
14+
echo "---"
15+
}
16+
17+
18+
for file in workspaces/*.yaml; do
19+
basename=$(basename -- "$file")
20+
name=${basename%.*}
21+
get_deployment $name
22+
done

deploy-k8s/images/base/Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM codercom/code-server:3.12.0
2+
3+
# Install Homebrew, must be as a non-root user
4+
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
5+
ENV PATH /home/linuxbrew/.linuxbrew/bin:${PATH}
6+
7+
USER root
8+
9+
RUN apt-get update && \
10+
apt-get install -y python3 python3-pip
11+
12+
USER coder

deploy-k8s/images/devops/Dockerfile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM bencdr/dev-env-base:latest
2+
3+
USER root
4+
5+
RUN apt-get update
6+
RUN apt-get install -y apt-transport-https gnupg
7+
8+
# Install kubectl
9+
RUN curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg && \
10+
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list && \
11+
apt-get update && apt-get install -y kubectl
12+
13+
# Install helm
14+
RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
15+
16+
# Install gcloud
17+
RUN curl -fsSLo /usr/share/keyrings/cloud.google.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg && \
18+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
19+
apt-get update && apt-get install -y google-cloud-sdk
20+
21+
# Install AWS CLI
22+
RUN pip3 install awscli
23+
24+
USER coder
25+
26+
# Install terraform
27+
RUN brew tap hashicorp/tap && \
28+
brew install hashicorp/tap/terraform
29+
30+
# Install kubectx
31+
RUN brew install kubectl
32+
33+
# Install Docker
34+
RUN sudo apt-get install -y docker.io systemd systemd-sysv
35+
RUN systemctl enable docker
36+
37+
USER coder

deploy-k8s/images/frontend/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM bencdr/dev-env-base:latest
2+
3+
USER root
4+
5+
# Install Node.js
6+
ARG NODE_VERSION=14
7+
RUN curl -sL "https://deb.nodesource.com/setup_$NODE_VERSION.x" | bash -
8+
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y nodejs
9+
10+
# Install yarn
11+
RUN npm install -g yarn
12+
13+
USER coder

deploy-k8s/init.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
# This will create a namespace on your cluster
4+
# and ensure you have the proper commands.
5+
6+
# It will also clone code server so that you
7+
# can use the helmchart :)
8+
9+
NAMESPACE=${NAMESPACE:-dev-envs}
10+
11+
git clone https://github.com/cdr/code-server
12+
kubectl create namespace $NAMESPACE
13+
14+
./set-namespace.sh $NAMESPACE
15+
16+
if ! command -v helm &> /dev/null; then
17+
echo "! Please install the helm: https://helm.sh/docs/intro/install/"
18+
exit
19+
fi
20+
21+
if ! command -v jq &> /dev/null; then
22+
echo "! Please install the yq command: https://stedolan.github.io/jq/"
23+
exit
24+
fi

deploy-k8s/provision-workspaces.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
# This will create/update helm deployments based
4+
# on the charts in your workspaces folder.
5+
6+
# To create a new deployment: clone a chart,
7+
# modify accordingly, and run this script.
8+
9+
for file in workspaces/*.yaml; do
10+
basename=$(basename -- "$file")
11+
name=${basename%.*}
12+
helm upgrade --install $name-dev code-server/ci/helm-chart --values $file
13+
14+
# restart the pods to grab the latest version
15+
# this is not needed if you version-control images
16+
kubectl rollout restart deployment $name-dev-code-server
17+
echo "---"
18+
done

deploy-k8s/set-namespace.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# Pretty lame, but helpful command :)
4+
# kubens is cool too.
5+
6+
# ex: ./set-namespace.sh dev-envs
7+
8+
kubectl config set-context --current --namespace=$1

deploy-k8s/workspaces/ben.yaml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
replicaCount: 1
2+
3+
hostnameOverride: "ben-dev"
4+
5+
image:
6+
repository: bencdr/dev-env-devops
7+
tag: "latest"
8+
pullPolicy: Always
9+
10+
resources:
11+
limits:
12+
cpu: 2000m
13+
memory: 8000Mi
14+
requests:
15+
cpu: 500m
16+
memory: 1000Mi
17+
18+
persistence:
19+
enabled: true
20+
accessMode: ReadWriteOnce
21+
size: 10Gi
22+
annotations: {}
23+
24+
extraContainers: |
25+
- name: docker-dind
26+
image: docker:20.10-dind
27+
imagePullPolicy: IfNotPresent
28+
resources:
29+
requests:
30+
cpu: 250m
31+
memory: 256M
32+
securityContext:
33+
privileged: true
34+
procMount: Default
35+
env:
36+
- name: DOCKER_TLS_CERTDIR
37+
value: ""
38+
- name: DOCKER_DRIVER
39+
value: "overlay2"
40+
41+
volumePermissions:
42+
enabled: true
43+
securityContext:
44+
runAsUser: 0
45+
46+
securityContext:
47+
enabled: true
48+
fsGroup: 1000
49+
runAsUser: 1000
50+
51+
service:
52+
type: LoadBalancer
53+
port: 8080
54+
55+
ingress:
56+
enabled: false
57+
#annotations:
58+
# kubernetes.io/ingress.class: nginx
59+
# kubernetes.io/tls-acme: "true"
60+
#hosts:
61+
# - host: code-server.example.loc
62+
# paths:
63+
# - /
64+
65+
#tls:
66+
# - secretName: code-server
67+
# hosts:
68+
# - code-server.example.loc
69+
70+
extraArgs: []
71+
extraVars:
72+
- name: DOCKER_HOST
73+
value: tcp://localhost:2375
74+
75+
nodeSelector: {}
76+
77+
tolerations: []
78+
79+
affinity: {}
80+
81+
extraSecretMounts: []
82+
83+
extraVolumeMounts: []
84+
85+
hostPath: ""
86+
87+
extraConfigmapMounts: []
88+
89+
serviceAccount:
90+
create: false

deploy-k8s/workspaces/jordan.yaml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
replicaCount: 1
2+
3+
hostnameOverride: "jordan-dev"
4+
5+
image:
6+
repository: bencdr/dev-env-frontend
7+
tag: "latest"
8+
pullPolicy: Always
9+
10+
resources:
11+
limits:
12+
cpu: 4000m
13+
memory: 8000Mi
14+
requests:
15+
cpu: 1000m
16+
memory: 2000Mi
17+
18+
persistence:
19+
enabled: true
20+
accessMode: ReadWriteOnce
21+
size: 10Gi
22+
annotations: {}
23+
24+
volumePermissions:
25+
enabled: true
26+
securityContext:
27+
runAsUser: 0
28+
29+
securityContext:
30+
enabled: true
31+
fsGroup: 1000
32+
runAsUser: 1000
33+
34+
service:
35+
type: LoadBalancer
36+
port: 8083
37+
38+
ingress:
39+
enabled: false
40+
#annotations:
41+
# kubernetes.io/ingress.class: nginx
42+
# kubernetes.io/tls-acme: "true"
43+
#hosts:
44+
# - host: code-server.example.loc
45+
# paths:
46+
# - /
47+
48+
#tls:
49+
# - secretName: code-server
50+
# hosts:
51+
# - code-server.example.loc
52+
53+
extraArgs: []
54+
55+
nodeSelector: {}
56+
57+
tolerations: []
58+
59+
affinity: {}
60+
61+
extraSecretMounts: []
62+
63+
extraVolumeMounts: []
64+
65+
hostPath: ""
66+
67+
extraConfigmapMounts: []
68+
69+
serviceAccount:
70+
create: false

0 commit comments

Comments
 (0)