Skip to content

Commit

Permalink
Add support for devcontainers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidswiss committed Dec 27, 2024
1 parent 93a71c4 commit a2247a6
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM mcr.microsoft.com/devcontainers/go:dev-1.23-bookworm

ARG TARGETOS
ARG TARGETARCH

ENV HELMVERS="v3.16.4"
ENV YQVERSION="v4.44.6"
ENV KUBECOLORVERSION="0.4.0"

# Install kubectl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl && chmod +x ./kubectl && mv ./kubectl /usr/local/bin

# Install helm
RUN bash -c "curl -s https://get.helm.sh/helm-${HELMVERS}-linux-${TARGETARCH}.tar.gz > helm3.tar.gz" && tar -zxvf helm3.tar.gz linux-${TARGETARCH}/helm && chmod +x linux-${TARGETARCH}/helm && mv linux-${TARGETARCH}/helm /usr/local/bin && rm helm3.tar.gz && rm -R linux-${TARGETARCH}

# Install yq
RUN curl -L -o yq "https://github.com/mikefarah/yq/releases/download/${YQVERSION}/yq_linux_${TARGETARCH}" && install -c -m 0755 yq /usr/local/bin

# Install kubecolor
RUN curl -L -o kubecolor.tar.gz https://github.com/kubecolor/kubecolor/releases/download/v${KUBECOLORVERSION}/kubecolor_${KUBECOLORVERSION}_linux_${TARGETARCH}.tar.gz && tar -xvzf kubecolor.tar.gz && install -c -m 0755 kubecolor /usr/local/bin

# Install bash-complete to make kubectl autocomplete work
RUN apt-get update && apt-get install bash-completion make vim -y && rm -rf /var/lib/apt/lists/*
54 changes: 54 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "KubeBuilder Example",
"build": {
"dockerfile": "./Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"moby": true
},
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils:1": {}
},
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
"customizations": {
// "devpod": {
// "prebuildRepository": "ghcr.io/loft-sh/devpod-kubebuilder-template"
// },
"vscode": {
"extensions": [
"golang.go",
"ms-vscode.makefile-tools",
"redhat.vscode-yaml",
"timonwong.shellcheck",
"eamodio.gitlens",
"mhutchie.git-graph"
],
"settings": {
// This has to be set individually to each developers preference
// in their local vscode configs.
// "terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash"
},
"zsh": {
"path": "zsh"
},
"fish": {
"path": "fish"
},
"tmux": {
"path": "tmux",
"icon": "terminal-tmux"
},
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell"
}
}
}
}
}
}
29 changes: 29 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
mkdir -p $HOME/.kube
kubectl completion bash > /home/vscode/.kube/completion.bash.inc
printf "
source /usr/share/bash-completion/bash_completion
source $HOME/.kube/completion.bash.inc
alias k=kubectl
complete -F __start_kubectl k
" >> $HOME/.bashrc

printf "
source <(kubectl completion zsh)
alias k=kubectl
alias ll='ls -al'
complete -F __start_kubectl k
" >> $HOME/.zshrc

rm -rf .kind

mkdir .kind

git clone -b add/devcontainers https://github.com/vshn/kindev .kind

cd .kind

# `make clean vshnall` doesn't work for some reason
make clean
make vshnall

cp .kind/kind-config ~/.kube/config
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ __debug_bin*
hack/res
hack/tmp
hack/diff/function.yaml

# MacOS stuff
.DS_store

0 comments on commit a2247a6

Please sign in to comment.