项目作者: andreoss

项目描述 :
高级语言: Java
项目地址: git://github.com/andreoss/mancala.git
创建时间: 2020-10-11T21:33:44Z
项目社区:https://github.com/andreoss/mancala

开源协议:GNU General Public License v3.0

下载


Mancala

Hits-of-Code
codecov
Build Status
Quality Gate Status

Simple implementation of Mancala.

Build and run

With JDK11+

  1. mvn package
  2. java -jar target/mancala.jar

Exercise the application

Swagger is available at http://localhost:8080/openapi-ui/index.html

Create a game

  1. * curl -v -X POST -H "Content-Type: application/json" http://0.0.0.0:8080/games
  2. > POST /games HTTP/1.1
  3. > Host: 0.0.0.0:8080
  4. > User-Agent: curl/7.70.0
  5. > Accept: */*
  6. > Content-Type: application/json
  7. >
  8. < HTTP/1.1 201 Created
  9. < Content-Length: 0
  10. < Date: Mon, 12 Oct 2020 01:25:41 +0300
  11. < Location: http://127.0.0.1:8080/2
  12. < connection: keep-alive
  13. <
  14. * Connection #0 to host 0.0.0.0 left intact

See status of a game

  1. * curl -v -X GET -H "Content-Type: application/json" http://0.0.0.0:8080/games/1
  2. * Connected to 0.0.0.0 (127.0.0.1) port 8080 (#0)
  3. > GET /games/1 HTTP/1.1
  4. > Host: 0.0.0.0:8080
  5. > User-Agent: curl/7.70.0
  6. > Accept: */*
  7. > Content-Type: application/json
  8. >
  9. < HTTP/1.1 200 OK
  10. < Content-Type: application/json
  11. < Date: Mon, 12 Oct 2020 01:23:32 +0300
  12. < connection: keep-alive
  13. < content-length: 108
  14. <
  15. * Connection #0 to host 0.0.0.0 left intact
  16. {"id":1,"status":{"1":6,"2":6,"3":6,"4":6,"5":6,"6":6,"7":0,"8":6,"9":6,"10":6,"11":6,"12":6,"13":6,"14":0}}

Make a move

  1. * curl -v -X PUT -H "Content-Type: application/json" http://0.0.0.0:8080/games/2/pits/1
  2. * Trying 0.0.0.0:8080...
  3. * Connected to 0.0.0.0 (127.0.0.1) port 8080 (#0)
  4. > PUT /games/2/pits/1 HTTP/1.1
  5. > Host: 0.0.0.0:8080
  6. > User-Agent: curl/7.70.0
  7. > Accept: */*
  8. > Content-Type: application/json
  9. >
  10. < HTTP/1.1 202 Accepted
  11. < Content-Length: 0
  12. < Date: Mon, 12 Oct 2020 01:27:06 +0300
  13. < Location: http://127.0.0.1:8080/2
  14. < connection: keep-alive
  15. <

Try health and metrics

  1. curl -s -X GET http://localhost:8080/health
  2. {"outcome":"UP",...
  3. . . .
  4. # Prometheus Format
  5. curl -s -X GET http://localhost:8080/metrics
  6. # TYPE base:gc_g1_young_generation_count gauge
  7. . . .
  8. # JSON Format
  9. curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
  10. {"base":...
  11. . . .

Build the Docker Image

  1. docker build -t mancala .

Start the application with Docker

  1. docker run --rm -p 8080:8080 mancala:latest

Exercise the application as described above

Deploy the application to Kubernetes

  1. kubectl cluster-info # Verify which cluster
  2. kubectl get pods # Verify connectivity to cluster
  3. kubectl create -f app.yaml # Deploy application
  4. kubectl get pods # Wait for quickstart pod to be RUNNING
  5. kubectl get service helidon-quickstart-mp # Verify deployed service

Note the PORTs. You can now exercise the application as you did before but use the second
port number (the NodePort) instead of 8080.

After you’re done, cleanup.

  1. kubectl delete -f app.yaml

Build a native image with GraalVM

GraalVM allows you to compile your programs ahead-of-time into a native
executable. See https://www.graalvm.org/docs/reference-manual/aot-compilation/
for more information.

You can build a native executable in 2 different ways:

  • With a local installation of GraalVM
  • Using Docker

Local build

Download Graal VM at https://www.graalvm.org/downloads, the version
currently supported for Helidon is 20.1.0.

  1. # Setup the environment
  2. export GRAALVM_HOME=/path
  3. # build the native executable
  4. mvn package -Pnative-image

You can also put the Graal VM bin directory in your PATH, or pass
-DgraalVMHome=/path to the Maven command.

See https://github.com/oracle/helidon-build-tools/tree/master/helidon-maven-plugin#goal-native-image
for more information.

Start the application:

  1. ./target/mancala

Multi-stage Docker build

Build the “native” Docker Image

  1. docker build -t mancala-native -f Dockerfile.native .

Start the application:

  1. docker run --rm -p 8080:8080 mancala-native:latest

You can build a custom Java Runtime Image (JRI) containing the application jars and the JDK modules
on which they depend. This image also:

  • Enables Class Data Sharing by default to reduce startup time.
  • Contains a customized start script to simplify CDS usage and support debug and test modes.

You can build a custom JRI in two different ways:

  • Local
  • Using Docker

Local build

  1. # build the JRI
  2. mvn package -Pjlink-image

See https://github.com/oracle/helidon-build-tools/tree/master/helidon-maven-plugin#goal-jlink-image
for more information.

Start the application:

  1. ./target/mancala/bin/start

Multi-stage Docker build

Build the “jlink” Docker Image

  1. docker build -t mancala-jlink -f Dockerfile.jlink .

Start the application:

  1. docker run --rm -p 8080:8080 mancala-jlink:latest

See the start script help:

  1. docker run --rm mancala-jlink:latest --help