Skip to content

Commit e643f67

Browse files
committed
ci: build image and publish to ghcr
1 parent eb38ffd commit e643f67

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Checkout the repository
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
# Get the short commit hash
19+
- name: Get short commit hash
20+
id: vars
21+
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
22+
23+
# Log in to GitHub Docker Registry
24+
- name: Log in to GitHub Docker Registry
25+
run: echo "$" | docker login ghcr.io -u $ --password-stdin
26+
27+
# Build the Docker image
28+
- name: Build Docker image
29+
run: |
30+
REPO_OWNER=$(echo "$" | tr '[:upper:]' '[:lower:]')
31+
REPO_NAME=$(echo "$" | tr '[:upper:]' '[:lower:]')
32+
IMAGE_TAG=$([[ "$" == "push" && "$" =~ ^refs/tags/ ]] && echo "$" || echo "$")
33+
docker build . --file Dockerfile --tag ghcr.io/$REPO_OWNER/$REPO_NAME:${IMAGE_TAG}
34+
docker tag ghcr.io/$REPO_OWNER/$REPO_NAME:${IMAGE_TAG} ghcr.io/$REPO_OWNER/$REPO_NAME:latest
35+
36+
# Push the Docker image to GitHub Container Registry
37+
- name: Push Docker image
38+
run: |
39+
REPO_OWNER=$(echo "$" | tr '[:upper:]' '[:lower:]')
40+
REPO_NAME=$(echo "$" | tr '[:upper:]' '[:lower:]')
41+
IMAGE_TAG=$([[ "$" == "push" && "$" =~ ^refs/tags/ ]] && echo "$" || echo "$")
42+
docker push ghcr.io/$REPO_OWNER/$REPO_NAME:${IMAGE_TAG}
43+
docker push ghcr.io/$REPO_OWNER/$REPO_NAME:latest

0 commit comments

Comments
 (0)