From 4bd8ce5f8c229e41375cc2aa543adeeb8be116a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfred=20G=C3=B6ppel?= <43101280+alfi0812@users.noreply.github.com> Date: Wed, 25 Jun 2025 18:29:35 +0200 Subject: [PATCH] fix(devcontainer): Make independent devcontainer & try to avoid version dependency (#36651) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code - [ ] 📜 Documentation Changes **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made changes to the documentation - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning - [ ] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):`, `chore(chart-name):`, `docs(chart-name):` or `fix(docs):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Signed-off-by: Alfred Göppel <43101280+alfi0812@users.noreply.github.com> --- .devcontainer/devcontainer.json | 1 - .devcontainer/postCreateCommand.sh | 19 ++-- .github/renovate/main.json5 | 3 +- .github/renovate/special/devcontainer.json5 | 18 ++++ .../DOTREPLACEdevcontainer/devcontainer.json | 1 - .../postCreateCommand.sh | 19 ++-- containers/apps/devcontainer/Dockerfile | 89 ++++++++++++++----- containers/apps/devcontainer/VERSION | 1 - containers/apps/devcontainer/get-version.sh | 3 + .../apps/devcontainer/latest-version.sh | 1 - 10 files changed, 118 insertions(+), 37 deletions(-) create mode 100644 .github/renovate/special/devcontainer.json5 delete mode 100644 containers/apps/devcontainer/VERSION create mode 100644 containers/apps/devcontainer/get-version.sh delete mode 100755 containers/apps/devcontainer/latest-version.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 670b08d4952..332ee677509 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,6 @@ "$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.schema.json", "name": "TrueCharts", "image": "tccr.io/tccr/devcontainer:v2.0.0@sha256:d8a12070a88e36cf1eb5b14fbeb1d5c866a1e5f8b52cc9e5989fb7f53c154b2b", - "initializeCommand": "docker pull tccr.io/tccr/devcontainer:v2.0.0", "postCreateCommand": { "setup": "bash ${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" }, diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh index 4cc64c13890..0ec4bff56ab 100755 --- a/.devcontainer/postCreateCommand.sh +++ b/.devcontainer/postCreateCommand.sh @@ -12,9 +12,18 @@ fisher install nickeb96/puffer-fish fisher install PatrickF1/fzf.fish " -kubectl krew install pv-mounter +( + set -x; cd "$(mktemp -d)" && + OS="$(uname | tr '[:upper:]' '[:lower:]')" && + ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" && + KREW="krew-${OS}_${ARCH}" && + curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && + tar zxvf "${KREW}.tar.gz" && + ./"${KREW}" install krew +) -# Create/update virtual environment -if ! grep -q "venv /workspaces/" .venv/pyvenv.cfg; then - rm -rf .venv -fi +export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" + +kubectl krew install pv-mounter +kubectl krew install cnpg +kubectl krew install df-pv diff --git a/.github/renovate/main.json5 b/.github/renovate/main.json5 index e018627a696..5f58516b21d 100644 --- a/.github/renovate/main.json5 +++ b/.github/renovate/main.json5 @@ -36,7 +36,8 @@ "github>truecharts/public//.github/renovate/special/customClusterManagers.json5", "github>truecharts/public//.github/renovate/special/customRules.json5", "github>truecharts/public//.github/renovate/special/customVersioning.json5", - "github>truecharts/public//.github/renovate/special/customTalosClustertool.json5" + "github>truecharts/public//.github/renovate/special/customTalosClustertool.json5", + "github>truecharts/public//.github/renovate/special/devcontainer.json5" ], // Main Renovate configuration that lists package rules for various paths "packageRules": [ diff --git a/.github/renovate/special/devcontainer.json5 b/.github/renovate/special/devcontainer.json5 new file mode 100644 index 00000000000..d913c95c43d --- /dev/null +++ b/.github/renovate/special/devcontainer.json5 @@ -0,0 +1,18 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "customManagers": [ + { + "customType": "regex", + "managerFilePatterns": [ + "/Dockerfile$/" + ], + "matchStrings": [ + "ARG CLUSTERTOOL_VERSION=(?[0-9.]+)" + ], + "datasourceTemplate": "github-releases", + "packageNameTemplate": "truecharts/public", + "versioningTemplate": "semver", + "extractVersionTemplate": "^v(?.*)$" + } + ] +} diff --git a/clustertool/embed/generic/root/DOTREPLACEdevcontainer/devcontainer.json b/clustertool/embed/generic/root/DOTREPLACEdevcontainer/devcontainer.json index a619188a8ad..08f84dc0642 100644 --- a/clustertool/embed/generic/root/DOTREPLACEdevcontainer/devcontainer.json +++ b/clustertool/embed/generic/root/DOTREPLACEdevcontainer/devcontainer.json @@ -2,7 +2,6 @@ "$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.schema.json", "name": "ClusterTool Cluster", "image": "tccr.io/tccr/devcontainer:v2.0.0@sha256:d8a12070a88e36cf1eb5b14fbeb1d5c866a1e5f8b52cc9e5989fb7f53c154b2b", - "initializeCommand": "docker pull tccr.io/tccr/devcontainer:v2.0.0", "postCreateCommand": { "setup": "bash ${containerWorkspaceFolder}/.devcontainer/postCreateCommand.sh" }, diff --git a/clustertool/embed/generic/root/DOTREPLACEdevcontainer/postCreateCommand.sh b/clustertool/embed/generic/root/DOTREPLACEdevcontainer/postCreateCommand.sh index 4cc64c13890..0ec4bff56ab 100755 --- a/clustertool/embed/generic/root/DOTREPLACEdevcontainer/postCreateCommand.sh +++ b/clustertool/embed/generic/root/DOTREPLACEdevcontainer/postCreateCommand.sh @@ -12,9 +12,18 @@ fisher install nickeb96/puffer-fish fisher install PatrickF1/fzf.fish " -kubectl krew install pv-mounter +( + set -x; cd "$(mktemp -d)" && + OS="$(uname | tr '[:upper:]' '[:lower:]')" && + ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" && + KREW="krew-${OS}_${ARCH}" && + curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && + tar zxvf "${KREW}.tar.gz" && + ./"${KREW}" install krew +) -# Create/update virtual environment -if ! grep -q "venv /workspaces/" .venv/pyvenv.cfg; then - rm -rf .venv -fi +export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" + +kubectl krew install pv-mounter +kubectl krew install cnpg +kubectl krew install df-pv diff --git a/containers/apps/devcontainer/Dockerfile b/containers/apps/devcontainer/Dockerfile index 4eacd45d45f..eac0e9507ef 100644 --- a/containers/apps/devcontainer/Dockerfile +++ b/containers/apps/devcontainer/Dockerfile @@ -1,44 +1,89 @@ # hadolint ignore=DL3007 -FROM ghcr.io/onedr0p/cluster-template/devcontainer:latest@sha256:90bd47adcf1ac31e8d60e028e521db7a203a16186685546c298a5bb5e7ff642b +FROM mcr.microsoft.com/devcontainers/base:alpine -ARG VERSION +ARG CLUSTERTOOL_VERSION=2.0.0 ARG CONTAINER_NAME -ARG CONTAINER_VER # hadolint ignore=DL3008,DL3015,SC2086,SC2155 -RUN \ -apk update && \ - apk --no-cache update && \ +RUN apk update && \ apk --no-cache add \ - sshfs \ - libc6-compat \ - fuse && \ + age bash bind-tools ca-certificates curl direnv fish fzf \ + gettext git github-cli helm iputils jq k9s kubectl kustomize \ + python3 py3-pip moreutils openssh-client openssl starship yq \ + sshfs libc6-compat fuse && \ rm -rf /var/cache/apk/* /tmp/* /var/tmp/* +# Install CLI tools via jpillora scripts +RUN for app in \ + "budimanjojo/talhelper!!?as=talhelper&type=script" \ + "fluxcd/flux2!!?as=flux&type=script" \ + "helmfile/helmfile!!?as=helmfile&type=script" \ + "kubecolor/kubecolor!!?as=kubecolor&type=script" \ + "kubernetes-sigs/krew!!?as=krew&type=script" \ + "siderolabs/talos!!?as=talosctl&type=script"; \ + do \ + echo "=== Installing ${app} ==="; \ + curl -fsSL "https://i.jpillora.com/${app}" | bash; \ + done + +# Create the completions and conf.d directories explicitly +RUN mkdir -p /home/vscode/.config/fish/completions && \ + mkdir -p /home/vscode/.config/fish/conf.d + +# Add completions only if the command exists +RUN for tool in cilium flux helm helmfile k9s kubectl kustomize talhelper talosctl; do \ + if command -v "$tool" >/dev/null 2>&1; then \ + mkdir -p /home/vscode/.config/fish/completions && \ + $tool completion fish > "/home/vscode/.config/fish/completions/${tool}.fish" || true; \ + fi; \ + done && \ + gh completion --shell fish > /home/vscode/.config/fish/completions/gh.fish || true && \ + stern --completion fish > /home/vscode/.config/fish/completions/stern.fish || true && \ + yq shell-completion fish > /home/vscode/.config/fish/completions/yq.fish || true + +RUN mkdir -p /home/vscode/.config/fish/conf.d && \ + printf '%s\n' \ + "if status is-interactive" \ + " direnv hook fish | source" \ + " starship init fish | source" \ + "end" \ + > /home/vscode/.config/fish/conf.d/hooks.fish + +# Add aliases to fish config +RUN mkdir -p /home/vscode/.config/fish/conf.d && \ + printf '%s\n' \ + "alias kubectl kubecolor" \ + "alias k kubectl" \ + > /home/vscode/.config/fish/conf.d/aliases.fish + +# Custom fish prompt +RUN mkdir -p /home/vscode/.config/fish/conf.d && \ + echo "set fish_greeting" > /home/vscode/.config/fish/conf.d/fish_greeting.fish + +# Setup direnv whitelist +RUN mkdir -p /home/vscode/.config/direnv && \ + tee /home/vscode/.config/direnv/direnv.toml > /dev/null <