diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..aca5934a7 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -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/* diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..c9d7f93a4 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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" + } + } + } + } + } +} diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100755 index 000000000..974dd9d04 --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,19 @@ +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 + +make setup-kindev + +cp .kind/.kind/kind-config ~/.kube/config diff --git a/.gitignore b/.gitignore index de6acf71f..c9094f77c 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ __debug_bin* hack/res hack/tmp hack/diff/function.yaml + +# MacOS stuff +.DS_store diff --git a/Makefile b/Makefile index 62ce808dd..b97440915 100644 --- a/Makefile +++ b/Makefile @@ -225,3 +225,13 @@ render-diff: ## Render diff between the cluster in KUBECONF and the local branch # this will speed up the compare in CI/CD environments. if ! docker pull $(IMG); then $(MAKE) docker-build-branchtag; fi hack/diff/compare.sh $(DEBUG) + +.PHONY: setup-kindev + +setup-kindev: ## Setup kindev in the .kind folder, will always create a new instance + rm -rf .kind && \ + git clone --depth=1 -b add/devcontainers https://github.com/vshn/kindev .kind && \ + cd .kind && \ + rm -rf .git && \ + make clean && \ + make vshnall diff --git a/README.md b/README.md index ef64ab065..28edc4eb0 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,45 @@ Documentation: https://vshn.github.io/appcat └── tools.go ``` +## Getting started with devcontainers + +This project contains a `.devcontainer` folder, which enables devcontainer support in vscode and other IDEs. +Make sure you've installed the dev containers extension for vscode. + +Then open the command palette and do `Dev Containers: Reopen in container`. +The first time doing this will take quite some as it builds the whole container. +After building the container it will spin up kindev, which will also take some time. + +Once it's finished there should be a ready to go dev environment to use. + +The container will contain: +* go +* helm +* kubectl +* yq +* kubecolor + +Additionally it will install some useful extensions for vscode to make development easier. + +### Devcontainer customizations + +It's possible to customize the devcontainer. +By setting `"terminal.integrated.defaultProfile.linux": "zsh"` in the vscode config, it's possible to switch the default shell to zsh. + +It's also possible to provide your own dotfiles. They will be installed after the kindev setup has finished. +For that, simply write a small script that contains all your desired configurations and put it in a publicly available repository. +Here's an example repo: https://github.com/lugoues/vscode-dev-containers-dotfiles + +After that set this configuration in vscode: +``` +{ + "dotfiles.repository": "your-github-id/your-dotfiles-repo", + "dotfiles.targetPath": "~/dotfiles", + "dotfiles.installCommand": "install.sh" +} +``` + + ## Generate Kubernetes code, XRDs with Go / KubeBuilder In `/apis` there is code in Go to generate the XRDs (composites) as this is in OpenAPI.