Skip to content

Commit

Permalink
Merge pull request #62 from mpepping/adds-dbin
Browse files Browse the repository at this point in the history
Adds dbin as static binaries source
  • Loading branch information
mpepping authored Aug 25, 2024
2 parents e8ccc25 + 8be1841 commit 19df353
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ ADD include/ /
RUN usermod -s /bin/bash root && \
addgroup -g 1000 podshell && \
adduser -D -u 1000 -G podshell -s /bin/bash -g "Podshell User" podshell && \
su - podshell -c "/usr/local/bin/_add_binenv"
su - podshell -c "/usr/local/bin/_add_binenv" && \
su - podshell -c "/usr/local/bin/_add_dbin --install /home/podshell/.local/bin/dbin"

USER 1000
WORKDIR /home/podshell
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ stop: ## Stop the container
docker rm -f podshell

test: ## Test the container build
docker run -it --rm $(APP_NAME):latest "cat /etc/os-release && id && env | sort"
docker run -it --rm $(APP_NAME):latest \
"env | sort && binenv version && dbin info"
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/mpepping/podshell)

*A simple and small container environment for development and debug purposes.*
_A simple and small container environment for development and debug purposes._

Podshell is a small set of userland tools you can shell into. The container starts as a regular user (uid `1000`), to play nice with potential Kubernetes admission policies. To make the shell useful, a set of most [useful packages](./Dockerfile) is already installed. The package list is not exhaustive, but can be extended by using the `binenv` tool. Run [binenv](https://github.com/devops-works/binenv) to install various packages, by running `binenv update`, `binenv search` and `binenv install <pkg>`.
Podshell is a small set of userland tools you can shell into. The container starts as a regular user (`podshell`, uid `1000`) to play nice with potential admission policies. A set of [useful packages](./Dockerfile) is already installed to provide a functional shell. The package list is not exhaustive, but can be extended at runtime via either [`binenv`](https://github.com/devops-works/binenv) or [`dbin`](https://github.com/xplshn/dbin):

- Run [`binenv`](https://github.com/devops-works/binenv) to install various packages from their original GitHub release repositories, by running `binenv update`, `binenv search` and `binenv install <pkg>`.
- Run [`dbin`](https://github.com/xplshn/dbin) to install various static binaries from the [Toolpacks](https://github.com/Azathothas/Toolpacks) repository, by running `dbin install`, `dbin search`, `dbin list` and `dbin run`.

In a podshell, you can use `sudo` to switch to root if needed. That should be sufficient to run debugging or development tasks that may need root. Optionally, you can run the container as root, by setting `securityContext.runAsUser: 0` in a container spec.

Expand Down Expand Up @@ -61,9 +64,9 @@ kubectl apply -f k8s/daemonset.yaml

This DaemonSet manifest will:

1. Ensure a pod with our Docker image is running indefinitely on every node.
2. Use `hostPID`, `hostIPC`, and `hostNetwork`.
3. Mount the entire host filesystem to `/host` in the containers.
1. Ensure a pod with our Docker image is running indefinitely on every node.
2. Use `hostPID`, `hostIPC`, and `hostNetwork`.
3. Mount the entire host filesystem to `/host` in the containers.

In order to make use of these workloads, you can exec into a pod of choice by name:

Expand Down
4 changes: 4 additions & 0 deletions include/etc/profile.d/bin-paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# shellcheck shell=sh

export PATH="/home/podshell/.local/bin:/home/podshell/.binenv:$PATH"

8 changes: 0 additions & 8 deletions include/usr/local/bin/_add_binenv
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,3 @@ chmod +x binenv

rm binenv

if [[ -n $BASH ]]; then ZESHELL=bash; fi
if [[ -n $ZSH_NAME ]]; then ZESHELL=zsh; fi

echo $ZESHELL
echo -e '\nexport PATH=~/.binenv:$PATH' >> ~/.${ZESHELL}rc
echo "source <(binenv completion ${ZESHELL})" >> ~/.${ZESHELL}rc

# exec $SHELL
57 changes: 57 additions & 0 deletions include/usr/local/bin/_add_dbin
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

# Copy of upstream install script, to avoid unintended changes
# https://github.com/xplshn/dbin/blob/master/stubdl

DEST="/tmp/._bdlstub_dbin.bin"

# Determine architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH_SUFFIX="amd64" ;;
aarch64) ARCH_SUFFIX="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac

DBIN_URL="https://github.com/xplshn/dbin/releases/latest/download/dbin_${ARCH_SUFFIX}"

# Handle --install option
if [ "$1" = "--install" ]; then
DEST="$2"
shift 2
fi

# Function to download the binary
download_dbin() {
if command -v wget >/dev/null 2>&1; then
wget -q "$DBIN_URL" -O "$DEST"
elif command -v curl >/dev/null 2>&1; then
curl -qfsSL "$DBIN_URL" -o "$DEST"
else
echo "Neither wget nor curl is available."
exit 1
fi
}

# Check if binary exists and is executable
if [ -e "$DEST" ] && [ ! "$1" = "--install" ]; then
# Run the binary
"$DEST" "$@"
else
# Download and install the binary
mkdir -p "$(dirname "$DEST")"
download_dbin

if [ "$1" = "--install" ]; then
chmod +x "$DEST"
echo "DBIN IS NOW AVAILABLE. ($DEST)"
exit 0
fi

# Make the binary executable and run it
chmod +x "$DEST"
"$DEST" "$@"

echo "done"
fi

0 comments on commit 19df353

Please sign in to comment.