14 changed files with 184 additions and 110 deletions
@ -0,0 +1,60 @@ |
|||||||
|
name: Cleanup Container Images |
||||||
|
|
||||||
|
on: |
||||||
|
delete: |
||||||
|
|
||||||
|
concurrency: |
||||||
|
group: ${{ github.workflow }}-${{ github.event.ref }} |
||||||
|
cancel-in-progress: false |
||||||
|
|
||||||
|
jobs: |
||||||
|
cleanup-images: |
||||||
|
name: Delete branch container images |
||||||
|
if: | |
||||||
|
github.event.ref != 'main' && |
||||||
|
github.event.ref != 'rc' && |
||||||
|
github.event.ref != 'hotfix-rc' |
||||||
|
runs-on: ubuntu-24.04 |
||||||
|
permissions: |
||||||
|
packages: write |
||||||
|
steps: |
||||||
|
- name: Generate image tag to delete |
||||||
|
id: tag |
||||||
|
env: |
||||||
|
EVENT_REF: ${{ github.event.ref }} |
||||||
|
run: | |
||||||
|
# Sanitize deleted branch name to match build workflow tag generation |
||||||
|
BRANCH_NAME="${EVENT_REF}" |
||||||
|
IMAGE_TAG=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9._-]+/-/g; s/-+/-/g; s/^-+|-+$//g' | cut -c1-128 | sed -E 's/[.-]$//') |
||||||
|
|
||||||
|
if [[ -z "$IMAGE_TAG" ]]; then |
||||||
|
echo "ERROR: Failed to generate valid IMAGE_TAG from EVENT_REF: $EVENT_REF" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
echo "tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT" |
||||||
|
|
||||||
|
- name: Delete container image version |
||||||
|
env: |
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
||||||
|
IMAGE_TAG: ${{ steps.tag.outputs.tag }} |
||||||
|
run: | |
||||||
|
# Get the version ID for this specific tag |
||||||
|
VERSION_ID=$(gh api \ |
||||||
|
-H "Accept: application/vnd.github+json" \ |
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \ |
||||||
|
"/orgs/bitwarden/packages/container/lite/versions" \ |
||||||
|
--jq ".[] | select(.metadata.container.tags[] == \"$IMAGE_TAG\") | .id" \ |
||||||
|
| head -1) |
||||||
|
|
||||||
|
if [[ -n "$VERSION_ID" ]]; then |
||||||
|
echo "Deleting image with tag: $IMAGE_TAG (version ID: $VERSION_ID)" |
||||||
|
gh api \ |
||||||
|
--method DELETE \ |
||||||
|
-H "Accept: application/vnd.github+json" \ |
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \ |
||||||
|
"/orgs/bitwarden/packages/container/lite/versions/$VERSION_ID" |
||||||
|
echo "Successfully deleted image" |
||||||
|
else |
||||||
|
echo "No image found with tag: $IMAGE_TAG" |
||||||
|
fi |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
# Git files |
||||||
|
.git |
||||||
|
.gitignore |
||||||
|
.gitattributes |
||||||
|
|
||||||
|
# CI/CD |
||||||
|
.github |
||||||
|
|
||||||
|
# Documentation |
||||||
|
*.md |
||||||
|
README |
||||||
|
LICENSE |
||||||
|
|
||||||
|
# IDE and editor files |
||||||
|
.vscode |
||||||
|
.idea |
||||||
|
*.swp |
||||||
|
*.swo |
||||||
|
*~ |
||||||
|
.DS_Store |
||||||
|
|
||||||
|
# Logs |
||||||
|
*.log |
||||||
|
logs/ |
||||||
|
|
||||||
|
# Temporary files |
||||||
|
tmp/ |
||||||
|
temp/ |
||||||
|
*.tmp |
||||||
|
|
||||||
|
# Build artifacts (if any local builds exist) |
||||||
|
*.exe |
||||||
|
*.dll |
||||||
|
*.so |
||||||
|
*.dylib |
||||||
|
|
||||||
|
# Editor config |
||||||
|
.editorconfig |
||||||
|
|
||||||
|
# Test files |
||||||
|
**/test/ |
||||||
|
**/tests/ |
||||||
|
**/*_test.go |
||||||
|
**/*_test.py |
||||||
|
**/*.test.js |
||||||
|
|
||||||
|
# Node modules (if any exist locally) |
||||||
|
**/node_modules/ |
||||||
|
|
||||||
|
# Environment files |
||||||
|
.env |
||||||
|
.env.* |
||||||
|
!.env.example |
||||||
@ -1,3 +1,3 @@ |
|||||||
COMPOSE_PROJECT_NAME=bitwarden |
COMPOSE_PROJECT_NAME=bitwarden |
||||||
REGISTRY=bitwarden |
REGISTRY=ghcr.io/bitwarden |
||||||
TAG=dev |
TAG=dev |
||||||
|
|||||||
Loading…
Reference in new issue