Update SparkJava samples
Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
This commit is contained in:
parent
fdc1e84d85
commit
3f8a58ef62
@ -21,14 +21,14 @@ services:
|
|||||||
backend:
|
backend:
|
||||||
build: backend
|
build: backend
|
||||||
ports:
|
ports:
|
||||||
- 80:8080
|
- 8080:8080
|
||||||
db:
|
db:
|
||||||
image: mysql:5.7
|
image: mysql:8.0.19
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
The compose file defines an application with two services `backend` and `db`.
|
The compose file defines an application with two services `backend` and `db`.
|
||||||
When deploying the application, docker-compose maps port 8080 of the backend service container to port 80 of the host as specified in the file.
|
When deploying the application, docker-compose maps port 8080 of the backend service container to port 80 of the host as specified in the file.
|
||||||
Make sure port 80 on the host is not already being in use.
|
Make sure port 8080 on the host is not already being in use.
|
||||||
|
|
||||||
## Deploy with docker-compose
|
## Deploy with docker-compose
|
||||||
|
|
||||||
@ -49,13 +49,13 @@ Listing containers must show two containers running and the port mapping as belo
|
|||||||
```
|
```
|
||||||
$ docker ps
|
$ docker ps
|
||||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||||
ee1e4f05d9f6 sparkjava-mysql_backend "/bin/sh -c 'java -j…" 44 seconds ago Up 43 seconds 0.0.0.0:80->8080/tcp sparkjava-mysql_backend_1
|
ee1e4f05d9f6 sparkjava-mysql_backend "/bin/sh -c 'java -j…" 44 seconds ago Up 43 seconds 0.0.0.0:8080->8080/tcp sparkjava-mysql_backend_1
|
||||||
716025ddf65b mysql:5.7 "docker-entrypoint.s…" 44 seconds ago Up 43 seconds 3306/tcp, 33060/tcp sparkjava-mysql_db_1
|
716025ddf65b mysql:8.0.19 "docker-entrypoint.s…" 44 seconds ago Up 43 seconds 3306/tcp, 33060/tcp sparkjava-mysql_db_1
|
||||||
```
|
```
|
||||||
|
|
||||||
After the application starts, run:
|
After the application starts, run:
|
||||||
```
|
```
|
||||||
$ curl localhost:80
|
$ curl localhost:8080
|
||||||
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
|
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
FROM maven:3.5-jdk-8-alpine AS build
|
FROM maven:3.6.3-jdk-11 AS build
|
||||||
COPY pom.xml .
|
WORKDIR /workdir/server
|
||||||
RUN mvn --batch-mode dependency:resolve
|
COPY pom.xml /workdir/server/pom.xml
|
||||||
COPY src/ src
|
RUN mvn dependency:go-offline
|
||||||
|
|
||||||
|
COPY src /workdir/server/src
|
||||||
|
|
||||||
RUN mvn --batch-mode clean compile assembly:single
|
RUN mvn --batch-mode clean compile assembly:single
|
||||||
|
|
||||||
FROM openjdk:8-jre-alpine3.7
|
FROM openjdk:11-jre-slim
|
||||||
|
ARG DEPENDENCY=/workdir/server/target
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
COPY --from=build target/app.jar /app.jar
|
COPY --from=build ${DEPENDENCY}/app.jar /app.jar
|
||||||
CMD java -jar /app.jar
|
CMD java -jar /app.jar
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sparkjava</groupId>
|
<groupId>com.sparkjava</groupId>
|
||||||
<artifactId>spark-core</artifactId>
|
<artifactId>spark-core</artifactId>
|
||||||
<version>2.5</version>
|
<version>2.8.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -3,14 +3,14 @@ services:
|
|||||||
backend:
|
backend:
|
||||||
build: backend
|
build: backend
|
||||||
ports:
|
ports:
|
||||||
- 80:8080
|
- 8080:8080
|
||||||
secrets:
|
secrets:
|
||||||
- db-password
|
- db-password
|
||||||
db:
|
db:
|
||||||
environment:
|
environment:
|
||||||
MYSQL_DATABASE: example
|
MYSQL_DATABASE: example
|
||||||
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db-password
|
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db-password
|
||||||
image: mysql:5.7
|
image: mysql:8.0.19
|
||||||
restart: always
|
restart: always
|
||||||
secrets:
|
secrets:
|
||||||
- db-password
|
- db-password
|
||||||
|
@ -18,11 +18,11 @@ services:
|
|||||||
sparkjava:
|
sparkjava:
|
||||||
build: sparkjava
|
build: sparkjava
|
||||||
ports:
|
ports:
|
||||||
- 80:8080
|
- 8080:8080
|
||||||
```
|
```
|
||||||
The compose file defines an application with one service `sparkjava`.
|
The compose file defines an application with one service `sparkjava`.
|
||||||
When deploying the application, docker-compose maps port 8080 of the sparkjava service container to port 80 of the host as specified in the file.
|
When deploying the application, docker-compose maps port 8080 of the sparkjava service container to port 8080 of the host as specified in the file.
|
||||||
Make sure port 80 on the host is not already being in use.
|
Make sure port 8080 on the host is not already being in use.
|
||||||
|
|
||||||
## Deploy with docker-compose
|
## Deploy with docker-compose
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ Make sure port 80 on the host is not already being in use.
|
|||||||
$ docker-compose up -d
|
$ docker-compose up -d
|
||||||
Creating network "sparkjava_default" with the default driver
|
Creating network "sparkjava_default" with the default driver
|
||||||
Building sparkjava
|
Building sparkjava
|
||||||
Step 1/9 : FROM maven:3.5-jdk-8-alpine AS build
|
Step 1/11 : FROM maven:3.6.3-jdk-11 AS build
|
||||||
3.5-jdk-8-alpine: Pulling from library/maven
|
3.6.3-jdk-11: Pulling from library/maven
|
||||||
...
|
...
|
||||||
Successfully tagged sparkjava_sparkjava:latest
|
Successfully tagged sparkjava_sparkjava:latest
|
||||||
WARNING: Image for service sparkjava was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
|
WARNING: Image for service sparkjava was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
|
||||||
@ -44,13 +44,13 @@ Listing containers must show two containers running and the port mapping as belo
|
|||||||
```
|
```
|
||||||
$ docker ps
|
$ docker ps
|
||||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||||
5af94cb25394 sparkjava_sparkjava "/bin/sh -c 'java -j…" 20 seconds ago Up 19 seconds 0.0.0.0:80->8080/tcp sparkjava_sparkjava_1
|
5af94cb25394 sparkjava_sparkjava "/bin/sh -c 'java -j…" 20 seconds ago Up 19 seconds 0.0.0.0:8080->8080/tcp sparkjava_sparkjava_1
|
||||||
```
|
```
|
||||||
|
|
||||||
After the application starts, navigate to `http://localhost:80` in your web browser or run:
|
After the application starts, navigate to `http://localhost:8080` in your web browser or run:
|
||||||
```
|
```
|
||||||
$ curl localhost:80
|
$ curl localhost:8080
|
||||||
Hello world
|
Hello from Docker!
|
||||||
```
|
```
|
||||||
|
|
||||||
Stop and remove the containers
|
Stop and remove the containers
|
||||||
|
@ -3,4 +3,4 @@ services:
|
|||||||
sparkjava:
|
sparkjava:
|
||||||
build: sparkjava
|
build: sparkjava
|
||||||
ports:
|
ports:
|
||||||
- 80:8080
|
- 8080:8080
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
FROM maven:3.5-jdk-8-alpine AS build
|
FROM maven:3.6.3-jdk-11 AS build
|
||||||
COPY pom.xml .
|
WORKDIR /workdir/server
|
||||||
RUN mvn --batch-mode dependency:resolve
|
COPY pom.xml /workdir/server/pom.xml
|
||||||
COPY src/ src
|
RUN mvn dependency:go-offline
|
||||||
|
|
||||||
|
COPY src /workdir/server/src
|
||||||
|
|
||||||
RUN mvn --batch-mode clean compile assembly:single
|
RUN mvn --batch-mode clean compile assembly:single
|
||||||
|
|
||||||
FROM openjdk:8-jre-alpine3.7
|
FROM openjdk:11-jre-slim
|
||||||
|
ARG DEPENDENCY=/workdir/server/target
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
COPY --from=build target/app.jar /app.jar
|
COPY --from=build ${DEPENDENCY}/app.jar /app.jar
|
||||||
CMD java -jar /app.jar
|
CMD java -jar /app.jar
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sparkjava</groupId>
|
<groupId>com.sparkjava</groupId>
|
||||||
<artifactId>spark-core</artifactId>
|
<artifactId>spark-core</artifactId>
|
||||||
<version>2.5</version>
|
<version>2.8.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -4,6 +4,6 @@ public class App {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
port(8080);
|
port(8080);
|
||||||
|
|
||||||
get("/", (req, res) -> "Hello world");
|
get("/", (req, res) -> "Hello from Docker!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user