Skip to content

Commit e769d47

Browse files
committed
removing ansible components
1 parent 363703a commit e769d47

File tree

14 files changed

+167
-518
lines changed

14 files changed

+167
-518
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
paths:
88
- 'debian12-ssh/**'
99
- 'rocky93-ssh/**'
10-
- 'debian24-ssh/**'
11-
- 'scripts/**'
10+
- 'ubuntu24-ssh/**'
11+
- 'build.sh'
1212
- '.github/workflows/build.yml'
1313
pull_request:
1414
branches: [ "main" ]
@@ -33,67 +33,20 @@ jobs:
3333
fail-fast: false
3434

3535
steps:
36-
# .................................................................
3736
- name: Checkout repository
3837
uses: actions/checkout@v4
3938

40-
# .................................................................
41-
- name: Set up environment variables
42-
run: |
43-
echo "CONTAINER_TOKEN=${{ secrets.CONTAINER_TOKEN }}" >> $GITHUB_ENV
44-
echo "CONTAINER_TYPE=${{ matrix.container_type }}" >> $GITHUB_ENV
45-
46-
# .................................................................
47-
- name: Install dependencies
39+
- name: Install Podman
4840
run: |
4941
sudo apt-get update
50-
sudo apt-get install -y podman ansible
51-
# Install collection in the GitHub workspace
52-
ansible-galaxy collection install -p ./ community.docker
53-
54-
# .................................................................
55-
- name: Configure container environment
56-
run: |
57-
mkdir -p ~/.config/containers ~/.local/share/containers
58-
chmod 700 ~/.config/containers ~/.local/share/containers
59-
cat > ~/.config/containers/containers.conf << 'EOL'
60-
[containers]
61-
default_capabilities = ["CHOWN", "DAC_OVERRIDE", "FOWNER", "FSETID", "KILL", "NET_BIND_SERVICE", "SETFCAP", "SETGID", "SETPCAP", "SETUID", "SYS_CHROOT"]
62-
[engine]
63-
runtime = "crun"
64-
cgroup_manager = "cgroupfs"
65-
events_logger = "journald"
66-
EOL
67-
68-
# podman system info
69-
70-
- name: Set up container storage permissions
71-
run: |
72-
mkdir -p ~/.local/share/containers
73-
sudo chown -R $USER:$USER ~/.local/share/containers
74-
chmod -R 700 ~/.local/share/containers
42+
sudo apt-get install -y podman
7543
76-
# .................................................................
77-
- name: Build container
44+
- name: Build and push container
7845
env:
7946
REGISTRY_HOST: ghcr.io
8047
REGISTRY_USER: ${{ github.repository_owner }}
8148
REGISTRY_REPO: testing-containers
8249
CONTAINER_TYPE: ${{ matrix.container_type }}
8350
CONTAINER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8451
SSH_KEY: ${{ secrets.SSH_KEY }}
85-
ANSIBLE_COMMON_ARGS: "-e ansible_connection=community.docker.docker"
86-
# ANSIBLE_COMMON_ARGS: "-e ansible_connection=community.docker.docker -e ansible_user=root -e ansible_become=false"
87-
run: ./scripts/build_container.sh
88-
89-
# .................................................................
90-
- name: Upload logs on failure
91-
if: failure()
92-
uses: actions/upload-artifact@v4
93-
with:
94-
name: build-logs-${{ matrix.container-type }}
95-
path: |
96-
.working/${{ matrix.container-type }}/
97-
~/.local/share/containers/
98-
if-no-files-found: warn
99-
include-hidden-files: false
52+
run: ./build.sh

README.md

Lines changed: 84 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,155 @@
11
# Testing Containers
22

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.
44

55
## Features
66

77
- Rootless podman container builds
88
- SSH access with configurable keys
99
- systemd support
1010
- 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)
1314

1415
## Prerequisites
1516

1617
- Podman
17-
- Ansible with community.docker collection
1818
- SSH key pair for container access
1919
- Registry access token (Gitea or GitHub)
2020

2121
## Installation
2222

23-
1. Install required packages:
2423
```bash
2524
# For Debian/Ubuntu
26-
sudo apt-get install podman ansible
25+
sudo apt-get install podman
2726

2827
# 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
3529
```
3630

3731
## Configuration
3832

39-
The script can be configured through environment variables:
33+
Environment variables:
4034

4135
```bash
42-
REGISTRY_HOST # Registry hostname (default: gitea.a0a0.org:3001)
36+
REGISTRY_HOST # Registry hostname (default: ghcr.io)
4337
REGISTRY_USER # Registry username (default: jackaltx)
4438
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)
4944
```
5045

5146
## Usage Examples
5247

53-
### Building a Debian Container
48+
### Build Debian 12
5449

5550
```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
6455
```
6556

66-
### Building a Rocky Linux Container
57+
### Build Rocky Linux 9.3
6758

6859
```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
7164
```
7265

73-
### Custom SSH Key
66+
### Build Ubuntu 24.10
7467

7568
```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
7973
```
8074

81-
### Custom Registry
75+
### Custom Registry (Gitea)
8276

8377
```bash
84-
export GITEA_TOKEN=your_token_here
85-
export REGISTRY_HOST=custom.registry.com
78+
export REGISTRY_HOST=gitea.example.com:3001
8679
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
8984
```
9085

9186
## Container Details
9287

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
101104

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
109109

110-
## Testing Containers
110+
## Using Containers
111111

112-
The built containers can be tested using Ansible:
112+
### Pull from Registry
113113

114114
```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
117117

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
119125
podman run -d \
120126
--name test_container \
121127
--privileged \
122-
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
128+
-v /sys/fs/cgroup:/sys/fs/cgroup:rw \
123129
-p 2222:22 \
124-
debian12-ssh \
130+
ghcr.io/jackaltx/testing-containers:debian12-ssh \
125131
/sbin/init
132+
```
126133

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
129138
```
130139

131-
Example inventory.yml:
140+
### Molecule Testing
141+
142+
These containers are designed for use with Molecule:
143+
132144
```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
143153
```
144154
145155
## Troubleshooting

build.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Simple build script for testing containers
5+
# Replaces the complex build_container.sh with pure Containerfile approach
6+
7+
# Configuration from environment
8+
CONTAINER_TYPE="${CONTAINER_TYPE:-debian12-ssh}"
9+
REGISTRY_HOST="${REGISTRY_HOST:-ghcr.io}"
10+
REGISTRY_USER="${REGISTRY_USER:-jackaltx}"
11+
REGISTRY_REPO="${REGISTRY_REPO:-testing-containers}"
12+
SSH_KEY="${SSH_KEY:?SSH_KEY environment variable is required}"
13+
14+
# Determine authentication token
15+
if [ "$REGISTRY_HOST" = "ghcr.io" ]; then
16+
TOKEN="${CONTAINER_TOKEN:?CONTAINER_TOKEN required for GitHub registry}"
17+
else
18+
TOKEN="${GITEA_TOKEN:?GITEA_TOKEN required for Gitea registry}"
19+
fi
20+
21+
# Validate container type
22+
case "$CONTAINER_TYPE" in
23+
debian12-ssh|rocky93-ssh|ubuntu24-ssh)
24+
echo "Building $CONTAINER_TYPE..."
25+
;;
26+
*)
27+
echo "Error: CONTAINER_TYPE must be one of: debian12-ssh, rocky93-ssh, ubuntu24-ssh"
28+
exit 1
29+
;;
30+
esac
31+
32+
# Login to registry
33+
echo "$TOKEN" | podman login "$REGISTRY_HOST" -u "$REGISTRY_USER" --password-stdin
34+
35+
# Build image
36+
IMAGE_TAG="$REGISTRY_HOST/$REGISTRY_USER/$REGISTRY_REPO:$CONTAINER_TYPE"
37+
38+
podman build \
39+
--build-arg SSH_KEY="$SSH_KEY" \
40+
-t "$IMAGE_TAG" \
41+
-f "$CONTAINER_TYPE/Containerfile" \
42+
"$CONTAINER_TYPE/"
43+
44+
# Push to registry
45+
podman push "$IMAGE_TAG"
46+
47+
# Tag as latest if requested
48+
if [ "${TAG_LATEST:-false}" = "true" ]; then
49+
podman tag "$IMAGE_TAG" "$REGISTRY_HOST/$REGISTRY_USER/$REGISTRY_REPO:latest"
50+
podman push "$REGISTRY_HOST/$REGISTRY_USER/$REGISTRY_REPO:latest"
51+
fi
52+
53+
# Logout
54+
podman logout "$REGISTRY_HOST"
55+
56+
echo "✓ Successfully built and pushed $IMAGE_TAG"

debian12-ssh/Containerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ ENV DEBIAN_FRONTEND=noninteractive
66

77
# Update and install required packages
88
RUN apt-get update && \
9+
apt-get upgrade -y && \
910
apt-get install -y \
1011
python3 \
1112
sudo \
1213
systemd \
1314
openssh-server \
1415
python3-pip \
1516
iproute2 \
17+
vim \
18+
wget \
19+
git \
20+
tmux \
1621
&& apt-get clean \
1722
&& rm -rf /var/lib/apt/lists/*
1823

0 commit comments

Comments
 (0)