Skip to content

Commit b97ad76

Browse files
author
Markus Koch
committed
fixing cleanup old container versions
1 parent ba0390d commit b97ad76

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

.github/workflows/cleanup-old-containers.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Cleanup Old SAP-EE Containers
2-
# currently does not work due to GITHUB TOKEN not support in api.github.com
2+
# Token: GITHUB_TOKEN funktioniert nicht ("missing field `id`", siehe
3+
# https://github.com/snok/container-retention-policy/issues/119). Es wird ein klassischer PAT
4+
# benötigt. Anleitung: siehe DEVELOPER.md Abschnitt "Cleanup-Workflow (GHCR)".
35
on:
46
# Erlaube manuelles Starten über die GitHub UI
57
workflow_dispatch:
@@ -16,10 +18,12 @@ jobs:
1618
steps:
1719
# Caution may have issues with multiarch images - see https://github.com/snok/container-retention-policy?tab=readme-ov-file#examples
1820
- name: Delete old sap-ee container images
19-
uses: snok/container-retention-policy@v3.0.0
21+
uses: snok/container-retention-policy@v3.0.1
2022
with:
21-
account: ${{ github.actor}}
22-
token: ${{ secrets.GITHUB_TOKEN }}
23+
# Für Organisation: Org-Name; für User-Repos: wörtlich "user" (laut Action-Doku)
24+
account: ${{ github.event.repository.owner.type == 'User' && 'user' || github.repository_owner }}
25+
# Klassischer PAT mit read:packages + delete:packages (GITHUB_TOKEN funktioniert nicht)
26+
token: ${{ secrets.GHCR_CLEANUP_TOKEN }}
2327
image-names: sap-ee
2428
image-tags: "dev*"
2529
cut-off: 6w

DEVELOPER.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ For the podman login command use your github username with a personal access tok
108108
> `WARNING: image platform (linux/amd64/v8) does not match the expected platform (linux/amd64)`
109109
> It can be safely ignored
110110
111+
## Cleanup-Workflow (GHCR)
112+
113+
Der Workflow `.github/workflows/cleanup-old-containers.yml` löscht alte Container-Images (z. B. `sap-ee:dev*`) aus dem GitHub Container Registry der Organisation. Mit dem temporären `GITHUB_TOKEN` tritt der Fehler „missing field `id`“ auf; es wird ein **klassischer Personal Access Token (PAT)** benötigt.
114+
115+
### Token anlegen (einmalig)
116+
117+
1. **PAT erstellen** (als Benutzer mit Schreibrechten auf die Packages der Organisation):
118+
- GitHub → dein Profil (oben rechts) → **Settings****Developer settings****Personal access tokens****Tokens (classic)****Generate new token (classic)**.
119+
- Scopes: **`read:packages`** und **`delete:packages`** anhaken.
120+
- Unter „Organization access“ die gewünschte Organisation (z. B. `sap-linuxlab`) auf **Grant** setzen, damit der Token auf die Org-Packages zugreifen darf.
121+
- Token erzeugen und den Wert sicher kopieren (nur einmal sichtbar).
122+
123+
2. **Secret im Repository oder in der Organisation ablegen:**
124+
- **Variante A – nur dieses Repo:** Repository → **Settings****Secrets and variables****Actions****New repository secret**. Name: `GHCR_CLEANUP_TOKEN`, Value: der PAT.
125+
- **Variante B – mehrere Repos:** Organisation → **Settings****Secrets and variables****Actions****New organization secret**. Name: `GHCR_CLEANUP_TOKEN`, Value: der PAT. Zugriff auf „Repository access“ beschränken (z. B. nur dieses Repo), wenn gewünscht.
126+
127+
Der Workflow nutzt `account: ${{ github.repository_owner }}`, also den Organisationsnamen – bei Repos unter einer Organisation ist keine weitere Anpassung nötig.
128+
129+
### Alternative Action
130+
131+
Die offizielle Action `actions/delete-package-versions` funktioniert mit `GITHUB_TOKEN`, unterstützt für Container-Packages aber **keine Tag-Muster** (z. B. `dev*`); gefiltert wird nach API-Versionsnamen (Digest), nicht nach Tags. Für „nur `dev*`-Tags bereinigen, 5 behalten, älter als 6 Wochen löschen“ ist `snok/container-retention-policy` mit PAT die passende Wahl.
132+
111133
# Changes for building supported EE for RHAAP
112134

113135
If you want to add supported Automation Hub content, get your Automation Hub token from [here](https://console.redhat.com/ansible/automation-hub/token) and export it in the environment variable `ANSIBLE_GALAXY_SERVER_RH_CERTIFIED_REPO_TOKEN`, login to `registry.redhat.io` with your RedHat credentials and run the following commands:

0 commit comments

Comments
 (0)