Skip to content

Commit 601db57

Browse files
committed
add an action to build and publish docker image
1 parent 24ea924 commit 601db57

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

.github/workflows/docker.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build and push docker image
2+
on:
3+
push:
4+
branches: [ main, development ]
5+
6+
jobs:
7+
push:
8+
name: Build and Push Docker Image
9+
runs-on: ubuntu-latest
10+
permissions:
11+
packages: write
12+
contents: read
13+
steps:
14+
- name: Check out the repo
15+
uses: actions/checkout@v5
16+
17+
- name: Set up JDK 21
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: 21
22+
23+
- name: Setup Gradle
24+
uses: gradle/actions/setup-gradle@v5
25+
26+
- name: Build container image (Ktor/Jib)
27+
run: ./gradlew --no-daemon buildImage
28+
29+
- name: Log in to GHCR
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract Docker metadata (tags, labels)
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ghcr.io/${{ github.repository }}
41+
tags: |
42+
type=sha
43+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
44+
45+
- name: Load, tag and push
46+
run: |
47+
LOCAL_IMAGE=$(docker load -i build/jib-image.tar | awk '/Loaded image:/ {print $3; exit}')
48+
for tag in ${{ steps.meta.outputs.tags }}; do
49+
docker tag "$LOCAL_IMAGE" "$tag"
50+
docker push "$tag"
51+
done

0 commit comments

Comments
 (0)