Last active
May 9, 2024 18:06
-
-
Save elnexreal/a6133105b90905ce050a262612ae8a0c to your computer and use it in GitHub Desktop.
Automatically pushes the current Docker container to the GitHub Container Registery
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
name: Build and Push container to GHCR | |
on: | |
push: | |
tags: "*" | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Login to GitHub Container Registery (GHCR) | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | |
- name: Build the image | |
run: | | |
docker build -t ${{ github.event.repository.name }} . | |
- name: Push the latest build | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
docker tag ${{ github.event.repository.name }} $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTES
MAJOR.MINOR.PATCH
(should not contain thev
prefix, otherwise the workflow won't run)packages
access to the repo using the workflow (how to)