Skip to content

Commit 86dfd27

Browse files
Merge pull request #39 from devgateway/task/update-docker-image
2 parents c750a5d + 663a8e3 commit 86dfd27

File tree

8 files changed

+71
-36
lines changed

8 files changed

+71
-36
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: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
1-
FROM maven:3-amazoncorretto-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
19-
FROM openjdk:21-jdk-slim AS runtime
38+
# Stage 4: Build the runtime image
39+
FROM eclipse-temurin:21-jre-alpine AS runtime
40+
RUN apk add --no-cache bash curl
2041
WORKDIR /opt/devgateway/tcdi/admin
2142

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

25-
# Copy entrypoint script
46+
# Copy entrypoint script and set permissions in one layer
2647
COPY entrypoint.sh ./
27-
EXPOSE 8080
2848
RUN chmod +x entrypoint.sh
49+
50+
EXPOSE 8080
2951
ENTRYPOINT ["/opt/devgateway/tcdi/admin/entrypoint.sh"]
3052
CMD ["admin"]

docker-compose.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
services:
22
web:
3-
image: data-viz-admin:latest
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
args:
7+
GIT_BRANCH: main
8+
restart: unless-stopped
49
environment:
510
SPRING_DATASOURCE_JDBC_URL: "jdbc:postgresql://postgres:5432/tcdi_admin"
611
SPRING_JPA_HIBERNATE_DDL-AUTO: "update"
@@ -10,7 +15,8 @@ services:
1015
networks:
1116
- backend
1217
depends_on:
13-
- postgres
18+
postgres:
19+
condition: service_healthy
1420

1521

1622
postgres:
@@ -27,7 +33,6 @@ services:
2733
interval: 10s
2834
timeout: 30s
2935
retries: 3
30-
start_period: 50s
3136
networks:
3237
backend:
3338

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)