Skip to content

Commit

Permalink
Merge pull request #14 from donkeyx/fix-build-process
Browse files Browse the repository at this point in the history
fix: switched to slim and updated docker image
  • Loading branch information
donkeyx authored Jun 15, 2024
2 parents bea26ce + cd90071 commit 551018c
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 140 deletions.
140 changes: 49 additions & 91 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 38 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
FROM alpine
# Description: Dockerfile for the Sleeper service
FROM debian:buster-slim

# Metadata
ARG VERSION=latest
LABEL maintainer="David Binney <donkeysoft@gmail.com>"
LABEL version=$VERSION
LABEL description="This container is a utility for testing within cluster or networks and not needing to install tooling"

# 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 \
git jq vim tmux zsh \
postgresql-client redis mongodb-tools \
git nodejs

RUN ./kickstart.sh
# 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/*

ENTRYPOINT ["sh", "/app/sleeper.sh"]
RUN apt-get update && apt-get install -y \
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/*

RUN ./kickstart.sh

ENTRYPOINT ["zsh", "/app/sleeper.sh"]
56 changes: 37 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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
```
23 changes: 13 additions & 10 deletions k8s-cluster-utils.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 26 additions & 7 deletions kickstart.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > ~/customfetch
#!/usr/bin/env sh
screenfetch
cat <<INFO
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
INFO
EOF

# echo "screenfetch" >> ~/.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/*

0 comments on commit 551018c

Please sign in to comment.