awesome-compose/sparkjava
Chad Metcalf 702ec96821
Adding a Makefile and basic tests.
This approach uses bats to create a generic docker-compose test. It
checks that images are pullable, projects are buildable, up works, and
if ports are exposed that something is listening.

The tests can be tailored for each example. As long as they are the same
though, you can edit lib/test.bats.example and then `make update-tests`
and all the tests will be synced.

Signed-off-by: Chad Metcalf <chad@docker.com>
2020-08-08 14:26:52 -07:00
..
sparkjava Update SparkJava samples 2020-03-17 15:31:13 +01:00
docker-compose.yaml Fix default port mapping and indentation 2020-03-24 00:44:49 +01:00
README.md Update SparkJava samples 2020-03-17 15:31:13 +01:00
test.bats Adding a Makefile and basic tests. 2020-08-08 14:26:52 -07:00

Compose sample application

Spark Java

Project structure:

.
├── docker-compose.yaml
├── README.md
└── sparkjava
    ├── Dockerfile
    └── ...

docker-compose.yaml

version: "3.7"
services:
  sparkjava:
    build: sparkjava
    ports:
    - 8080:8080

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 8080 of the host as specified in the file. Make sure port 8080 on the host is not already being in use.

Deploy with docker-compose

$ docker-compose up -d
Creating network "sparkjava_default" with the default driver
Building sparkjava
Step 1/11 : FROM maven:3.6.3-jdk-11 AS build
3.6.3-jdk-11: Pulling from library/maven
...
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`.
Creating sparkjava_sparkjava_1 ... done

Expected result

Listing containers must show two containers running and the port mapping as below:

$ docker ps
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:8080->8080/tcp   sparkjava_sparkjava_1

After the application starts, navigate to http://localhost:8080 in your web browser or run:

$ curl localhost:8080
Hello from Docker!

Stop and remove the containers

$ docker-compose down
Stopping sparkjava_sparkjava_1 ... done
Removing sparkjava_sparkjava_1 ... done
Removing network sparkjava_default