Skip to content

Commit 663a8e3

Browse files
chore: update base image to eclipse-temurin:21-jre-alpine and add git branch
1 parent 36132e8 commit 663a8e3

File tree

8 files changed

+65
-34
lines changed

8 files changed

+65
-34
lines changed

.github/workflows/pre-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ jobs:
7676
build-args: |
7777
VERSION=${{ needs.prepare-a-release.outputs.new_version }}
7878
TAG=${{ needs.prepare-a-release.outputs.new_tag }}
79+
GIT_BRANCH=${{ needs.prepare-a-release.outputs.new_tag }}
7980
tags: |
8081
${{ vars.DOCKER_REGISTRY }}/data-viz-admin:v${{ needs.prepare-a-release.outputs.new_version }}
81-
82+
8283
release-on-github:
8384
needs: build-and-push-docker-image
8485
runs-on: ubuntu-latest

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ jobs:
6666
build-args: |
6767
VERSION=${{ needs.prepare-a-release.outputs.new_version }}
6868
TAG=${{ needs.prepare-a-release.outputs.new_tag }}
69+
GIT_BRANCH=${{ needs.prepare-a-release.outputs.new_tag }}
6970
tags: |
7071
${{ vars.DOCKER_REGISTRY }}/data-viz-admin:latest
7172
${{ vars.DOCKER_REGISTRY }}/data-viz-admin:v${{ needs.prepare-a-release.outputs.new_version }}
72-
73+
7374
release-on-github:
7475
needs: build-and-push-docker-image
7576
runs-on: ubuntu-latest

Dockerfile

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
1-
FROM maven:3-eclipse-temurin-21 AS base
1+
# Stage 1: Download dependencies (cached separately from source code)
2+
FROM maven:3-eclipse-temurin-21 AS dependencies
3+
WORKDIR /app
4+
5+
# Copy only POM files first to cache dependency downloads
6+
COPY pom.xml ./
7+
COPY persistence/pom.xml ./persistence/
8+
COPY web/pom.xml ./web/
9+
COPY forms/pom.xml ./forms/
210

3-
FROM base AS builder
11+
# Download all dependencies (this layer will be cached unless POM files change)
12+
RUN --mount=type=cache,target=/root/.m2 \
13+
mvn -B dependency:go-offline -DskipTests -Dcheckstyle.skip || true
14+
15+
# Stage 2: Build the application
16+
FROM dependencies AS builder
417
WORKDIR /app
518

6-
COPY . /app
7-
# Use cache mounts so dependencies aren't re-downloaded on every build
8-
RUN --mount=type=cache,target=/root/.m2 mvn -B clean install -DskipTests -Dcheckstyle.skip
19+
# Accept git branch/tag as build argument
20+
ARG GIT_BRANCH=unknown
21+
22+
# Now copy source code (changes here won't invalidate dependency cache)
23+
COPY persistence/src ./persistence/src
24+
COPY web/src ./web/src
25+
COPY forms/src ./forms/src
26+
COPY checkstyle.xml checkstyle-suppressions.xml ./
927

10-
# Create directory for extracting the JAR
11-
RUN mkdir -p forms/target/deps
28+
# Build with cache mount for any additional dependencies
29+
# Pass git.closest.tag.name as a Maven property
30+
RUN --mount=type=cache,target=/root/.m2 \
31+
mvn -B clean package -DskipTests -Dcheckstyle.skip -Dgit.closest.tag.name=${GIT_BRANCH}
1232

13-
# Extract the JAR contents
33+
# Stage 3: Extract JAR layers (Spring Boot layered JAR)
1434
FROM builder AS assembler
1535
WORKDIR /app/forms/target/deps
16-
RUN jar -xf ../*.jar
36+
RUN jar -xf ../tcdi-admin-forms-*.jar
1737

18-
# Build the runtime image
38+
# Stage 4: Build the runtime image
1939
FROM eclipse-temurin:21-jre-alpine AS runtime
2040
RUN apk add --no-cache bash curl
2141
WORKDIR /opt/devgateway/tcdi/admin
2242

23-
# Copy the application code
43+
# Copy the extracted application in optimal order for layer caching
2444
COPY --from=assembler /app/forms/target/deps ./deps
2545

26-
# Copy entrypoint script
46+
# Copy entrypoint script and set permissions in one layer
2747
COPY entrypoint.sh ./
28-
EXPOSE 8080
2948
RUN chmod +x entrypoint.sh
49+
50+
EXPOSE 8080
3051
ENTRYPOINT ["/opt/devgateway/tcdi/admin/entrypoint.sh"]
3152
CMD ["admin"]

docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ services:
33
build:
44
context: .
55
dockerfile: Dockerfile
6+
args:
7+
GIT_BRANCH: main
68
restart: unless-stopped
79
environment:
810
SPRING_DATASOURCE_JDBC_URL: "jdbc:postgresql://postgres:5432/tcdi_admin"
@@ -13,7 +15,8 @@ services:
1315
networks:
1416
- backend
1517
depends_on:
16-
- postgres
18+
postgres:
19+
condition: service_healthy
1720

1821

1922
postgres:
@@ -30,7 +33,6 @@ services:
3033
interval: 10s
3134
timeout: 30s
3235
retries: 3
33-
start_period: 50s
3436
networks:
3537
backend:
3638

entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ while IFS='=' read -r -d '' n v; do
1818
fi
1919
done < <(env -0)
2020

21+
# Add git.branch if it exists
22+
if [[ -n "${git.branch}" ]]; then
23+
echo "git.branch=${git.branch}" >> $PROP_FILE
24+
fi
25+
2126
echo "................. Properties ................."
2227
cat $PROP_FILE
2328
echo "................. End Properties ................."

forms/pom.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,6 @@
378378

379379
<plugins>
380380

381-
<!-- <plugin>-->
382-
<!-- <groupId>pl.project13.maven</groupId>-->
383-
<!-- <artifactId>git-commit-id-plugin</artifactId>-->
384-
<!-- <version>2.2.4</version>-->
385-
<!-- <executions>-->
386-
<!-- <execution>-->
387-
<!-- <goals>-->
388-
<!-- <goal>revision</goal>-->
389-
<!-- </goals>-->
390-
<!-- </execution>-->
391-
<!-- </executions>-->
392-
<!-- <configuration>-->
393-
<!-- <dotGitDirectory>${project.basedir}/../../.git</dotGitDirectory>-->
394-
<!-- </configuration>-->
395-
<!-- </plugin>-->
396-
397381
<!-- tag::plugin[] -->
398382
<plugin>
399383
<groupId>com.spotify</groupId>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
toolkit.branch = ${git.branch}
1+
toolkit.branch = ${git.closest.tag.name}

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@
135135

136136
<build>
137137
<plugins>
138+
<plugin>
139+
<groupId>pl.project13.maven</groupId>
140+
<artifactId>git-commit-id-plugin</artifactId>
141+
<version>2.2.4</version>
142+
<executions>
143+
<execution>
144+
<goals>
145+
<goal>revision</goal>
146+
</goals>
147+
</execution>
148+
</executions>
149+
<configuration>
150+
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
151+
<generateGitPropertiesFile>false</generateGitPropertiesFile>
152+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
153+
</configuration>
154+
</plugin>
138155
<plugin>
139156
<groupId>org.apache.maven.plugins</groupId>
140157
<artifactId>maven-checkstyle-plugin</artifactId>

0 commit comments

Comments
 (0)