Skip to content

Commit f9cf4c2

Browse files
author
Ricardo Campos
committed
feat: add docker file for aws ec2 and native profile
1 parent d47aead commit f9cf4c2

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
### Builder
2+
FROM ghcr.io/graalvm/native-image:ol8-java17-22 AS build
3+
4+
# Copy
5+
WORKDIR /app
6+
COPY pom.xml mvnw ./
7+
COPY src ./src
8+
COPY .mvn/ ./.mvn
9+
10+
# Build
11+
RUN ./mvnw package -Pnative -DskipTests -Dspring-boot.run.profiles=prod
12+
13+
### Deployer
14+
FROM amazonlinux:2023.3.20240131.0 AS deploy
15+
16+
# Copy
17+
WORKDIR /app
18+
COPY --from=build /app/target/aws-java-rest-api ./aws-java-rest-api
19+
20+
# User, port and health check
21+
USER 1001
22+
EXPOSE 8080
23+
HEALTHCHECK CMD timeout 10s bash -c 'true > /dev/tcp/127.0.0.1/8080'
24+
25+
# Startup
26+
ENTRYPOINT ["/app/aws-java-rest-api"]

Dockerfile.old

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
### Builder
2+
FROM ghcr.io/graalvm/native-image:ol8-java17-22 AS build
3+
4+
# Copy
5+
WORKDIR /app
6+
COPY pom.xml mvnw ./
7+
COPY src ./src
8+
COPY .mvn/ ./.mvn
9+
10+
# Build
11+
RUN ./mvnw package -Pnative -DskipTests -Dspring-boot.run.profiles=prod
12+
13+
### Deployer
14+
FROM debian:bookworm-slim AS deploy
15+
16+
# Copy
17+
WORKDIR /app
18+
COPY --from=build /app/target/aws-java-rest-api ./aws-java-rest-api
19+
20+
# User, port and health check
21+
USER 1001
22+
EXPOSE 8080
23+
HEALTHCHECK CMD timeout 10s bash -c 'true > /dev/tcp/127.0.0.1/8080'
24+
25+
# Startup
26+
ENTRYPOINT ["/app/aws-java-rest-api"]

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ Tasks:
2020
- Spring Boot DevTools
2121
- Spring Boot Actuator
2222
- Lombok
23+
24+
## Docker
25+
26+
Building:
27+
28+
```sh
29+
docker build -t aws-java-rest-api .
30+
```
31+
32+
Running:
33+
34+
```sh
35+
docker run -it --rm \
36+
-p 8080:8080 \
37+
--name aws-java-rest-api \
38+
aws-java-rest-api
39+
```

pom.xml

+23
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
</dependencies>
4646

4747
<build>
48+
<finalName>aws-java-rest-api</finalName>
4849
<plugins>
4950
<plugin>
5051
<groupId>org.springframework.boot</groupId>
@@ -61,4 +62,26 @@
6162
</plugins>
6263
</build>
6364

65+
<profiles>
66+
<profile>
67+
<id>native</id>
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>org.graalvm.buildtools</groupId>
72+
<artifactId>native-maven-plugin</artifactId>
73+
<executions>
74+
<execution>
75+
<id>build-native</id>
76+
<goals>
77+
<goal>compile-no-fork</goal>
78+
</goals>
79+
<phase>package</phase>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
</profile>
86+
</profiles>
6487
</project>

0 commit comments

Comments
 (0)