Skip to content

Commit e62c535

Browse files
Scaffold EE spec files for Gitlab (#575)
* Add initial changes * lint fix * Update ee * try to move to utils - note test all again --------- Co-authored-by: Anushka Shukla <anshukla@redhat.com>
1 parent 45f7dde commit e62c535

18 files changed

Lines changed: 1717 additions & 19 deletions

File tree

docs/ee_scaffolding.md

Lines changed: 123 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
The `ansible-creator init execution_env` command scaffolds a complete
55
Execution Environment (EE) project, including the EE definition file, a
6-
GitHub Actions CI/CD workflow, and optional configuration for Ansible Galaxy
7-
servers.
6+
CI/CD workflow for **GitHub Actions** (default) or **GitLab CI**, and optional
7+
configuration for Ansible Galaxy servers.
88

99
## Quick start
1010

1111
```console
1212
ansible-creator init execution_env my-ee-project
1313
```
1414

15-
This produces:
15+
This produces a GitHub Actions–based project:
1616

1717
```text
1818
my-ee-project/
@@ -24,6 +24,38 @@ my-ee-project/
2424
└── execution-environment.yml
2525
```
2626

27+
### GitLab instead of GitHub
28+
29+
Use `--scm-provider gitlab` to scaffold `.gitlab-ci.yml` instead of
30+
`.github/workflows/ee-build.yml`:
31+
32+
```console
33+
ansible-creator init execution_env --scm-provider gitlab my-ee-gitlab
34+
```
35+
36+
```text
37+
my-ee-gitlab/
38+
├── .gitlab-ci.yml
39+
├── .gitignore
40+
├── README.md
41+
└── execution-environment.yml
42+
```
43+
44+
Galaxy and SCM tokens use the **same variable names** as in the GitHub
45+
workflow (`ANSIBLE_GALAXY_SERVER_<ID>_TOKEN`, plus each
46+
`scm_servers[*].token_env_var`). Configure them under **Settings →
47+
CI/CD → Variables** (mark secrets as masked/protected). For pushes to
48+
GitLab Container Registry you can rely on the predefined
49+
`CI_REGISTRY_USER` / `CI_REGISTRY_PASSWORD`, or set
50+
`REGISTRY_USERNAME` / `REGISTRY_PASSWORD` for another registry. See
51+
[GitLab CI pipeline](#gitlab-ci-pipeline-gitlab-ciyml).
52+
53+
You can add the same CI files to an existing directory with:
54+
55+
```console
56+
ansible-creator add resource ee-ci --scm-provider gitlab /path/to/project
57+
```
58+
2759
## Configuration
2860

2961
EE projects can be customized via CLI flags, inline JSON
@@ -153,12 +185,13 @@ If `galaxy_servers` is empty and no `ansible_cfg` is provided, no
153185

154186
#### Token workflow integration
155187

156-
For each server with `token_required: true`, the scaffolded
157-
`ee-build.yml` workflow:
188+
For each server with `token_required: true`, the scaffolded workflow
189+
(GitHub Actions `ee-build.yml` or GitLab `.gitlab-ci.yml`):
158190

159191
1. Checks whether the corresponding `ANSIBLE_GALAXY_SERVER_<ID>_TOKEN`
160-
secret is configured.
161-
2. Passes the token as a `--build-arg` to `buildah bud`.
192+
is configured (repository **secret** on GitHub, **CI/CD variable** on
193+
GitLab).
194+
2. Passes the token as a `--build-arg` to `podman build` / `buildah bud`.
162195
3. Declares a matching `ARG` directive in the EE definition's
163196
`prepend_galaxy` section.
164197

@@ -191,7 +224,7 @@ SCM provider or organization:
191224
|-------|----------|-------------|
192225
| `id` | yes | Identifier (lowercase letters, numbers, underscores) |
193226
| `hostname` | yes | Git server hostname (e.g. `github.com`) |
194-
| `token_env_var` | yes | Environment variable name for the token. Must start with an uppercase letter and contain only uppercase letters, digits, and underscores (e.g. `GITHUB_ORG1_TOKEN`). This name is used as the GitHub Actions secret name. |
227+
| `token_env_var` | yes | Environment variable name for the token. Must start with an uppercase letter and contain only uppercase letters, digits, and underscores (e.g. `GITHUB_ORG1_TOKEN`). This name is used as the GitHub Actions secret name or the GitLab CI/CD variable name. |
195228

196229
#### Collection URL naming convention
197230

@@ -222,8 +255,9 @@ In the example above, `${GITHUB_ORG1_TOKEN}` in the collection URL
222255
matches the `token_env_var` of the `github_org1` SCM server entry.
223256
The workflow will:
224257

225-
1. Expect a GitHub Actions secret named `GITHUB_ORG1_TOKEN`
226-
2. Validate the secret is configured before building
258+
1. Expect a GitHub Actions secret or GitLab CI/CD variable named
259+
`GITHUB_ORG1_TOKEN`
260+
2. Validate it is configured before building
227261
3. Resolve `${GITHUB_ORG1_TOKEN}` in the generated requirements file
228262
via `envsubst`
229263

@@ -343,18 +377,50 @@ This creates:
343377
`ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN` secret and passes it as
344378
a build arg.
345379

380+
The same `--ee-config` with `--scm-provider gitlab` swaps the last item
381+
for `.gitlab-ci.yml` (and omits `.github/workflows/`):
382+
383+
```console
384+
ansible-creator init execution_env \
385+
--scm-provider gitlab \
386+
--ee-config '{
387+
"name": "ee-network",
388+
"base_image": "registry.redhat.io/ansible-automation-platform-25/ee-minimal-rhel8:latest",
389+
"collections": [
390+
{"name": "cisco.ios"},
391+
{"name": "ansible.netcommon"}
392+
],
393+
"galaxy_servers": [
394+
{
395+
"id": "automation_hub",
396+
"url": "https://console.redhat.com/api/automation-hub/content/published/",
397+
"auth_url": "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token",
398+
"token_required": true
399+
},
400+
{
401+
"id": "galaxy",
402+
"url": "https://galaxy.ansible.com/"
403+
}
404+
]
405+
}' \
406+
my-ee-gitlab
407+
```
408+
346409
## CI/CD workflow
347410

348-
The scaffolded `ee-build.yml` workflow builds and publishes the EE image.
411+
Scaffolded pipelines build and publish the EE image using **podman** (GitLab)
412+
or **buildah** (GitHub), with the same token and `envsubst` model.
349413

350-
### Triggers
414+
### GitHub Actions (`ee-build.yml`)
415+
416+
#### Triggers
351417

352418
- **Pull requests** to `main`/`master` — build only (no push).
353419
- **Push** to `main`/`master` — build, push with `latest` and SHA tags.
354420
- **Release** — tag with the release version and `prd`.
355421
- **Manual** (`workflow_dispatch`) — with optional skip-validation toggle.
356422

357-
### Required secrets
423+
#### Required secrets
358424

359425
Galaxy server tokens follow the Ansible naming convention:
360426

@@ -376,11 +442,53 @@ Additional secrets:
376442
| `REGISTRY_USERNAME` / `REGISTRY_PASSWORD` | Container registry credentials |
377443
| `REDHAT_REGISTRY_PASSWORD` | Red Hat registry authentication for base images |
378444

445+
### GitLab CI pipeline (`.gitlab-ci.yml`)
446+
447+
#### Triggers
448+
449+
The pipeline runs when:
450+
451+
- A **Git tag** is pushed, or
452+
- The pipeline is started from the **web UI**, **API**, or an **upstream trigger**.
453+
454+
(There is no default “every push to `main`” rule; adjust `workflow: rules`
455+
in `.gitlab-ci.yml` if you want branch pipelines.)
456+
457+
#### Required CI/CD variables
458+
459+
Use the **same names** as GitHub secrets. Galaxy tokens:
460+
461+
```text
462+
ANSIBLE_GALAXY_SERVER_<ID>_TOKEN
463+
```
464+
465+
Set each under **Settings → CI/CD → Variables**. SCM `token_env_var`
466+
values from `scm_servers` are listed in the header comments of
467+
`.gitlab-ci.yml`.
468+
469+
Registry-related variables:
470+
471+
| Variable | Purpose |
472+
|----------|---------|
473+
| `REGISTRY_USERNAME` / `REGISTRY_PASSWORD` | Push target registry. If unset, the job uses `CI_REGISTRY_USER` / `CI_REGISTRY_PASSWORD` (GitLab Container Registry). |
474+
| `REDHAT_REGISTRY_USERNAME` / `REDHAT_REGISTRY_PASSWORD` | Login to `registry.redhat.io` for Red Hat base images |
475+
476+
Optional: `SKIP_BASE_IMAGE_VALIDATION`, `STORAGE_DRIVER` (e.g. `vfs` for
477+
some runners). The template expects a **podman**-capable image (e.g.
478+
`quay.io/podman/stable`) and **podman 4+** so build `ARG`s are not stored
479+
in image history.
480+
481+
The pipeline uses a single `REGISTRY_AUTHFILE` under the project directory
482+
for `podman login`, `podman build`, and `podman push`, so registries that
483+
require authentication on layer/blob checks (e.g. Quay.io) succeed.
484+
`IMAGE_NAME` is lowercased before tagging and pushing because many OCI
485+
registries reject mixed-case repository paths.
486+
379487
### Token security
380488

381489
- **Galaxy server tokens** are passed as `--build-arg` values. With
382-
`buildah >= 1.24`, `ARG` values do not appear in image history or
383-
metadata.
490+
`buildah >= 1.24` / **podman 4+**, `ARG` values do not appear in image
491+
history or metadata.
384492
- **SCM tokens** are resolved via `envsubst` into the build context
385493
after `ansible-builder create`. The multi-stage build ensures tokens
386494
only exist in intermediate stages, never in the final image.

src/ansible_creator/arg_parser.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ def _add_resource_ee_ci(self, subparser: SubParser[argparse.ArgumentParser]) ->
440440
"""
441441
parser = subparser.add_parser(
442442
"ee-ci",
443-
help="Add a GitHub Action CI workflow for building execution environments.",
443+
help=(
444+
"Add a CI workflow for building execution environments "
445+
"(GitHub Actions or GitLab CI)."
446+
),
444447
)
445448

446449
parser.add_argument(
@@ -452,6 +455,14 @@ def _add_resource_ee_ci(self, subparser: SubParser[argparse.ArgumentParser]) ->
452455
"The default is the current working directory.",
453456
)
454457

458+
parser.add_argument(
459+
"--scm-provider",
460+
dest="scm_provider",
461+
default="github",
462+
choices=["github", "gitlab"],
463+
help="SCM provider to generate CI for. Default: github",
464+
)
465+
455466
self._add_overwrite(parser)
456467
self._add_args_common(parser)
457468

@@ -835,6 +846,15 @@ def _init_ee_project(self, subparser: SubParser[argparse.ArgumentParser]) -> Non
835846
"Overrides the value from --ee-config/--ee-config-file when set explicitly.",
836847
)
837848

849+
parser.add_argument(
850+
"--scm-provider",
851+
dest="scm_provider",
852+
default="github",
853+
choices=["github", "gitlab"],
854+
help="SCM provider for the scaffolded EE CI files (GitHub Actions or GitLab CI). "
855+
"Default: github",
856+
)
857+
838858
self._add_args_common(parser)
839859
self._add_args_init_common(parser)
840860

src/ansible_creator/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Config:
5050
registry_tls_verify: Whether to verify TLS for container registry operations
5151
(login, pull, push, and image builds). None means the user did not
5252
explicitly set this flag, so the EE config file value is preserved.
53+
scm_provider: SCM provider for EE CI scaffolding (github or gitlab).
5354
"""
5455

5556
creator_version: str
@@ -80,6 +81,7 @@ class Config:
8081
ee_name: str = "ansible_sample_ee"
8182
ee_file_name: str = "execution-environment.yml"
8283
registry_tls_verify: bool | None = None
84+
scm_provider: str = "github"
8385

8486
def __post_init__(self) -> None:
8587
"""Post process config values."""

0 commit comments

Comments
 (0)