Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/compose-oci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ jobs:
run: |
image="ghcr.io/${GITHUB_REPOSITORY,,}/compose"
while IFS= read -r compose_file; do
artifact_tag=${IMAGE_TAG}
artifact_image=${image}
filename=${compose_file##*/}
if [[ "${filename}" != "docker-compose.yml" ]]; then
suffix=${filename#docker-compose.}
suffix=${suffix%.yml}
artifact_tag="${IMAGE_TAG}-${suffix}"
deployment=${filename#docker-compose.}
deployment=${deployment%.yml}
deployment=${deployment//_/-}
artifact_image="${image}/${deployment,,}"
fi
docker compose -f "${compose_file}" publish --with-env --yes "${image}:${artifact_tag}"
docker compose -f "${compose_file}" publish --with-env --yes "${artifact_image}:${IMAGE_TAG}"
done < <(find "${COMPOSE_FOLDER}" -maxdepth 1 -type f -name 'docker-compose*.yml' | sort)
82 changes: 54 additions & 28 deletions .github/workflows/ghcr-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ name: ghcr-cleanup
on:
workflow_call:
inputs:
images:
description: Comma-separated images below the repository package, for example `server,client` for `<repo>/server` and `<repo>/client`. The repository package itself is always cleaned.
required: false
type: string
default: ""
cleanup-compose:
description: Clean github.repository/compose
description: Clean the Compose packages, github.repository/compose[/<deployment>]
required: false
type: boolean
default: true
cleanup-helm:
description: Clean github.repository/helm
description: Clean the Helm packages, github.repository/helm/<chart>
required: false
type: boolean
default: true
Expand All @@ -26,29 +31,50 @@ jobs:
- name: Determine package names
id: package
shell: bash
env:
IMAGES: ${{ inputs.images }}
run: |
repository_name='${{ github.event.repository.name }}'
echo "helm_chart_name=${repository_name//_/-}" >> "$GITHUB_OUTPUT"
launch_suffixes=
while IFS= read -r chart_file; do
chart_version=$(sed -nE 's/^version:[[:space:]]*([^[:space:]#]+).*$/\1/p' "${chart_file}")
app_version=$(sed -nE 's/^appVersion:[[:space:]]*([^[:space:]#]+).*$/\1/p' "${chart_file}")
if [[ "${chart_version}" == "${app_version}-"* ]]; then
launch_suffix=${chart_version#"${app_version}-"}
launch_suffix=${launch_suffix//./\\.}
launch_suffixes="${launch_suffixes:+${launch_suffixes}|}${launch_suffix}"
repository_name=${repository_name,,}

image_packages=${repository_name}
IFS=',' read -ra images <<< "${IMAGES}"
for image in "${images[@]}"; do
image=${image//[[:space:]]/}
if [[ -n "${image}" ]]; then
image_packages="${image_packages},${repository_name}/${image}"
fi
done

# docker-compose.yml -> <repo>/compose, docker-compose.<deployment>.yml -> <repo>/compose/<deployment>
compose_packages=
while IFS= read -r compose_file; do
filename=${compose_file##*/}
package=${repository_name}/compose
if [[ "${filename}" != "docker-compose.yml" ]]; then
deployment=${filename#docker-compose.}
deployment=${deployment%.yml}
deployment=${deployment//_/-}
package="${package}/${deployment,,}"
fi
done < <(find deployment/helm -mindepth 2 -maxdepth 2 -type f -name Chart.yaml 2>/dev/null | sort)
if [[ -n "${launch_suffixes}" ]]; then
helm_exclude_tags="^[0-9]+\\.[0-9]+\\.[0-9]+(-(${launch_suffixes}))?(-main)?$"
else
helm_exclude_tags='^[0-9]+\.[0-9]+\.[0-9]+(-main)?$'
fi
echo "helm_exclude_tags=${helm_exclude_tags}" >> "$GITHUB_OUTPUT"
- name: Cleanup ${{ github.repository }}
compose_packages="${compose_packages:+${compose_packages},}${package}"
done < <(find deployment/compose -maxdepth 1 -type f -name 'docker-compose*.yml' 2>/dev/null | sort)

# helm push appends the chart name: <repo>/helm/<chart>
helm_packages=
while IFS= read -r chart_name; do
helm_packages="${helm_packages:+${helm_packages},}${repository_name}/helm/${chart_name}"
done < <(find deployment/helm -mindepth 1 -maxdepth 2 -type f -name Chart.yaml 2>/dev/null | sort | xargs -r sed -nE 's/^name:[[:space:]]*([^[:space:]#]+).*$/\1/p' | sort -u)

{
echo "image_packages=${image_packages}"
echo "compose_packages=${compose_packages}"
echo "helm_packages=${helm_packages}"
} >> "$GITHUB_OUTPUT"
- name: Cleanup ${{ steps.package.outputs.image_packages }}
uses: dataaxiom/ghcr-cleanup-action@v1.2.2
with:
packages: ${{ github.event.repository.name }}
packages: ${{ steps.package.outputs.image_packages }}
dry-run: false
use-regex: true
skip-regex-checks: true
Expand All @@ -60,32 +86,32 @@ jobs:
delete-partial-images: true
delete-orphaned-images: true
validate: true
- name: Cleanup ${{ github.repository }}/compose
if: ${{ inputs['cleanup-compose'] }}
- name: Cleanup ${{ steps.package.outputs.compose_packages }}
if: ${{ inputs['cleanup-compose'] && steps.package.outputs.compose_packages != '' }}
uses: dataaxiom/ghcr-cleanup-action@v1.2.2
with:
packages: ${{ github.event.repository.name }}/compose
packages: ${{ steps.package.outputs.compose_packages }}
dry-run: false
use-regex: true
skip-regex-checks: true
older-than: 1 month
exclude-tags: '^(v[0-9]+\.[0-9]+\.[0-9]+|main)$' # v1.2.3, main
exclude-tags: '^(v[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+\.[0-9]+\.[0-9]+)?|main)$' # v1.2.3, v1.2.3-4.5.6, main
delete-tags: ".*"
delete-untagged: true
delete-ghost-images: true
delete-partial-images: true
delete-orphaned-images: true
validate: true
- name: Cleanup ${{ github.event.repository.name }}/helm/${{ steps.package.outputs.helm_chart_name }}
if: ${{ inputs['cleanup-helm'] }}
- name: Cleanup ${{ steps.package.outputs.helm_packages }}
if: ${{ inputs['cleanup-helm'] && steps.package.outputs.helm_packages != '' }}
uses: dataaxiom/ghcr-cleanup-action@v1.2.2
with:
packages: ${{ github.event.repository.name }}/helm/${{ steps.package.outputs.helm_chart_name }}
packages: ${{ steps.package.outputs.helm_packages }}
dry-run: false
use-regex: true
skip-regex-checks: true
older-than: 1 month
exclude-tags: ${{ steps.package.outputs.helm_exclude_tags }} # 1.2.3, 1.2.3-<launch>, *-main
exclude-tags: '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+\.[0-9]+\.[0-9]+)?(-main)?$' # 1.2.3, 1.2.3-4.5.6, *-main
delete-tags: ".*"
delete-untagged: true
delete-ghost-images: true
Expand Down
11 changes: 6 additions & 5 deletions .gitlab-ci.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ compose-oci:
- echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
- |
for compose_file in $COMPOSE_FILES; do
artifact_tag=$COMPOSE_IMAGE_TAG
artifact_image=$COMPOSE_IMAGE_NAME
filename=${compose_file##*/}
if [ "$filename" != docker-compose.yml ]; then
suffix=${filename#docker-compose.}
suffix=${suffix%.yml}
artifact_tag="$COMPOSE_IMAGE_TAG-$suffix"
deployment=${filename#docker-compose.}
deployment=${deployment%.yml}
deployment=$(echo "$deployment" | tr '_' '-' | tr '[:upper:]' '[:lower:]')
artifact_image="$COMPOSE_IMAGE_NAME/$deployment"
fi
docker compose -f "$compose_file" publish --with-env --yes "$COMPOSE_IMAGE_NAME:$artifact_tag"
docker compose -f "$compose_file" publish --with-env --yes "$artifact_image:$COMPOSE_IMAGE_TAG"
done

helm-oci:
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ To check whether the committed Compose file is up to date without changing it, r

The generator expects a ROS package subdirectory with launch files in `launch/`. A package-level `<package>_launch.py` remains the exclusive default and generates `deployment/compose/docker-compose.yml`. Without that default, a single launch file that directly starts the package generates the same output. Multiple directly launching files generate `deployment/compose/docker-compose.<name>.yml`, where `<name>` is the filename without `_launch.py` or `.launch.py`. Launch files that only include other launch files do not create a deployment.

Multi-launch deployments use each launch file's default node name and parameter file. The GitHub and GitLab `compose-oci` jobs publish them below the existing Compose image name with the launch name appended to the ref tag, for example `compose:main-cam_generator`. Single-launch artifact names and tags remain unchanged.
Multi-launch deployments use each launch file's default node name and parameter file. The GitHub and GitLab `compose-oci` jobs publish each of them to its own package below the Compose image name, named after the launch with underscores converted to hyphens, for example `compose/cam-generator:main`. A single `docker-compose.yml` is published to `compose:<ref>`. See [Artifact Naming](#artifact-naming).

Each directly launching file must define at least one `Node` and `DeclareLaunchArgument(...)` entries. A `remappable_topics` list is optional and only controls which topic remaps are exposed and grouped as Compose environment variables. The generator owns `docker-compose.yml` and `docker-compose.*.yml` below `deployment/compose`; generation removes obsolete outputs and `--check` reports them.

Expand All @@ -180,7 +180,7 @@ Use [`generate_helm.py`](scripts/generate_helm.py) to generate `helm/Chart.yaml`
.openads-dev-environment/scripts/generate_helm.py --check
```

A single launch deployment keeps the existing `deployment/helm/Chart.yaml` and `deployment/helm/values.yaml` paths, chart name, and version. Multiple directly launching files generate one chart below `deployment/helm/<name>/` per launch file. All charts use the same package-derived chart name and therefore share one OCI repository. Multi-launch chart versions append the launch name with underscores converted to hyphens, for example `1.0.0-first-node`; branch builds append the Git ref afterwards. The Helm OCI workflows discover, package, publish, and clean up all generated charts. Generation pins the `openadservice` dependency to the template version, while `--check` also accepts a newer version in the repository.
A single launch deployment keeps the existing `deployment/helm/Chart.yaml` and `deployment/helm/values.yaml` paths, chart name, and version. Multiple directly launching files generate one chart below `deployment/helm/<name>/` per launch file. Each chart is named after its launch file with underscores converted to hyphens, for example `first-node`, keeps the package version and is therefore published to its own OCI repository, `helm/first-node`. Branch builds append the Git ref to the version. The Helm OCI workflows discover, package, publish, and clean up all generated charts. Generation pins the `openadservice` dependency to the template version, while `--check` also accepts a newer version in the repository. See [Artifact Naming](#artifact-naming).

### Consistency Checker

Expand Down Expand Up @@ -228,5 +228,17 @@ This repository stores CI workflow templates for the following use cases. CI wor
| `consistency` | Runs the [consistency checker](#consistency-checker) to check for repository consistency and convention adherence. |
| `docker-ros` | Uses [docker-ros](https://github.com/ika-rwth-aachen/docker-ros) to build, test, and push a container image containing the ROS packages of the repository. |
| `docs` | Builds and deploys documentation using [GitHub Pages](https://docs.github.com/en/pages) or [GitLab Pages](https://docs.gitlab.com/ee/user/project/pages/). |
| `ghcr-cleanup` | Cleans up unused images in the GitHub Container Registry. |
| `ghcr-cleanup` | Deletes branch builds and untagged images older than a month from the repository's image, Compose and Helm packages in the GitHub Container Registry; releases and `main` are kept. Further images below the repository package are passed with `images`, for example `images: server,client`. |
| `helm-oci` | Publishes the repository's single- or multi-launch Helm charts as OCI artifacts to the configured container registry. |

#### Artifact Naming

The package path says what an artifact is, the tag says which state of the repository it was built from. A deployment name appears in the path only when a repository has more than one deployment; Helm always appends the chart name. Images follow [docker-ros](https://github.com/ika-rwth-aachen/docker-ros).
Comment thread
lukaszanger marked this conversation as resolved.
Resolved

| Artifact | Package | Release `v1.2.3` | `main` | Branch `feature/x` |
| --- | --- | --- | --- | --- |
| Image | `<repo>`, further images `<repo>/<image>` | `v1.2.3`, `v1.2.3-dev`, `v1.2.3-slim` | `latest`, `latest-dev`, `latest-slim` | `latest_feature-x_ci`, `latest-dev_feature-x_ci`, `latest-slim_feature-x_ci` |
| Compose | `<repo>/compose`, or `<repo>/compose/<deployment>` | `v1.2.3` | `main` | `feature-x` |
| Helm | `<repo>/helm/<chart>` | `1.2.3` | `1.2.3-main` | `1.2.3-feature-x` |

Helm needs the version first because chart versions must be SemVer.
7 changes: 3 additions & 4 deletions scripts/generate_helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ def render_helm(
multi_launch: bool,
) -> tuple[str, str]:
launch_stem = launch_file_stem(Path(launch_data.launch_file_name))
chart_name = compose_service_name(package_metadata.name)
chart_version = (
f"{package_metadata.version}-{compose_service_name(launch_stem)}" if multi_launch else package_metadata.version
)
# helm push appends the chart name to the OCI path: <repo>/helm/<chart_name>.
chart_name = compose_service_name(launch_stem if multi_launch else package_metadata.name)
chart_version = package_metadata.version

arguments = sorted_launch_arguments(launch_data)
input_variables, output_variables, other_topic_variables = topic_environment_variables(
Expand Down
22 changes: 14 additions & 8 deletions tests/test_generate_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
COMPOSE_DIR = Path("deployment/compose")
GITLAB_CI_TEMPLATE = DEV_ENV_ROOT / ".gitlab-ci.template.yml"
GITHUB_COMPOSE_WORKFLOW = DEV_ENV_ROOT / ".github" / "workflows" / "compose-oci.yml"
GITHUB_CLEANUP_WORKFLOW = DEV_ENV_ROOT / ".github" / "workflows" / "ghcr-cleanup.yml"
MULTI_LAUNCH_FIXTURE = FIXTURES_DIR / "sample_pkg_multi_launch"
GENERATOR_SPEC = importlib.util.spec_from_file_location("compose_generator_under_test", GENERATOR_SCRIPT)
assert GENERATOR_SPEC is not None and GENERATOR_SPEC.loader is not None
Expand Down Expand Up @@ -129,20 +130,25 @@ def test_generator_rejects_multi_launch_name_collisions() -> None:
GENERATOR_MODULE.compose_paths_for_launch_files([Path("duplicate.launch.py"), Path("duplicate_launch.py")])


def test_oci_workflows_derive_sorted_multi_launch_suffix_tags() -> None:
def test_oci_workflows_publish_multi_launch_deployments_to_own_packages() -> None:
gitlab_ci = GITLAB_CI_TEMPLATE.read_text(encoding="utf-8")
github_workflow = GITHUB_COMPOSE_WORKFLOW.read_text(encoding="utf-8")
cleanup_workflow = GITHUB_CLEANUP_WORKFLOW.read_text(encoding="utf-8")

for workflow in (gitlab_ci, github_workflow):
for workflow in (gitlab_ci, github_workflow, cleanup_workflow):
assert "-maxdepth 1 -type f -name 'docker-compose*.yml'" in workflow
assert "| sort" in workflow
assert "filename=${compose_file##*/}" in workflow
assert "suffix=${filename#docker-compose.}" in workflow
assert "suffix=${suffix%.yml}" in workflow

assert 'artifact_tag="$COMPOSE_IMAGE_TAG-$suffix"' in gitlab_ci
assert 'docker compose -f "$compose_file" publish --with-env --yes' in gitlab_ci
assert 'artifact_tag="${IMAGE_TAG}-${suffix}"' in github_workflow
assert "deployment=${filename#docker-compose.}" in workflow
assert "deployment=${deployment%.yml}" in workflow

assert 'artifact_image="$COMPOSE_IMAGE_NAME/$deployment"' in gitlab_ci
assert 'publish --with-env --yes "$artifact_image:$COMPOSE_IMAGE_TAG"' in gitlab_ci
assert 'artifact_image="${image}/${deployment,,}"' in github_workflow
assert 'publish --with-env --yes "${artifact_image}:${IMAGE_TAG}"' in github_workflow
assert 'package="${package}/${deployment,,}"' in cleanup_workflow
assert "-$suffix" not in gitlab_ci
assert "-${suffix}" not in github_workflow
assert "COMPOSE_FOLDER: deployment/compose" in gitlab_ci
assert "COMPOSE_FILE:" not in gitlab_ci
assert "compose-folder:" in github_workflow
Expand Down
18 changes: 9 additions & 9 deletions tests/test_generate_helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def test_generate_helm_creates_launch_specific_charts(tmp_path: Path) -> None:
second_chart = (helm_dir / "second_node" / "Chart.yaml").read_text(encoding="utf-8")
second_values = (helm_dir / "second_node" / "values.yaml").read_text(encoding="utf-8")

assert "name: sample-pkg-multi-launch\n" in first_chart
assert "name: sample-pkg-multi-launch\n" in second_chart
assert "version: 1.0.0-first-node\n" in first_chart
assert "version: 1.0.0-second-node\n" in second_chart
assert "name: first-node\n" in first_chart
assert "name: second-node\n" in second_chart
assert "version: 1.0.0\n" in first_chart
assert "version: 1.0.0\n" in second_chart
assert "appVersion: 1.0.0\n" in first_chart
assert "appVersion: 1.0.0\n" in second_chart
assert "NAME: first_node\n" in first_values
Expand Down Expand Up @@ -234,8 +234,8 @@ def test_helm_oci_workflows_discover_and_publish_multiple_charts() -> None:
assert "helm package" in workflow
assert "helm push" in workflow

assert "helm_chart_name=" in cleanup_workflow
assert "packages: ${{ github.event.repository.name }}/helm/${{ steps.package.outputs.helm_chart_name }}" in cleanup_workflow
assert "helm_exclude_tags=" in cleanup_workflow
assert "exclude-tags: ${{ steps.package.outputs.helm_exclude_tags }}" in cleanup_workflow
assert "helm_packages=" not in cleanup_workflow
assert "find deployment/helm -mindepth 1 -maxdepth 2 -type f -name Chart.yaml" in cleanup_workflow
assert "${repository_name}/helm/${chart_name}" in cleanup_workflow
assert "packages: ${{ steps.package.outputs.helm_packages }}" in cleanup_workflow
assert "steps.package.outputs.helm_packages != ''" in cleanup_workflow
assert "launch_suffix" not in cleanup_workflow
Loading