From 1e8bd6bd42cddf668b605101c94ed2a38125c333 Mon Sep 17 00:00:00 2001 From: David Binney Date: Thu, 13 Jun 2024 20:39:51 +0930 Subject: [PATCH 1/3] fix: switched to slim and updated docker image --- .github/workflows/docker-build-push.yml | 140 +++++++++--------------- Dockerfile | 30 ++--- k8s-cluster-utils.yml | 2 +- 3 files changed, 67 insertions(+), 105 deletions(-) diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml index f523306..66c03fe 100644 --- a/.github/workflows/docker-build-push.yml +++ b/.github/workflows/docker-build-push.yml @@ -2,111 +2,69 @@ name: Docker build and push on: push: - branches: [ $default-branch, 'release/*'] - tags: [ 'v*.*.*' ] - pull_request: - branches: [ $default-branch ] - -env: - IMAGE_NAME: ${{ github.repository }} - + tags: + - "v*" jobs: - build: - environment: deployment # this gets the secrets for deployments + cache: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }} + docker: + needs: cache runs-on: ubuntu-latest permissions: - contents: read + contents: write packages: write id-token: write - steps: - name: Checkout repository - uses: actions/checkout@v3 - - - - name: Capture build vars - id: vars - shell: bash - run: | - git_ref=$(echo ${GITHUB_REF#refs/*/}| tr "/" "-" ) - hash=${GITHUB_SHA::6} - - if [ "$GITHUB_REF_TYPE" == "tag" ]; then - echo "processing tag" - docker_tag="$git_ref" - - echo "docker tag string latest" - latest_tag=" -t \donkeyx/cluster-utils:latest" - - fi + uses: actions/checkout@v4 - if [ "$GITHUB_REF_TYPE" == "branch" ]; then - echo "processing branch" + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - if [ "$git_ref" == "master" ]; then - echo "match latest" - docker_tag=latest - fi - - docker_tag="${git_ref}" - fi - - echo "branch: $git_ref" - echo "hash: $hash" - echo "dockertag: $docker_tag" - - echo "::set-output name=git_ref::$git_ref" - echo "::set-output name=sha_short::$hash" - echo "::set-output name=docker_tag::$docker_tag" - echo "::set-output name=latest_tag::$latest_tag" - - # for multi architecture builds arm/x86 - - name: Setup qumu runner - uses: docker/setup-qemu-action@v1 - - - name: Setup Docker buildx - uses: docker/setup-buildx-action@v1 - - # ################################ - # push docker images (dockerhub/github) - # ################################ - - name: Log into registry (dockerhub) - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_PASS }} - logout: true - - - - name: Build and push docker image (dockerhub) - run: | - - docker buildx build \ - --platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \ - -t "donkeyx/cluster-utils:${{ steps.vars.outputs.docker_tag }}" \ - ${{ steps.vars.outputs.latest_tag }} \ - --push \ - . - - - - name: Log into registry (github) - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - logout: true - - - name: Build and push docker image (github) - run: | - docker buildx build \ - --platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \ - -t "ghcr.io/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }}" \ - ${{ steps.vars.outputs.latest_tag }} \ - --push \ - . + - name: Docker meta (GHCR) + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/donkeyx/cluster-utils + docker.io/donkeyx/cluster-utils + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + build-args: VERSION=${{ env.VERSION }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/Dockerfile b/Dockerfile index 4a4e271..640bd9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,27 @@ -FROM alpine +# Description: Dockerfile for the Sleeper service +FROM debian:slim + +# Metadata +ARG VERSION=latest +LABEL maintainer="David Binney " +LABEL version=$VERSION +LABEL description="This is a custom Docker image for the Sleeper service." -# ENV LANG en_AU.UTF-8 -# ENV LANGUAGE en_AU.UTF-8 -# ENV LC_ALL en_AU.UTF-8 -# ENV LC_CTYPE=en_AU.UTF-8 ENV TZ="Australia/Adelaide" -# ENV DEBIAN_FRONTEND "noninteractive apt-get autoremove" WORKDIR /app COPY ./*.sh /app/ -RUN apk add --no-cache \ - bind-tools netcat-openbsd curl \ +RUN apt-get update && apt-get install -y \ + dnsutils netcat curl \ git jq vim tmux zsh \ - postgresql-client redis mongodb-tools \ - git nodejs + postgresql-client redis-tools mongodb-tools \ + git nodejs npm golang && \ + npm install -g yarn && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + chsh -s $(which zsh) RUN ./kickstart.sh - -ENTRYPOINT ["sh", "/app/sleeper.sh"] - +ENTRYPOINT ["sh", "/app/sleeper.sh"] \ No newline at end of file diff --git a/k8s-cluster-utils.yml b/k8s-cluster-utils.yml index 269171b..0f5cb28 100644 --- a/k8s-cluster-utils.yml +++ b/k8s-cluster-utils.yml @@ -3,6 +3,7 @@ kind: Pod metadata: name: cluster-utils labels: + app: cluster-utils purpose: testing spec: containers: @@ -12,4 +13,3 @@ spec: - name: RUNTIME value: "1800" restartPolicy: Never - From dd7f67858ac1949eac3c541be3e8f073658b835b Mon Sep 17 00:00:00 2001 From: David Binney Date: Sat, 15 Jun 2024 11:25:09 +0930 Subject: [PATCH 2/3] fix: cleanup readme, use debian and update docs --- Dockerfile | 41 ++++++++++++++++++++++++++++---------- README.md | 56 ++++++++++++++++++++++++++++++++++------------------ kickstart.sh | 33 ++++++++++++++++++++++++------- 3 files changed, 94 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index 640bd9d..d9a2f46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,48 @@ # Description: Dockerfile for the Sleeper service -FROM debian:slim +FROM debian:buster-slim # Metadata ARG VERSION=latest LABEL maintainer="David Binney " LABEL version=$VERSION -LABEL description="This is a custom Docker image for the Sleeper service." +LABEL description="This container is a utility for testing within cluster or networks and not needing to install tooling" ENV TZ="Australia/Adelaide" WORKDIR /app COPY ./*.sh /app/ + +# Update and install basic tools +RUN apt-get update && apt-get install -y \ + dnsutils netcat curl wget tar gnupg vim tmux zsh screenfetch && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install database clients +RUN apt-get update && apt-get install -y \ + postgresql-client redis-tools && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install programming languages and tools +RUN apt-get update && apt-get install -y \ + git golang && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + RUN apt-get update && apt-get install -y \ - dnsutils netcat curl \ - git jq vim tmux zsh \ - postgresql-client redis-tools mongodb-tools \ - git nodejs npm golang && \ - npm install -g yarn && \ + nodejs npm && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install MongoDB tools +RUN wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add - && \ + echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list && \ + apt-get update && apt-get install -y mongodb-org-tools && \ apt-get clean && \ - rm -rf /var/lib/apt/lists/* && \ - chsh -s $(which zsh) + rm -rf /var/lib/apt/lists/* RUN ./kickstart.sh -ENTRYPOINT ["sh", "/app/sleeper.sh"] \ No newline at end of file +ENTRYPOINT ["zsh", "/app/sleeper.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 84e39bc..f8b19c7 100644 --- a/README.md +++ b/README.md @@ -32,24 +32,39 @@ cluster-utils 1/1 Running 0 2m18s Now the pod is running, you can exec into it and.. do whatever you need within the context of your cluster/namespace. ```bash -# jump into container with zsh shell + ohmyzsh - ................ root@5341f0387b50 - ∴::::::::::::::::∴ OS: Alpine Linux - ∴::::::::::::::::::∴ Kernel: x86_64 Linux 4.19.76-linuxkit - ∴::::::::::::::::::::∴ Uptime: 6d 19h 30m - ∴:::::::. :::::':::::::∴ Packages: 67 - ∴:::::::. ;::; ::::::::∴ Shell: ash - ∴::::::; ∵ :::::::∴ Disk: / () - ∴:::::. . .::::::∴ CPU: Intel Core i7-7700HQ @ 4x 2.8GHz - :::::: :::. . :::::: RAM: 463MiB / 1991MiB - ∵:::: ::::::. ::. ::::∵ - ∵:.. .:;::::::: :::. :::∵ - ∵::::::::::::::::::::::::∵ - ∵::::::::::::::::::::::∵ - ∵::::::::::::::::::::∵ - :::::::::::::::::::: - ∵::::::::::::::::∵ - +$ kubectl exec -it cluster-utils -- zsh + +awk: cannot open /proc/fb (No such file or directory) + _,met$$$$$gg. root@c8b5eabe6232 + ,g$$$$$$$$$$$$$$$P. OS: Debian 10 buster + ,g$$P"" """Y$$.". Kernel: x86_64 Linux 5.15.153.1-microsoft-standard-WSL2 + ,$$P' `$$$. Uptime: 14h 13m + ',$$P ,ggs. `$$b: Packages: 546 + `d$$' ,$P"' . $$$ Shell: sh + $$P d$' , $$P CPU: AMD Ryzen 5 3600 6-Core @ 12x 3.6GHz + $$: $$. - ,d$$' GPU: + $$\; Y$b._ _,d$P' RAM: 1957MiB / 15959MiB + Y$$. `.`"Y$$$$P"' + `$$b "-.__ + `Y$$ + `Y$$. + `$$b. + `Y$$b. + `"Y$b._ + `"""" + +This container is useful for cluster and network testing with many tools. + +database connection tools: +- psql, redis-cli, mongo +network testing tools: +- curl, wget, ping, traceroute, mtr, nmap, tcpdump, netcat +performance testing tools: +- vegeta, k6 +programming languages: +- golang, python, nodejs +shell: +- zsh with oh-my-zsh ``` @@ -96,7 +111,10 @@ nc -z -v -w5 10.1.1.51 8080 # check dns dig google.com +# curl your internal service +curl my-internal-service.default.cluster.local | jq + # traceroute path for request -traceroute my-internal-service.com +traceroute my-internal-service.default.cluster.local ``` diff --git a/kickstart.sh b/kickstart.sh index de71d88..bbd7dfd 100755 --- a/kickstart.sh +++ b/kickstart.sh @@ -1,21 +1,40 @@ #!/usr/bin/env sh -set -eou pipefail +set -eu pipefail # # decent prompt echo "--- prompt setup zsh ---" -apk add --no-cache zsh sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" curl -sS -L https://github.com/tsenart/vegeta/releases/download/v12.8.3/vegeta-12.8.3-linux-amd64.tar.gz | tar -xz mv vegeta /usr/local/bin -# apk add --no-cache screenfetch --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing +# Create a new script that runs screenfetch and then prints the additional information +cat < ~/customfetch +#!/usr/bin/env sh +screenfetch +cat <> ~/.zshrc -# echo "export PATH=$HOME/go/bin:$PATH" >> ~/.zshrc +chmod +x ~/customfetch +# Add customfetch to .zshrc so it runs whenever a new shell starts +echo "~/customfetch" >> ~/.zshrc +echo "export PATH=$HOME/go/bin:$PATH" >> ~/.zshrc echo "--- cleanup ---" -rm -rf /var/cache/apk/* && \ - rm -rf /tmp/* +apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* \ No newline at end of file From cd9007117ffacd7543da996f92be65c7e5230c92 Mon Sep 17 00:00:00 2001 From: David Binney Date: Sat, 15 Jun 2024 11:30:43 +0930 Subject: [PATCH 3/3] fix: moved the kubes manifest to a job so it will autokill --- k8s-cluster-utils.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/k8s-cluster-utils.yml b/k8s-cluster-utils.yml index 0f5cb28..8c3e144 100644 --- a/k8s-cluster-utils.yml +++ b/k8s-cluster-utils.yml @@ -1,15 +1,18 @@ -apiVersion: v1 -kind: Pod +apiVersion: batch/v1 +kind: Job metadata: name: cluster-utils labels: app: cluster-utils purpose: testing spec: - containers: - - name: cluster-utils - image: donkeyx/cluster-utils:latest - env: - - name: RUNTIME - value: "1800" - restartPolicy: Never + template: + spec: + containers: + - name: cluster-utils + image: donkeyx/cluster-utils:latest + env: + - name: RUNTIME + value: "1800" + restartPolicy: Never + ttlSecondsAfterFinished: 1800