-
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.
add github action to create docker image
- Loading branch information
1 parent
90ab938
commit d5252f5
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
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,42 @@ | ||
name: Build and Push Docker Image to GHCR | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' # Trigger only on tags that start with 'v' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Check out the code | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# Log in to GitHub Container Registry | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} # GitHub token is automatically provided | ||
|
||
# Extract version from tag (remove leading 'v') | ||
- name: Extract version | ||
id: version | ||
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV | ||
|
||
# Build the Docker image | ||
- name: Build Docker image | ||
run: | | ||
docker build -t ghcr.io/${{ github.repository }}:${{ env.VERSION }} -t ghcr.io/${{ github.repository }}:latest . | ||
# Push the Docker image to GitHub Container Registry | ||
- name: Push Docker image | ||
run: | | ||
docker push ghcr.io/${{ github.repository }}:${{ env.VERSION }} | ||
- name: Push Docker image with 'latest' tag | ||
run: | | ||
docker push ghcr.io/${{ github.repository }}:latest |