Skip to content

Commit 19c4093

Browse files
committed
Initial CI workflow
1 parent 7c9be41 commit 19c4093

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
on: push
2+
3+
permissions:
4+
packages: write
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Set up JDK 21
13+
uses: actions/setup-java@v3
14+
with:
15+
java-version: 21
16+
distribution: temurin
17+
18+
- name: Docker Metadata
19+
id: docker-metadata
20+
uses: docker/metadata-action@v5
21+
with:
22+
# won't be used but is required by the action
23+
images: dummy
24+
tags: |
25+
type=semver,pattern=v{{major}}
26+
type=semver,pattern=v{{major}}.{{minor}}
27+
type=semver,pattern=v{{version}}
28+
type=ref,event=tag
29+
type=ref,event=branch
30+
type=ref,event=pr
31+
32+
- name: Setup gradle
33+
uses: gradle/actions/setup-gradle@v3
34+
35+
- name: Build docker image
36+
id: build-docker-image
37+
run: |
38+
additional_tags="$(echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr '\n' ' ' | sed 's/dummy://g')"
39+
40+
application_version="$(./gradlew properties -q | awk '/^version:/ {print $2}')"
41+
# unique version like `2.6.1-69` - immutable
42+
full_version="$application_version-${{github.run_number}}"
43+
44+
./gradlew \
45+
-Pme.snoty.docker.tags="$full_version $additional_tags" \
46+
-Pme.snoty.github.run="${{github.run_id}}:${{github.run_number}}" \
47+
jibDockerBuild
48+
49+
- name: Log in to GHCR
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ghcr.io
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Push docker image
57+
run: docker push --all-tags ghcr.io/snotyme/snoty-backend
58+
59+
- name: Upload JAR
60+
uses: actions/upload-artifact@v3
61+
with:
62+
name: artifacts
63+
path: build/libs

build.gradle.kts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io.github.simulatan.gradle.plugin.buildinfo.configuration.BuildInfoExtension
22
import io.github.simulatan.gradle.plugin.buildinfo.configuration.PropertiesOutputLocation
3+
import org.eclipse.jgit.api.Git
34
import org.jetbrains.gradle.ext.Application
45
import org.jetbrains.gradle.ext.runConfigurations
56
import org.jetbrains.gradle.ext.settings
@@ -134,7 +135,7 @@ jib {
134135
image = "eclipse-temurin:21-jre-alpine"
135136
}
136137
to {
137-
val allTags = project.properties["snoty.docker.tags"]?.toString()?.split(" ")?.toSet()
138+
val allTags = project.properties["me.snoty.docker.tags"]?.toString()?.trim()?.split(" ")?.toSet()
138139
?: setOf(version.toString())
139140
image = "ghcr.io/snotyme/snoty-backend:${allTags.first()}"
140141
// workaround for the TERRIBLE design decisions of the JIB developers to
@@ -148,6 +149,30 @@ jib {
148149
creationTime = "USE_CURRENT_TIMESTAMP"
149150
appRoot = "/app"
150151
workingDirectory = "/app"
152+
ports = listOf("8080")
153+
val (ghaRunId, ghaRunNumber) =
154+
project.properties["me.snoty.github.run"]?.toString()?.split(":") ?: listOf(null, null)
155+
labels = mapOf(
156+
"org.opencontainers.image.title" to "snoty-backend",
157+
"org.opencontainers.image.description" to "Backend for the snoty project",
158+
"org.opencontainers.image.url" to "https://github.com/SnotyMe/snoty-backend/pkgs/container/snoty-backend",
159+
*Git.open(project.rootDir).use { git ->
160+
val headRef = git.repository.resolve("HEAD").name
161+
arrayOf(
162+
"org.opencontainers.image.revision" to headRef,
163+
// source to https version of the git repository
164+
"org.opencontainers.image.source" to git.repository.config.getString("remote", "origin", "url")
165+
.replace(":", "/")
166+
.replace("git@", "https://")
167+
.replace(".git", "")
168+
+ "/tree/$headRef"
169+
)
170+
},
171+
*if (ghaRunId != null && ghaRunNumber != null) arrayOf(
172+
"com.github.actions.run.id" to ghaRunId,
173+
"com.github.actions.run.number" to ghaRunNumber
174+
) else arrayOf()
175+
)
151176
}
152177
}
153178

0 commit comments

Comments
 (0)