Skip to content

Commit 829bc75

Browse files
author
gabriele.sisinna
committed
Add Docker run and test setup
1 parent bede263 commit 829bc75

4 files changed

Lines changed: 73 additions & 0 deletions

File tree

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git
2+
.github
3+
.gradle
4+
build
5+
out
6+
.idea
7+
.vscode
8+
*.iml

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM eclipse-temurin:17-jdk-jammy AS builder
2+
3+
WORKDIR /workspace
4+
5+
COPY gradlew gradlew
6+
COPY gradlew.bat gradlew.bat
7+
COPY gradle gradle
8+
COPY build.gradle settings.gradle ./
9+
COPY src src
10+
11+
RUN chmod +x gradlew && ./gradlew --no-daemon bootJar
12+
13+
FROM eclipse-temurin:17-jre-jammy AS runtime
14+
15+
WORKDIR /app
16+
17+
COPY --from=builder /workspace/build/libs/*.jar app.jar
18+
19+
EXPOSE 8080
20+
21+
ENTRYPOINT ["java", "-jar", "/app/app.jar"]

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ Read these files in order:
6060

6161
The app starts on `http://localhost:8080`.
6262

63+
## Run with Docker
64+
65+
Build and start the app container:
66+
67+
```bash
68+
docker compose up --build app
69+
```
70+
71+
Then open:
72+
73+
- `http://localhost:8080/api/students`
74+
- `http://localhost:8080/swagger-ui.html`
75+
76+
To stop it:
77+
78+
```bash
79+
docker compose down
80+
```
81+
6382
## Try the API
6483

6584
Get the seeded students:
@@ -119,6 +138,12 @@ openapi.yaml
119138
./gradlew test
120139
```
121140

141+
Run the tests inside a container:
142+
143+
```bash
144+
docker compose run --rm test
145+
```
146+
122147
## GitHub CI
123148

124149
This repo includes a GitHub Actions workflow at `.github/workflows/ci.yml`.

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
image: java-spring-learning:local
7+
ports:
8+
- "8080:8080"
9+
10+
test:
11+
image: eclipse-temurin:17-jdk-jammy
12+
working_dir: /workspace
13+
command: ["./gradlew", "--no-daemon", "test"]
14+
volumes:
15+
- .:/workspace
16+
- gradle-cache:/root/.gradle
17+
18+
volumes:
19+
gradle-cache:

0 commit comments

Comments
 (0)