|
1 | 1 | # Testing Containers |
2 | 2 |
|
3 | | -This repository provides tools for building container images suitable for testing Ansible roles. It includes support for both Debian and Rocky Linux-based containers with SSH and systemd support. |
| 3 | +Base container images for testing Ansible roles via Molecule. Provides current, minimal, Ansible-ready platforms for Debian, Rocky Linux, and Ubuntu. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 |
|
7 | 7 | - Rootless podman container builds |
8 | 8 | - SSH access with configurable keys |
9 | 9 | - systemd support |
10 | 10 | - Ansible-ready with Python and required dependencies |
11 | | -- Support for both Debian and Rocky Linux base images |
12 | | -- Registry integration (Gitea and GitHub Container Registry support) |
| 11 | +- Current packages (updated at build time) |
| 12 | +- Stock configuration with minimal modifications |
| 13 | +- Registry integration (Gitea and GitHub Container Registry) |
13 | 14 |
|
14 | 15 | ## Prerequisites |
15 | 16 |
|
16 | 17 | - Podman |
17 | | -- Ansible with community.docker collection |
18 | 18 | - SSH key pair for container access |
19 | 19 | - Registry access token (Gitea or GitHub) |
20 | 20 |
|
21 | 21 | ## Installation |
22 | 22 |
|
23 | | -1. Install required packages: |
24 | 23 | ```bash |
25 | 24 | # For Debian/Ubuntu |
26 | | -sudo apt-get install podman ansible |
| 25 | +sudo apt-get install podman |
27 | 26 |
|
28 | 27 | # For Fedora/RHEL |
29 | | -sudo dnf install podman ansible |
30 | | -``` |
31 | | - |
32 | | -2. Install required Ansible collection: |
33 | | -```bash |
34 | | -ansible-galaxy collection install community.docker |
| 28 | +sudo dnf install podman |
35 | 29 | ``` |
36 | 30 |
|
37 | 31 | ## Configuration |
38 | 32 |
|
39 | | -The script can be configured through environment variables: |
| 33 | +Environment variables: |
40 | 34 |
|
41 | 35 | ```bash |
42 | | -REGISTRY_HOST # Registry hostname (default: gitea.a0a0.org:3001) |
| 36 | +REGISTRY_HOST # Registry hostname (default: ghcr.io) |
43 | 37 | REGISTRY_USER # Registry username (default: jackaltx) |
44 | 38 | REGISTRY_REPO # Repository name (default: testing-containers) |
45 | | -CONTAINER_TYPE # Container type (debian12-ssh or rocky93-ssh) |
46 | | -SSH_KEY # SSH public key (default: ~/.ssh/id_ed25519.pub) |
47 | | -GITEA_TOKEN # Gitea access token |
48 | | -GITHUB_TOKEN # GitHub access token (alternative to GITEA_TOKEN) |
| 39 | +CONTAINER_TYPE # debian12-ssh, rocky93-ssh, or ubuntu24-ssh |
| 40 | +SSH_KEY # SSH public key (required) |
| 41 | +CONTAINER_TOKEN # GitHub token (for ghcr.io) |
| 42 | +GITEA_TOKEN # Gitea token (for Gitea registry) |
| 43 | +TAG_LATEST # Tag as 'latest' (default: false) |
49 | 44 | ``` |
50 | 45 |
|
51 | 46 | ## Usage Examples |
52 | 47 |
|
53 | | -### Building a Debian Container |
| 48 | +### Build Debian 12 |
54 | 49 |
|
55 | 50 | ```bash |
56 | | -# Using Gitea registry |
57 | | -export GITEA_TOKEN=your_token_here |
58 | | -./build_container.sh CONTAINER_TYPE=debian12-ssh |
59 | | - |
60 | | -# Using GitHub registry |
61 | | -export GITHUB_TOKEN=your_token_here |
62 | | -export GITHUB_REPOSITORY=your_username/your_repo |
63 | | -./build_container.sh CONTAINER_TYPE=debian12-ssh |
| 51 | +export CONTAINER_TOKEN=ghp_your_token_here |
| 52 | +export SSH_KEY=$(cat ~/.ssh/id_ed25519.pub) |
| 53 | +export CONTAINER_TYPE=debian12-ssh |
| 54 | +./build.sh |
64 | 55 | ``` |
65 | 56 |
|
66 | | -### Building a Rocky Linux Container |
| 57 | +### Build Rocky Linux 9.3 |
67 | 58 |
|
68 | 59 | ```bash |
69 | | -export GITEA_TOKEN=your_token_here |
70 | | -./build_container.sh CONTAINER_TYPE=rocky93-ssh |
| 60 | +export CONTAINER_TOKEN=ghp_your_token_here |
| 61 | +export SSH_KEY=$(cat ~/.ssh/id_ed25519.pub) |
| 62 | +export CONTAINER_TYPE=rocky93-ssh |
| 63 | +./build.sh |
71 | 64 | ``` |
72 | 65 |
|
73 | | -### Custom SSH Key |
| 66 | +### Build Ubuntu 24.10 |
74 | 67 |
|
75 | 68 | ```bash |
76 | | -export GITEA_TOKEN=your_token_here |
77 | | -export SSH_KEY=$(cat ~/.ssh/custom_key.pub) |
78 | | -./build_container.sh CONTAINER_TYPE=debian12-ssh |
| 69 | +export CONTAINER_TOKEN=ghp_your_token_here |
| 70 | +export SSH_KEY=$(cat ~/.ssh/id_ed25519.pub) |
| 71 | +export CONTAINER_TYPE=ubuntu24-ssh |
| 72 | +./build.sh |
79 | 73 | ``` |
80 | 74 |
|
81 | | -### Custom Registry |
| 75 | +### Custom Registry (Gitea) |
82 | 76 |
|
83 | 77 | ```bash |
84 | | -export GITEA_TOKEN=your_token_here |
85 | | -export REGISTRY_HOST=custom.registry.com |
| 78 | +export REGISTRY_HOST=gitea.example.com:3001 |
86 | 79 | export REGISTRY_USER=your_username |
87 | | -export REGISTRY_REPO=your_repo |
88 | | -./build_container.sh CONTAINER_TYPE=debian12-ssh |
| 80 | +export GITEA_TOKEN=your_token_here |
| 81 | +export SSH_KEY=$(cat ~/.ssh/id_ed25519.pub) |
| 82 | +export CONTAINER_TYPE=debian12-ssh |
| 83 | +./build.sh |
89 | 84 | ``` |
90 | 85 |
|
91 | 86 | ## Container Details |
92 | 87 |
|
93 | | -### Debian Container (debian12-ssh) |
94 | | -- Base Image: debian:12 |
95 | | -- Included Packages: |
96 | | - - python3 |
97 | | - - sudo |
98 | | - - systemd |
99 | | - - openssh-server |
100 | | - - python3-pip |
| 88 | +All containers include: |
| 89 | +- Python 3 (for Ansible) |
| 90 | +- OpenSSH server (key-based auth) |
| 91 | +- systemd (for service management) |
| 92 | +- sudo (passwordless for jackaltx user) |
| 93 | +- vim, wget, git, tmux (utilities) |
| 94 | + |
| 95 | +### Debian 12 (debian12-ssh) |
| 96 | +- Base: `debian:12` |
| 97 | +- Package manager: apt |
| 98 | +- SSH service: ssh |
| 99 | + |
| 100 | +### Rocky Linux 9.3 (rocky93-ssh) |
| 101 | +- Base: `rockylinux:9.3` |
| 102 | +- Package manager: dnf |
| 103 | +- SSH service: sshd |
101 | 104 |
|
102 | | -### Rocky Linux Container (rocky93-ssh) |
103 | | -- Base Image: rockylinux:9.3 |
104 | | -- Included Packages: |
105 | | - - python3 |
106 | | - - sudo |
107 | | - - systemd |
108 | | - - openssh-server |
| 105 | +### Ubuntu 24.10 (ubuntu24-ssh) |
| 106 | +- Base: `ubuntu:24.10` |
| 107 | +- Package manager: apt |
| 108 | +- SSH service: ssh |
109 | 109 |
|
110 | | -## Testing Containers |
| 110 | +## Using Containers |
111 | 111 |
|
112 | | -The built containers can be tested using Ansible: |
| 112 | +### Pull from Registry |
113 | 113 |
|
114 | 114 | ```bash |
115 | | -# Pull the container |
116 | | -podman pull gitea.a0a0.org:3001/jackaltx/testing-containers/debian12-ssh:latest |
| 115 | +# GitHub Container Registry |
| 116 | +podman pull ghcr.io/jackaltx/testing-containers:debian12-ssh |
117 | 117 |
|
118 | | -# Run the container |
| 118 | +# Gitea Registry |
| 119 | +podman pull gitea.example.com:3001/jackaltx/testing-containers:rocky93-ssh |
| 120 | +``` |
| 121 | + |
| 122 | +### Run Container |
| 123 | + |
| 124 | +```bash |
119 | 125 | podman run -d \ |
120 | 126 | --name test_container \ |
121 | 127 | --privileged \ |
122 | | - -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ |
| 128 | + -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ |
123 | 129 | -p 2222:22 \ |
124 | | - debian12-ssh \ |
| 130 | + ghcr.io/jackaltx/testing-containers:debian12-ssh \ |
125 | 131 | /sbin/init |
| 132 | +``` |
126 | 133 |
|
127 | | -# Test with Ansible |
128 | | -ansible-playbook -i inventory.yml your_playbook.yml |
| 134 | +### SSH Access |
| 135 | + |
| 136 | +```bash |
| 137 | +ssh -p 2222 jackaltx@localhost |
129 | 138 | ``` |
130 | 139 |
|
131 | | -Example inventory.yml: |
| 140 | +### Molecule Testing |
| 141 | + |
| 142 | +These containers are designed for use with Molecule: |
| 143 | + |
132 | 144 | ```yaml |
133 | | -all: |
134 | | - hosts: |
135 | | - debian_container: |
136 | | - ansible_connection: community.docker.docker |
137 | | - ansible_host: test_container |
138 | | - ansible_user: jackaltx |
139 | | - ansible_become: true |
140 | | - ansible_python_interpreter: python3 |
141 | | - ansible_remote_tmp: /tmp/ansible-${USER} |
142 | | - ansible_pipelining: true |
| 145 | +# molecule.yml |
| 146 | +platforms: |
| 147 | + - name: instance |
| 148 | + image: ghcr.io/jackaltx/testing-containers:debian12-ssh |
| 149 | + privileged: true |
| 150 | + volumes: |
| 151 | + - /sys/fs/cgroup:/sys/fs/cgroup:rw |
| 152 | + command: /sbin/init |
143 | 153 | ``` |
144 | 154 |
|
145 | 155 | ## Troubleshooting |
|
0 commit comments