-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a new image and delete for every branch
- Loading branch information
Showing
5 changed files
with
56 additions
and
172 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |