8000 initial commit (#71) · coder/deploy-code-server@3cdbae5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3cdbae5

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

File tree

16 files changed

+458
-0
lines changed

16 files changed

+458
-0
lines changed

deploy-k8s/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
code-server/

deploy-k8s/README.md

Lines changed: 11 additions & 0 deletions
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< 10000 /code>+
1. Run `provision-workspaces.sh` and then `get-deployments.sh`

deploy-k8s/build-images.sh

Lines changed: 31 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 22 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 37 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 24 additions & 0 deletions
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

0 commit comments

Comments
 (0)
0