Skip to content

Commit

Permalink
create a new image and delete for every branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mi3lix9 committed Jun 20, 2024
1 parent 37ea860 commit fcdbf2d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 172 deletions.
50 changes: 0 additions & 50 deletions .github/workflows/create-docker-compose-by-branch.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/create-docker-image-by-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and Push to GHCR

on:
push:
branches:
- "**"

jobs:
build_and_push:
permissions:
packages: write
contents: read

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Build and Push the Image to GHCR
run: |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
if [ "${{ github.ref_name }}" == "main" ]; then
TAG="latest"
else
TAG="${{ github.ref_name }}"
fi
docker build -t ghcr.io/${{ github.repository }}:$TAG .
docker push ghcr.io/${{ github.repository }}:$TAG
61 changes: 0 additions & 61 deletions .github/workflows/create-docker-image-develop.yml

This file was deleted.

61 changes: 0 additions & 61 deletions .github/workflows/create-docker-image-latest.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/delete-docker-image-with-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Remove Image from GHCR

on:
delete:
branches:
- "**"

jobs:
remove_image:
permissions:
packages: write
contents: read

runs-on: ubuntu-latest

steps:
- name: Authenticate to GitHub Container Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Remove Image from GHCR
run: |
IMAGE_NAME=ghcr.io/${{ github.repository }}:${{ github.ref_name }}
docker pull $IMAGE_NAME || echo "Image not found, skipping removal"
docker rmi $IMAGE_NAME || echo "Failed to remove image locally"
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://ghcr.io/v2/${{ github.repository }}/manifests/$(docker manifest inspect $IMAGE_NAME -v | jq -r .Descriptor.digest)" \
|| echo "Failed to remove image from GHCR"

0 comments on commit fcdbf2d

Please sign in to comment.