Skip to content

Commit e23c3be

Browse files
committed
Add forgejo_setup role
Deploy Forgejo Git service using rootless Podman pods. Forgejo is a community fork of Gitea, created to preserve open-source governance and prevent corporate control over a critical development tool. Features: - Rootless Podman pod with PostgreSQL backend - Auto-generated secure passwords for DB and admin user - Simplified pod networking (no separate network needed) - Clean task separation - Comprehensive documentation and argument specs - Proper UID mapping for rootless container storage Assisted-by: Claude
1 parent 6131005 commit e23c3be

File tree

9 files changed

+519
-2
lines changed

9 files changed

+519
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Name | Description
6565
[redhatci.ocp.etcd_data](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/etcd_data/README.md) | Allows to query, encrypt or decrypt etcd data using the supported encryption types.
6666
[redhatci.ocp.example_cnf_deploy](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/example_cnf_deploy/README.md) | Deploys the example-cnf workload on top of an OpenShift cluster
6767
[redhatci.ocp.extract_openshift_installer](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/extract_openshift_installer/README.md) | Extracts openshift_installer binary from the release image.
68+
[redhatci.ocp.forgejo_setup](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/forgejo_setup/README.md) | A role to deploy and configure Forgejo Git service.
6869
[redhatci.ocp.generate_agent_iso](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/generate_agent_iso/README.md) | Creates the boot ISO using OpenShift_installer's agent sub-command
6970
[redhatci.ocp.generate_manifests](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/generate_manifests/README.md) | Generates the manifests required for OpenShift_installer's agent sub-command
7071
[redhatci.ocp.generate_ssh_key_pair](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/generate_ssh_key_pair/README.md) | Produces an ssh key pair

ansible-collection-redhatci-ocp.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%global forgeurl https://github.com/%{org}/%{repo}
44

55
Name: %{repo}
6-
Version: 2.10.EPOCH
6+
Version: 2.11.EPOCH
77
Release: VERS%{?dist}
88
Summary: Red Hat OCP CI Collection for Ansible
99

@@ -54,6 +54,9 @@ find -type f ! -executable -name '*.py' -print -exec sed -i -e '1{\@^#!.*@d}' '{
5454

5555

5656
%changelog
57+
* Thu Oct 23 2025 Tony Garcia <[email protected]> - 2.11.EPOCH-VERS
58+
- Add forgejo_setup role
59+
5760
* Fri Sep 19 2025 Tony Garcia <[email protected]> - 2.10.EPOCH-VERS
5861
- Add redact filter plugin
5962

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: ocp
1010
# Patch version is replaced from commit date in UNIX epoch format
1111
# Example: 1.3.0 -> 1.3.2147483647
1212
# Keep in sync with ansible-collection-redhatci-ocp.spec
13-
version: 2.10.0
13+
version: 2.11.0
1414

1515
# The path to the Markdown (.md) readme file.
1616
readme: README.md

roles/forgejo_setup/README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# forgejo_setup
2+
3+
A role to deploy and configure Forgejo Git service
4+
5+
## Description
6+
7+
This role sets up a complete Forgejo Git service installation with:
8+
- Pod to host the application and database containers
9+
- PostgreSQL database backend (containerized)
10+
- Forgejo application server (containerized)
11+
- Persistent storage for data and database
12+
- Health checks for both services
13+
14+
All containers run in rootless mode within a single pod
15+
16+
## Requirements
17+
18+
- [Podman](https://podman.io)
19+
- Ansible collection: [containers.podman](https://galaxy.ansible.com/containers/podman)
20+
- Enough disk space for Git repos and DB
21+
22+
## Variables
23+
24+
| Variable | Default | Description
25+
| ----------------------- | ----------------------------------- | -----------
26+
| fs_state | present | State of the deployment (present/absent)
27+
| fs_app_container_name | forgejo | Application container name
28+
| fs_app_env_vars | [] | Additional environment variables for the application
29+
| fs_app_image | codeberg.org/forgejo/forgejo:13 | Forgejo container image
30+
| fs_app_email | {{ fs_app_user }}@localhost | Application admin email
31+
| fs_app_name | Forgejo: Beyond coding. We forge. | Application name
32+
| fs_app_password | <auto generated> | Application password automatically generated if not set
33+
| fs_app_user | forgejo | Application admin user
34+
| fs_base_dir | {{ ansible_env.HOME }}/forgejo | Base directory for all Forgejo data
35+
| fs_data_dir | {{ fs_base_dir }}/data | Directory for Forgejo application data
36+
| fs_db_container_name | db | DB container name
37+
| fs_db_dir | {{ fs_base_dir }}/db | Directory for DB data
38+
| fs_db_name | forgejo | DB name
39+
| fs_db_password | <auto generated> | DB password automatically generated if not set
40+
| fs_db_user | forgejo | DB user
41+
| fs_pod_http_port | 3000 | Host port for Forgejo HTTP interface
42+
| fs_pod_name | forgejo | Podman pod name
43+
| fs_pod_ssh_port | 2222 | Host port for Forgejo SSH interface
44+
| fs_postgres_image | docker.io/library/postgres:14 | DB container image
45+
| fs_user | {{ ansible_user_id }} | User to run containers as (rootless mode)
46+
| fs_user_gid | {{ ansible_user_gid }} | GID of the user running containers
47+
| fs_user_uid | {{ ansible_user_uid }} | UID of the user running containers
48+
| fs_wait_delay | 10 | Delay in seconds between retries
49+
| fs_wait_retries | 30 | Number of retries when waiting for services
50+
51+
## Dependencies
52+
53+
- containers.podman collection
54+
55+
## Usage Examples
56+
57+
### Basic Deployment
58+
59+
```yaml
60+
- name: Deploy Forgejo with PostgreSQL
61+
ansible.builtin.include_role:
62+
name: redhatci.ocp.forgejo_setup
63+
```
64+
65+
### Custom Configuration
66+
67+
```yaml
68+
- name: Deploy Forgejo with custom settings
69+
ansible.builtin.include_role:
70+
name: redhatci.ocp.forgejo_setup
71+
vars:
72+
fs_pod_http_port: 8080
73+
fs_pod_ssh_port: 2222
74+
fs_postgres_password: "secure_password_here"
75+
fs_base_dir: /opt/forgejo
76+
fs_forgejo_env_vars:
77+
FORGEJO__server__DOMAIN: git.example.com
78+
FORGEJO__server__ROOT_URL: https://git.example.com
79+
FORGEJO__server__SSH_DOMAIN: git.example.com
80+
```
81+
82+
### Remove Forgejo Deployment
83+
84+
```yaml
85+
- name: Remove Forgejo installation
86+
ansible.builtin.include_role:
87+
name: redhatci.ocp.forgejo_setup
88+
vars:
89+
fs_state: absent
90+
```
91+
92+
## Post-Installation
93+
94+
Access Forgejo at `http://localhost:3000` (or your custom port) with the credentials provided or generated during deployment.
95+
96+
## Troubleshooting
97+
98+
### Check pod and container status
99+
100+
```bash
101+
podman pod ps
102+
podman ps -a --pod
103+
```
104+
105+
### View container logs
106+
107+
```bash
108+
podman logs forgejo
109+
podman logs db
110+
```
111+
112+
### Restart pod
113+
114+
```bash
115+
podman pod restart forgejo
116+
```
117+
118+
### Access database files
119+
120+
The database directory is owned by the mapped container UID due to rootless Podman's user namespace mapping.
121+
To access database files as the container user for backup or management:
122+
123+
```bash
124+
podman unshare <cmd> /path/to/db
125+
```
126+
127+
This allows you to interact with files using the same UID mapping that the container uses.
128+
129+
## License
130+
131+
Apache-2.0
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# Forgejo configuration defaults
3+
fs_state: present
4+
fs_user: "{{ ansible_user_id }}"
5+
fs_user_uid: "{{ ansible_user_uid }}"
6+
fs_user_gid: "{{ ansible_user_gid }}"
7+
fs_base_dir: "{{ ansible_env.HOME }}/forgejo"
8+
fs_data_dir: "{{ fs_base_dir }}/data"
9+
fs_db_dir: "{{ fs_base_dir }}/db"
10+
11+
# Container configuration
12+
fs_app_image: codeberg.org/forgejo/forgejo:13
13+
fs_postgres_image: docker.io/library/postgres:14
14+
15+
# Pod configuration
16+
fs_pod_name: forgejo
17+
fs_pod_http_port: 3000
18+
fs_pod_ssh_port: 2222
19+
20+
# Database configuration
21+
fs_db_user: forgejo
22+
fs_db_name: forgejo
23+
fs_db_port: 5432
24+
fs_db_container_name: db
25+
26+
# Application configuration
27+
fs_app_user: forgejo
28+
fs_app_email: "{{ fs_app_user }}@localhost"
29+
fs_app_container_name: forgejo
30+
fs_app_name: "Forgejo: Beyond coding. We forge."
31+
32+
# Additional application environment variables
33+
fs_app_env_vars: {}
34+
# Example:
35+
# fs_app_env_vars:
36+
# FORGEJO__server__DOMAIN: git.example.com
37+
# FORGEJO__server__ROOT_URL: https://git.example.com
38+
39+
# Waiting times
40+
fs_wait_retries: 30
41+
fs_wait_delay: 10
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
argument_specs:
3+
main:
4+
short_description: Main entry point for Forgejo deployment
5+
description: >
6+
Main entry point that dispatches to present or absent tasks based on fs_state.
7+
options:
8+
fs_state:
9+
type: str
10+
required: false
11+
default: present
12+
choices:
13+
- present
14+
- absent
15+
description: State of the Forgejo deployment (present to deploy, absent to remove).
16+
17+
present:
18+
short_description: Deploy Forgejo with PostgreSQL in a Podman pod
19+
description: >
20+
Deploy Forgejo Git service with PostgreSQL database using rootless Podman containers in a pod.
21+
This creates the necessary directories, sets up a Podman pod,
22+
and deploys both PostgreSQL and Forgejo containers within the pod for simplified networking.
23+
options:
24+
fs_user:
25+
type: str
26+
required: false
27+
default: "{{ ansible_user_id }}"
28+
description: User to run containers as (rootless mode).
29+
fs_user_uid:
30+
type: str
31+
required: false
32+
default: "{{ ansible_user_uid }}"
33+
description: UID of the user running containers.
34+
fs_user_gid:
35+
type: str
36+
required: false
37+
default: "{{ ansible_user_gid }}"
38+
description: GID of the user running containers.
39+
fs_base_dir:
40+
type: str
41+
required: false
42+
default: "{{ ansible_env.HOME }}/forgejo"
43+
description: Base directory for Forgejo data and configuration.
44+
fs_data_dir:
45+
type: str
46+
required: false
47+
default: "{{ fs_base_dir }}/data"
48+
description: Directory for Forgejo application data.
49+
fs_db_dir:
50+
type: str
51+
required: false
52+
default: "{{ fs_base_dir }}/db"
53+
description: Directory for database data.
54+
fs_app_image:
55+
type: str
56+
required: false
57+
default: codeberg.org/forgejo/forgejo:13
58+
description: Forgejo container image to use.
59+
fs_postgres_image:
60+
type: str
61+
required: false
62+
default: docker.io/library/postgres:14
63+
description: PostgreSQL container image to use.
64+
fs_pod_name:
65+
type: str
66+
required: false
67+
default: forgejo
68+
description: Name of the Podman pod.
69+
fs_pod_http_port:
70+
type: int
71+
required: false
72+
default: 3000
73+
description: Host port to expose Forgejo HTTP interface.
74+
fs_pod_ssh_port:
75+
type: int
76+
required: false
77+
default: 2222
78+
description: Host port to expose Forgejo SSH interface.
79+
fs_db_user:
80+
type: str
81+
required: false
82+
default: forgejo
83+
description: Database user.
84+
fs_db_password:
85+
type: str
86+
required: false
87+
description: Database password. If not provided, a random 32-character password will be auto-generated.
88+
fs_db_name:
89+
type: str
90+
required: false
91+
default: forgejo
92+
description: Database name.
93+
fs_db_port:
94+
type: int
95+
required: false
96+
default: 5432
97+
description: Database port.
98+
fs_db_container_name:
99+
type: str
100+
required: false
101+
default: db
102+
description: Name of the database container.
103+
fs_app_container_name:
104+
type: str
105+
required: false
106+
default: forgejo
107+
description: Name of the application container.
108+
fs_app_name:
109+
type: str
110+
required: false
111+
default: "Forgejo: Beyond coding. We forge."
112+
description: Application name.
113+
fs_app_email:
114+
type: str
115+
required: false
116+
default: "{{ fs_app_user }}@localhost"
117+
description: Application admin email.
118+
fs_app_user:
119+
type: str
120+
required: false
121+
default: forgejo
122+
description: Application admin user.
123+
fs_app_env_vars:
124+
type: dict
125+
required: false
126+
default: {}
127+
description: Additional environment variables for application container.
128+
fs_app_password:
129+
type: str
130+
required: false
131+
description: Application password. If not provided, a random 32-character password will be auto-generated.
132+
fs_wait_retries:
133+
type: int
134+
required: false
135+
default: 30
136+
description: Number of retries when waiting for services to be ready.
137+
fs_wait_delay:
138+
type: int
139+
required: false
140+
default: 10
141+
description: Delay in seconds between retries.
142+
143+
absent:
144+
short_description: Remove Forgejo deployment
145+
description: >
146+
Remove Forgejo pod and containers. Data directories are preserved and must be manually deleted if needed.
147+
options:
148+
fs_pod_name:
149+
type: str
150+
required: false
151+
default: forgejo
152+
description: Name of the Podman pod to remove.
153+
fs_app_container_name:
154+
type: str
155+
required: false
156+
default: forgejo
157+
description: Name of the application container to remove.
158+
fs_db_container_name:
159+
type: str
160+
required: false
161+
default: db
162+
description: Name of the database container to remove.
163+
fs_base_dir:
164+
type: str
165+
required: false
166+
default: "{{ ansible_env.HOME }}/forgejo"
167+
description: Base directory path (displayed in removal information).

0 commit comments

Comments
 (0)