From f24a4fa24ebe93b680c1e7399ed09614663ecf1b Mon Sep 17 00:00:00 2001 From: Alexander Gschrei Date: Tue, 15 Jun 2021 22:35:47 +0200 Subject: [PATCH] added k8s image --- .github/workflows/main.yml | 8 +++++++- README.md | 8 +++++++- base/.zshrc | 4 ++-- base/Dockerfile | 18 +++++++++++++----- k8s/Dockerfile | 22 ++++++++++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 k8s/Dockerfile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8ba4334..05ff7fb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,8 +32,14 @@ jobs: - name: login docker hub run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin # Runs a set of commands using the runners shell - - name: build image + - name: build base image run: | docker buildx build --push \ --tag agschrei/productivity-images:base \ --platform linux/amd64,linux/arm64 base + - name: build k8s image + run: | + docker buildx build --push \ + --tag agschrei/productivity-images:k8s \ + --platform linux/amd64,linux/arm64 k8s + diff --git a/README.md b/README.md index f927b8e..56513ce 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,10 @@ This is the bare minimum I want to have in an interactive image, is based on ubu - zsh (set up with [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) and the [p10k](https://github.com/romkatv/powerlevel10k) theme) - build-essential (including gcc and make) -To make installation of additional packages easier, the default user for this image is root. \ No newline at end of file +To make installation of additional packages easier, the default user for this image is root. + +## K8s image +This image adds on top of the minimal base image and provides the following: +- kubectl +- helm +A kubeconfig file is expected to be mounted at k8s/config \ No newline at end of file diff --git a/base/.zshrc b/base/.zshrc index 8fcf0b1..9028cf5 100644 --- a/base/.zshrc +++ b/base/.zshrc @@ -9,7 +9,7 @@ fi # export PATH=$HOME/bin:/usr/local/bin:$PATH # Path to your oh-my-zsh installation. -export ZSH="/root/.oh-my-zsh" +export ZSH="/home/debug/.oh-my-zsh" # Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, @@ -17,7 +17,7 @@ export ZSH="/root/.oh-my-zsh" # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes ZSH_THEME="powerlevel10k/powerlevel10k" -plugins=(git ansible docker python ubuntu) +plugins=(git ansible docker python ubuntu helm kubectl) source $ZSH/oh-my-zsh.sh diff --git a/base/Dockerfile b/base/Dockerfile index 7c632f2..3a62e3c 100644 --- a/base/Dockerfile +++ b/base/Dockerfile @@ -12,13 +12,21 @@ LABEL org.opencontainers.image.documentation="https://github.com/agschrei/produc LABEL org.opencontainers.image.source="https://github.com/agschrei/productivity-images.git" LABEL org.opencontainers.image.licenses="MIT" -RUN apt update && apt upgrade -y && apt install zsh curl git htop build-essential ca-certificates dpkg-dev jq python3 python3-pip fonts-powerline -y --no-install-recommends +RUN apt update && apt upgrade -y && apt install zsh curl git htop build-essential tmux vim ca-certificates dpkg-dev jq python3 python3-pip fonts-powerline -y --no-install-recommends -# change default shell to zsh -RUN chsh -s $(which zsh) -RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +ARG username=debug + +# add non-root user and set zsh as default shell +RUN useradd -m ${username} -s $(which zsh) + +WORKDIR /home/${username} + +USER ${username}:0 + +# install oh-my-zsh +RUN ZSH=/home/${username}/.oh-my-zsh; sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" RUN git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k -COPY *.zsh* ./ +COPY --chown=${username}:0 *.zsh* ./ ENTRYPOINT [ "/bin/zsh" ] \ No newline at end of file diff --git a/k8s/Dockerfile b/k8s/Dockerfile new file mode 100644 index 0000000..de02def --- /dev/null +++ b/k8s/Dockerfile @@ -0,0 +1,22 @@ +FROM agschrei/productivity-images:base +# install kubectl and verify the binary +ARG TARGETARCH +ARG HELM_VERSION=3.6.0 +# the expected mount location for kubectl config +ENV KUBECONFIG k8s/config +RUN printenv +RUN echo "Installing kubectl binary for ${TARGETARCH}" &&\ + 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/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl.sha256" &&\ + echo "$(cat kubectl.sha256) kubectl" | sha256sum --check &&\ + rm kubectl.sha256 &&\ + chmod +x ./kubectl &&\ + mkdir -p ~/.local/bin/ &&\ + mv ./kubectl ~/.local/bin/ +RUN echo "Installing helm binary for ${TARGETARCH}" && \ + curl -LO https://get.helm.sh/helm-v${HELM_VERSION}-linux-${TARGETARCH}.tar.gz &&\ + curl -LO https://get.helm.sh/helm-v${HELM_VERSION}-linux-${TARGETARCH}.tar.gz.sha256sum &&\ + cat helm-v${HELM_VERSION}-linux-${TARGETARCH}.tar.gz.sha256sum | shasum --check &&\ + tar -zxvf helm-v${HELM_VERSION}-linux-${TARGETARCH}.tar.gz &&\ + mv linux-${TARGETARCH}/helm ~/.local/bin/ && rm -rf helm-* linux-* +RUN echo "PATH=~/.local/bin/:$PATH" >> .zshrc \ No newline at end of file