diff --git a/Dockerfile b/Dockerfile index da3632f..81588a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,15 @@ -FROM alpine:3 +FROM docker.io/library/alpine:3 + +LABEL org.opencontainers.image.title=jswank/alpine-cli \ + org.opencontainers.image.description="A minimal image for running Linux CLI utilities" \ + org.opencontainers.image.url=https://git.sr.ht/~jswank/alpine-cli \ + org.opencontainers.image.authors="Jason Swank" \ + org.opencontainers.image.licenses=MIT RUN apk -U --no-cache add \ - doas doas-sudo-shim \ - bash less \ - coreutils grep gawk perl + doas doas-sudo-shim \ + bash less \ + coreutils grep gawk perl RUN adduser -h /home/cli -s /bin/bash -D cli cli && \ addgroup cli wheel && \ diff --git a/bin/cli b/bin/cli index 66ef2b7..dfcad80 100755 --- a/bin/cli +++ b/bin/cli @@ -1,25 +1,66 @@ #!/usr/bin/env -S just --working-directory . --justfile image := "ghcr.io/jswank/alpine-cli:latest" -n := "cli" +n := "alpine-cli" -# run +# Invoke the 'run' recipe default: run -# run a temporary container based on {{image}} -@run: - podman run -ti --rm {{image}} +# Usage: run +# +# Start a shell in an ephemeral container. +# +# Examples: +# cli run +# +# Run an ephemeral container. +@run: + podman run -ti --userns=keep-id --rm {{image}} -# run (or attach to) a persistent container {{n}} +# Usage: persist +# +# Start a shell in a persistent container. +# +# Examples: +# cli persist +# +# Run (or attach to) a persistent container persist: #!/bin/sh - if [ $(podman ps --all --filter name="{{n}}" -q | wc -l) -gt 0 ]; then + if [ $(podman ps --all --filter name="^{{n}}$" -q | wc -l) -gt 0 ]; then podman start -i -a {{n}} else - podman run -ti --name {{n}} {{image}} + podman run -ti --userns=keep-id --name {{n}} {{image}} fi -# remove the persistent container +# Remove the persistent container @clean: podman rm -f {{n}} >/dev/null 2>&1 +# Usage: save [new_image_name] +# +# Sometimes you want a quick snapshot of your work in progress. Use this target +# to create an image based on the running container. +# +# Examples: +# cli save foo` - saves the current (persistent) container as a new image +# named "foo" +# ` cli save - saves the current (persistent) container as a new +# default image +# +# Save the running container as a new image +save i=image: + podman commit -q {{n}} {{i}} >/dev/null 2>&1 + +# Remove a running container, and run the default recipe +@restart: clean default + +# Display this listing. Detailed help is available with 'help recipe_name'. +help recipe="help": + #!/bin/sh + if [ "{{recipe}}" = "help" ]; then + just --list --justfile {{justfile()}} + else + grep -B 32 -E '^@?{{recipe}}\s?.*:' {{justfile()}} \ + | tac | awk 'NR==1 {print; next}; !/^#/{exit}1;' | tac + fi