Lab 1 Report
Lab 1 Report
Successful Run
Link: Successful CI/CD job run
.gitlab-ci.yml Structure
Image:
Uses a JDK 25 Docker image for Maven builds.
Variables:
Defines Maven flags and a local .m2 cache for faster builds.
Cache:
Reuses dependencies between stages using maven-deps key.
Stages:
build → package → run
Jobs:
maven-build:
stage: build
script:
- ./mvnw clean package
artifacts:
paths:
- target/
cache:
key: maven-deps
paths:
- .m2/repository
maven-container-image-generation:
stage: package
script:
- echo "Building container image..."
run-game:
stage: run
script:
- java -jar target/game.jar
Problems & Solutions:
-
Problem:
WARNING: .m2/repository: no matching files. - Cause: Artifact path was not relative to the working directory.
-
Fix: In
maven-build, addedmkdir -p .m2/repositoryto create the missing directory.
Questions
1. What is ./mvnw and its advantage over mvn?
./mvnw is the Maven Wrapper, a script that ensures a specific Maven version is downloaded and used automatically.
Advantage: it guarantees build consistency across environments without requiring Maven to be preinstalled.
2. GitLab Cache vs Artifacts
| Feature | Purpose | Example | Lifetime |
|---|---|---|---|
| Cache | Reusable data between jobs (e.g., dependencies) | .m2/repository |
Reused across pipelines |
| Artifacts | Job outputs passed between stages | target/ |
Available until expiration |
Choice:
- Maven dependencies → Cache (speeds up builds, reused across stages)
- Build files (
target/) → Artifacts (passed to packaging stage, short-lived)
Trade-offs:
- Cache improves speed but risks stale data if dependencies change.
- Artifacts ensure correct, isolated results but increase storage use and job time.
3. 25-jre vs 25-jdk Images
| Image | Includes | Use Case | Pros | Cons |
|---|---|---|---|---|
JDK (25-jdk) |
Compilers & build tools | Building code | Versatile | Larger size |
JRE (25-jre) |
Runtime only | Running apps | Lightweight | Cannot build |
Reasoning:
- Using 25-jdk for both:
- Simpler setup (single image)
- Heavier runtime, slower startup, larger attack surface
- Using 25-jre for both:
- Build jobs would fail (no compiler or Maven tools)
- Slightly smaller image size, but not functional for building
Edited by Lander De Kesel