Skip to content

Commit a311df4

Browse files
committed
update gradle config, add docker build & ci
1 parent 010ce1a commit a311df4

File tree

4 files changed

+124
-4
lines changed

4 files changed

+124
-4
lines changed

.github/workflows/build.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ '**' ]
6+
paths-ignore:
7+
- '**.md'
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Java
17+
uses: actions/setup-java@v4
18+
with:
19+
distribution: zulu
20+
java-version: 17
21+
22+
- name: Setup Gradle
23+
uses: gradle/actions/setup-gradle@v4
24+
25+
- name: Build Lavalink-Config-Server
26+
run: ./gradlew build
27+
28+
- name: Upload Lavalink-Config-Server.jar
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: Lavalink-Config-Server.jar
32+
path: build/libs/Lavalink-Config-Server.jar
33+
34+
build-docker:
35+
needs: build
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
41+
- name: Download Lavalink-Config-Server.jar
42+
uses: actions/download-artifact@v4
43+
with:
44+
name: Lavalink-Config-Server.jar
45+
path: build/libs/
46+
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v3
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
53+
- name: Login to GitHub Container Registry
54+
uses: docker/login-action@v3
55+
with:
56+
registry: ghcr.io
57+
username: ${{ github.repository_owner }}
58+
password: ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Docker Meta ${{ matrix.name }}
61+
id: meta
62+
uses: docker/metadata-action@v5
63+
with:
64+
images: |
65+
ghcr.io/${{ github.repository }}
66+
tags: |
67+
type=ref,event=branch
68+
type=ref,event=pr
69+
type=semver,pattern={{version}}
70+
type=semver,pattern={{major}}.{{minor}}
71+
type=semver,pattern={{major}}
72+
type=sha,prefix=
73+
74+
- name: Docker Build ${{ matrix.name }} and Push
75+
uses: docker/build-push-action@v6
76+
with:
77+
file: Dockerfile
78+
context: .
79+
platforms: linux/amd64,linux/arm64/v8
80+
push: true
81+
tags: ${{ steps.meta.outputs.tags }}
82+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM azul/zulu-openjdk-alpine:21-jre-headless-latest
2+
3+
# Run as non-root user
4+
RUN addgroup -g 322 -S lavalink && \
5+
adduser -u 322 -S lavalink lavalink
6+
7+
WORKDIR /opt/Lavalink-Config-Server
8+
9+
RUN chown -R lavalink:lavalink /opt/Lavalink-Config-Server
10+
11+
USER lavalink
12+
13+
COPY build/libs/Lavalink-Config-Server.jar Lavalink-Config-Server.jar
14+
15+
ENTRYPOINT ["java", "-jar"]
16+
17+
CMD ["Lavalink-Config-Server.jar"]

build.gradle.kts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
import org.ajoberstar.grgit.Grgit
2+
13
plugins {
24
java
35
application
6+
id("org.ajoberstar.grgit") version "5.2.0"
7+
id("org.springframework.boot") version "3.3.0"
48
}
59

10+
val gitVersion = versionFromGit()
11+
logger.lifecycle("Version: $gitVersion")
12+
613
group = "dev.lavalink.config.server"
7-
version = "1.0-SNAPSHOT"
814

915
application {
10-
mainClass = "lavalink.server.Launcher"
16+
mainClass = "dev.lavalink.config.server.Launcher"
1117
}
1218

1319
repositories {
@@ -19,3 +25,18 @@ dependencies {
1925
implementation("org.springframework.cloud:spring-cloud-config-server:4.2.2")
2026
implementation("ch.qos.logback:logback-classic:1.5.6")
2127
}
28+
29+
fun versionFromGit(): String {
30+
Grgit.open(mapOf("currentDir" to project.rootDir)).use { git ->
31+
val headTag = git.tag
32+
.list()
33+
.find { it.commit.id == git.head().id }
34+
35+
val clean = git.status().isClean || System.getenv("CI") != null
36+
if (!clean) {
37+
logger.lifecycle("Git state is dirty, version is a snapshot.")
38+
}
39+
40+
return if (headTag != null && clean) headTag.name else "${git.head().id}-SNAPSHOT"
41+
}
42+
}

src/main/java/dev/lavalink/config/server/Main.java renamed to src/main/java/dev/lavalink/config/server/Launcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
@SpringBootApplication
88
@EnableConfigServer
9-
public class Main {
9+
public class Launcher {
1010

1111
public static void main(String[] args) {
12-
SpringApplication.run(Main.class, args);
12+
SpringApplication.run(Launcher.class, args);
1313
}
1414

1515
}

0 commit comments

Comments
 (0)