Building Images¶
How to build Testing Container images from source.
Prerequisites¶
- Podman installed
- SSH key generated
- Registry access (ghcr.io or Gitea)
Quick Build¶
# Clone repository
git clone https://github.com/jackaltx/testing-containers.git
cd testing-containers
# Set SSH key
export SSH_KEY="$(cat ~/.ssh/id_ed25519.pub)"
# Set registry token (for GitHub)
export CONTAINER_TOKEN="ghp_your_token_here"
# Build and push
./build.sh debian12-ssh
Build Script Usage¶
# Syntax
./build.sh <container-type>
# Available types
./build.sh debian12-ssh
./build.sh rocky9x-ssh
./build.sh ubuntu24-ssh
# Environment variables
SSH_KEY # Required - public key to inject
CONTAINER_TOKEN # For ghcr.io (default registry)
GITEA_TOKEN # For Gitea registry
REGISTRY_HOST # Defaults to ghcr.io
REGISTRY_USER # Defaults to jackaltx
REGISTRY_REPO # Defaults to testing-containers
TAG_LATEST # Set to "true" to also tag as :latest
Manual Build¶
Debian 12¶
cd debian12-ssh
podman build \
--build-arg SSH_KEY="$(cat ~/.ssh/id_ed25519.pub)" \
-t ghcr.io/jackaltx/testing-containers/debian-ssh:12 \
-f Containerfile .
Rocky Linux 9¶
cd rocky9x-ssh
podman build \
--build-arg SSH_KEY="$(cat ~/.ssh/id_ed25519.pub)" \
-t ghcr.io/jackaltx/testing-containers/rocky-ssh:9 \
-f Containerfile .
Ubuntu 24.04¶
cd ubuntu24-ssh
podman build \
--build-arg SSH_KEY="$(cat ~/.ssh/id_ed25519.pub)" \
-t ghcr.io/jackaltx/testing-containers/ubuntu-ssh:24 \
-f Containerfile .
Custom Registry¶
Build for Private Registry¶
export REGISTRY_HOST="registry.example.com"
export REGISTRY_USER="myuser"
export REGISTRY_REPO="ansible-test-images"
export GITEA_TOKEN="your_gitea_token"
./build.sh debian12-ssh
Result: registry.example.com/myuser/ansible-test-images/debian-ssh:12
Build for Docker Hub¶
export REGISTRY_HOST="docker.io"
export REGISTRY_USER="yourusername"
export CONTAINER_TOKEN="your_docker_token"
./build.sh debian12-ssh
Local Testing¶
Test Without Pushing¶
# Build locally
export SSH_KEY="$(cat ~/.ssh/id_ed25519.pub)"
cd debian12-ssh
podman build \
--build-arg SSH_KEY="$SSH_KEY" \
-t local/debian-ssh:12 \
-f Containerfile .
# Test
./run-podman.sh
ssh -p 2222 jackaltx@localhost
./cleanup-podman.sh
Test Script¶
# Set to use local image
export CONTAINER_TYPE=debian12-ssh
export IMAGE="local/debian-ssh:12"
./run-podman.sh
# Verify SSH
ssh -p 2222 jackaltx@localhost 'echo "Success!"'
# Cleanup
./cleanup-podman.sh
Containerfile Anatomy¶
Structure¶
# 1. Base image
FROM debian:12
# 2. Environment setup
ENV DEBIAN_FRONTEND=noninteractive
# 3. Package installation
RUN apt-get update && apt-get install -y python3 openssh-server systemd sudo
# 4. User creation
RUN useradd -m -s /bin/bash jackaltx
# 5. SSH key injection
ARG SSH_KEY
RUN echo "$SSH_KEY" > /home/jackaltx/.ssh/authorized_keys
# 6. SSH configuration
RUN systemctl enable ssh
# 7. Security hardening
RUN chmod 700 /etc/sudoers.d
Build Automation¶
GitHub Actions¶
name: Build Images
on:
schedule:
- cron: '0 0 1 * *' # Monthly
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
distro: [debian12-ssh, rocky9x-ssh, ubuntu24-ssh]
steps:
- uses: actions/checkout@v3
- name: Build and push
env:
SSH_KEY: ${{ secrets.BUILD_SSH_KEY }}
CONTAINER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./build.sh ${{ matrix.distro }}
Troubleshooting¶
Build Fails: SSH Key Invalid¶
# Verify SSH key format
cat ~/.ssh/id_ed25519.pub
# Should start with: ssh-ed25519 AAAA...
# If using RSA, ensure it's valid:
cat ~/.ssh/id_rsa.pub
# Should start with: ssh-rsa AAAA...
# Test key format
echo "$SSH_KEY" | ssh-keygen -l -f -
Build Fails: Package Not Found¶
Update package lists in Containerfile: