Skip to content

Commit 0483dc1

Browse files
committed
Add docker image build logic
1 parent 106f91a commit 0483dc1

File tree

5 files changed

+120
-2
lines changed

5 files changed

+120
-2
lines changed

.github/workflows/build-api-gw.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- feature/**
8+
9+
#----- Detect changes in services and trigger builds accordingly ------#
10+
jobs:
11+
build-server:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
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: Cache Gradle packages
24+
uses: actions/cache@v4
25+
with:
26+
path: |
27+
~/.gradle/caches
28+
~/.gradle/wrapper
29+
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
30+
restore-keys: |
31+
gradle-${{ runner.os }}-
32+
33+
- name: Grant execute permission for gradlew
34+
run: chmod +x gradlew
35+
working-directory: server
36+
37+
- name: Log in to GitHub Container Registry
38+
uses: docker/login-action@v3
39+
with:
40+
registry: ghcr.io
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GITHUB_TOKEN }}
43+
44+
- name: Publish image
45+
run: ./gradlew :api-gw:jib
46+
working-directory: server

server/api-gw/build.gradle.kts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,29 @@ dependencyManagement {
77
dependencies {
88
implementation("org.springframework.cloud:spring-cloud-starter-gateway-mvc")
99
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
10+
}
11+
12+
jib {
13+
from {
14+
image = "eclipse-temurin:21-jre-alpine"
15+
}
16+
to {
17+
image = "ghcr.io/aet-devops25/team-continuous-disappointment/api-gw"
18+
tags = setOf("latest")
19+
}
20+
container {
21+
ports = listOf("8080")
22+
23+
environment = mapOf(
24+
"SPRING_PROFILES_ACTIVE" to "production"
25+
)
26+
user = "1000"
27+
28+
creationTime = "USE_CURRENT_TIMESTAMP"
29+
}
30+
31+
32+
dockerClient {
33+
executable = "/usr/local/bin/docker"
34+
}
1035
}

server/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
plugins {
22
id("org.springframework.boot") version "3.3.0" apply false
33
id("io.spring.dependency-management") version "1.1.4" apply false
4+
id("com.google.cloud.tools.jib") version "3.4.1" apply false
45
id("java")
56
}
67

78
subprojects {
89
apply(plugin = "java")
910
apply(plugin = "org.springframework.boot")
1011
apply(plugin = "io.spring.dependency-management")
12+
apply(plugin = "com.google.cloud.tools.jib")
1113

1214
group = "com.continuousdisappointment"
1315
version = "0.0.1-SNAPSHOT"
@@ -43,4 +45,4 @@ subprojects {
4345
tasks.withType<Test> {
4446
useJUnitPlatform()
4547
}
46-
}
48+
}

server/chat/build.gradle.kts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
11
dependencies {
22
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
3+
}
4+
5+
jib {
6+
from {
7+
image = "eclipse-temurin:21-jre-alpine"
8+
}
9+
to {
10+
image = "ghcr.io/aet-devops25/team-continuous-disappointment/chat"
11+
tags = setOf("latest")
12+
}
13+
container {
14+
ports = listOf("8082")
15+
16+
environment = mapOf(
17+
"SPRING_PROFILES_ACTIVE" to "production"
18+
)
19+
user = "1000"
20+
21+
creationTime = "USE_CURRENT_TIMESTAMP"
22+
}
23+
24+
dockerClient {
25+
executable = "/usr/local/bin/docker"
26+
}
327
}

server/user/build.gradle.kts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1-
dependencies {
1+
jib {
2+
from {
3+
image = "eclipse-temurin:21-jre-alpine"
4+
}
5+
to {
6+
image = "ghcr.io/aet-devops25/team-continuous-disappointment/user"
7+
tags = setOf("latest")
8+
}
9+
container {
10+
ports = listOf("8081")
11+
12+
environment = mapOf(
13+
"SPRING_PROFILES_ACTIVE" to "production"
14+
)
15+
user = "1000"
16+
17+
creationTime = "USE_CURRENT_TIMESTAMP"
18+
}
19+
20+
dockerClient {
21+
executable = "/usr/local/bin/docker"
22+
}
223
}

0 commit comments

Comments
 (0)