diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile deleted file mode 100644 index 22e7acd..0000000 --- a/.devcontainer/Containerfile +++ /dev/null @@ -1,45 +0,0 @@ -FROM docker.io/ubuntu:24.04 -ARG TARGETARCH - -RUN rm -rf /home/ubuntu - -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - apt-transport-https \ - ca-certificates \ - curl \ - wget \ - gnupg \ - git - -# Fetch kubectl -RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl" && \ - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl.sha256" && \ - echo "$(cat kubectl.sha256) kubectl" | sha256sum --check && \ - install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \ - rm kubectl kubectl.sha256 - -# Install kubecolor for some colour https://kubecolor.github.io/ -RUN wget -O /tmp/kubecolor.deb https://kubecolor.github.io/packages/deb/pool/main/k/kubecolor/kubecolor_$(wget -q -O- https://kubecolor.github.io/packages/deb/version)_$(dpkg --print-architecture).deb && \ - dpkg -i /tmp/kubecolor.deb && \ - apt update && \ - rm /tmp/kubecolor.deb - -RUN adduser homelab -USER homelab - -# Install krew, a plugin manager for kubectl https://krew.sigs.k8s.io/ -RUN (set -x; cd "$(mktemp -d)" && \ - KREW="krew-linux_${TARGETARCH}" && \ - curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && \ - tar zxvf "${KREW}.tar.gz" && \ - ./"${KREW}" install krew ) && \ - echo "export PATH=\"${KREW_ROOT:-$HOME/.krew}/bin:$PATH\"" >> ${HOME}/.bashrc - -RUN PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" kubectl krew install ctx ns oidc-login - -RUN echo "alias k='kubectl'" >> ${HOME}/.bash_aliases && \ - echo "alias kubectl='kubecolor'" >> ${HOME}/.bash_aliases && \ - echo "alias tf='tofu'" >> ${HOME}/.bash_aliases - -USER root diff --git a/.devcontainer/README.md b/.devcontainer/README.md index 0a75826..0a5cd14 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -1,9 +1,10 @@ # Devcontainer -The `devcontainer.json` file uses a pre-built image based on the configuration in the `devcontainer-build.json` file. +The `devcontainer.json` file uses a pre-built image based on the configuration in the `./.github/.devcontainer` +directory. Check available Devcontainer features at [https://containers.dev/features](https://containers.dev/features), -or edit the `Containerfile`. +or edit the `Containerfile` there. **Disclaimer**: this is a fairly untested feature from the main author, feedback is welcome. @@ -19,7 +20,7 @@ Alternatively, you can start the devcontainer manually by running ```shell docker run -it --rm \ - --user $(id -u):$(id -g) \ + --user dev \ --name homelab-devcontainer \ --mount target=/tmp,type=tmpfs \ --mount type=bind,src=.,dst=/workspace \ diff --git a/.devcontainer/devcontainer-build.json b/.devcontainer/devcontainer-build.json deleted file mode 100644 index 08a8802..0000000 --- a/.devcontainer/devcontainer-build.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "Stonegarden Homelab Devcontainer", - "build": { - "dockerfile": "Containerfile" - }, - "features": { - "ghcr.io/devcontainers/features/common-utils:2": { - "installZsh": true, - "configureZshAsDefaultShell": true, - "installOhMyZsh": true, - "installOhMyZshConfig": true, - "upgradePackages": true, - "username": "homelab" - }, - "ghcr.io/devcontainers/features/github-cli:1": {}, - "ghcr.io/devcontainers/features/java:1": {}, - "ghcr.io/devcontainers-extra/features/argo-cd:1": {}, - "ghcr.io/devcontainers-extra/features/talosctl:1": {}, - "ghcr.io/devcontainers-extra/features/yamllint:2": {}, - "ghcr.io/dhoeric/features/k9s:1": {}, - "ghcr.io/eitsupi/devcontainer-features/jq-likes": { - "jqVersion": "latest", - "yqVersion": "latest" - }, - "ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {}, - "ghcr.io/robbert229/devcontainer-features/opentofu:1": {} - }, - "remoteUser": "homelab" -} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7473006..f259933 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -8,5 +8,5 @@ "type": "bind" } ], - "remoteUser": "homelab" + "remoteUser": "dev" } diff --git a/.github/.devcontainer/Containerfile b/.github/.devcontainer/Containerfile new file mode 100644 index 0000000..ac1a068 --- /dev/null +++ b/.github/.devcontainer/Containerfile @@ -0,0 +1,106 @@ +FROM docker.io/ubuntu:24.04 +ARG TARGETARCH + +RUN rm -rf /home/ubuntu + +RUN apt update && \ + apt install -y --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + wget \ + gnupg \ + git \ + jq \ + yamllint && \ + apt clean + +# Add GitHub CLI repo +RUN mkdir -p -m 755 /etc/apt/keyrings && \ + mkdir -p -m 755 /etc/apt/sources.list.d && \ + curl https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null && \ + chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg && \ + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null + +# Add Adoption repo for JRE needed by IDEA devcontainer +RUN curl -sSL https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null && \ + echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list + +# Add Postgresql repo +RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null && \ + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/apt.postgresql.org.gpg] https://apt.postgresql.org/pub/repos/apt $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release)-pgdg main" > /etc/apt/sources.list.d/pgdg.list + +# Add OpenTofu repo +RUN curl -fsSL https://get.opentofu.org/opentofu.gpg | tee /etc/apt/keyrings/opentofu.gpg > /dev/null && \ + curl -fsSL https://packages.opentofu.org/opentofu/tofu/gpgkey | gpg --no-tty --batch --dearmor -o /etc/apt/keyrings/opentofu-repo.gpg > /dev/null && \ + chmod a+r /etc/apt/keyrings/opentofu.gpg /etc/apt/keyrings/opentofu-repo.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main \ + deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" | \ + tee /etc/apt/sources.list.d/opentofu.list > /dev/null && \ + chmod a+r /etc/apt/sources.list.d/opentofu.list + +# Install packages from added repos +RUN apt update && \ + apt install -y --no-install-recommends \ + gh \ + temurin-21-jre \ + postgresql-client \ + tofu && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +# Install kubectl +RUN curl -sSLO "https://dl.k8s.io/release/$(curl -sSL https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl" && \ + curl -sSLO "https://dl.k8s.io/release/$(curl -sSL https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl.sha256" && \ + echo "$(cat kubectl.sha256) kubectl" | sha256sum --check && \ + install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \ + rm kubectl kubectl.sha256 + + # Install kubecolor for some colour https://kubecolor.github.io/ +RUN curl -sSL -o kubecolor.deb "https://kubecolor.github.io/packages/deb/pool/main/k/kubecolor/kubecolor_$(curl -sSL https://kubecolor.github.io/packages/deb/version)_${TARGETARCH}.deb" && \ + dpkg -i kubecolor.deb && \ + rm kubecolor.deb + +# Install k9s +RUN curl -sSL -o k9s.deb "https://github.com/derailed/k9s/releases/latest/download/k9s_Linux_${TARGETARCH}.deb" && \ + dpkg -i k9s.deb && \ + rm k9s.deb + +# Install Argo CD CLI +RUN curl -sSL -o argocd "https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-${TARGETARCH}" && \ + install -o root -g root -m 0755 argocd /usr/local/bin/argocd && \ + rm argocd + +# Install yq +RUN curl -sSL -o yq "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_${TARGETARCH}" && \ + install -o root -g root -m 0755 yq /usr/local/bin/yq && \ + rm yq + +# Install talosctl +RUN curl -sSL -o talosctl "https://github.com/siderolabs/talos/releases/latest/download/talosctl-linux-${TARGETARCH}" && \ + install -o root -g root -m 0755 talosctl /usr/local/bin/talosctl && \ + rm talosctl + +RUN adduser dev +USER dev + +# Install krew, a plugin manager for kubectl https://krew.sigs.k8s.io/ +RUN (cd "$(mktemp -d)" && \ + curl -sSL -o krew.tar.gz "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew-linux_${TARGETARCH}.tar.gz" && \ + tar zxvf krew.tar.gz && \ + ./krew-linux_${TARGETARCH} install krew && \ + rm *) && \ + echo "export PATH=\"${KREW_ROOT:-$HOME/.krew}/bin:$PATH\"" >> ${HOME}/.bashrc + +# Install kubectl plugins for easy switching of context and namespace, as well as OIDC login +RUN PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" kubectl krew install ctx ns oidc-login + +# Alias everything +RUN echo "alias kubectl='kubecolor'" >> ${HOME}/.bash_aliases && \ + echo "alias k='kubectl'" >> ${HOME}/.bash_aliases && \ + echo "alias kz='kubectl kustomize --enable-helm'" >> ${HOME}/.bash_aliases && \ + echo "alias tf='tofu'" >> ${HOME}/.bash_aliases && \ + echo "alias tl='talosctl'" >> ${HOME}/.bash_aliases && \ + echo "alias yl='yamllint'" >> ${HOME}/.bash_aliases + +USER root diff --git a/.github/.devcontainer/devcontainer.json b/.github/.devcontainer/devcontainer.json new file mode 100644 index 0000000..cc087a8 --- /dev/null +++ b/.github/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "Stonegarden Homelab Devcontainer", + "build": { + "dockerfile": "Containerfile" + }, + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": true, + "configureZshAsDefaultShell": true, + "installOhMyZsh": true, + "installOhMyZshConfig": true, + "upgradePackages": true, + "username": "dev" + }, + }, + "remoteUser": "dev" +} diff --git a/.github/workflows/build-devcontainer.yaml b/.github/workflows/build-devcontainer.yaml index 2c6ff53..00dd3aa 100644 --- a/.github/workflows/build-devcontainer.yaml +++ b/.github/workflows/build-devcontainer.yaml @@ -3,7 +3,7 @@ name: Build devcontainer on: push: branches: [ main ] - paths: [ '.devcontainer/**' ] + paths: [ '.github/.devcontainer/**' ] schedule: - cron: '4 20 28 * *' @@ -36,7 +36,7 @@ jobs: - name: Pre-build dev container image uses: devcontainers/ci@8bf61b26e9c3a98f69cb6ce2f88d24ff59b785c6 #v0.3.1900000417 with: - configFile: ./.devcontainer/devcontainer-build.json + subFolder: ./.github platform: linux/amd64,linux/arm64 imageName: ghcr.io/vehagn/homelab-devcontainer cacheFrom: ghcr.io/vehagn/homelab-devcontainer