This project contains Dockerfile that creates a base image to run Spring Boot applications.
This is not an official Google product.
Create a Dockerfile in your project directory:
FROM saturnism/spring-boot:1.2.3-jdk-8-groovy-2.4.3
ADD . $SRC_DIR
You can then build and run the image:
docker build -t myapp
docker run -ti myapp
You'll notice that everytime the container starts, it will resolve all the dependencies.
To avoid this, you can also pre-compile your Groovy application using the onbuild
image.
In the Dockerfile, use:
FROM saturnism/spring-boot:1.2.3jdk-8-groovy-2.4.3-onbuild
You can then build and run the image just like the previous method:
docker build -t myapp
docker run -ti myapp
You can find examples under the Examples directory.
Ray used this repository for many of his demos during his talks around the world in conferences. You can find a list of Ray's videos on how to run the demos in his YouTube playlist.
But specifically, checkout the one from Jfokus.
-
Create a new directory, and change into it:
mkdir hello-live && cd hello-live
-
Create
Helloworld.groovy
@RestController class Helloworld { @RequestMapping("/mul/{x}/{y}") def mul(@PathVariable int x, @PathVariable int y) { [ x: x, y: y, result: x * y ] } }
-
Run it:
spring run .
-
Build it:
spring jar ~/app.jar .
-
Run the jar:
java -jar ~/app.jar
- Create a
Dockerfile
- Build the container
docker build -t helloworld .
- Run it:
docker run -ti --rm -p 8080:8080 helloworld
This assumes that you have a Google Cloud Platform account, a Container Engine managed Kubernetes cluster, and the associated Project ID.
- Tag it:
docker tag -f helloworld gcr.io/${PROJECT_ID}/helloworld
- Push it to Google Container Registry, a private repository:
gcloud docker push gcr.io/${PROJECT_ID}/helloworld
- Deploy it in Kubernetes:
kubectl run helloworld --image=gcr.io/${RPOJECT_ID}/helloworld -l app=hellworld,visualize=true
(the label "visualize" is for demo visualization purposes. You can use whatever labels you like). - Scale it:
kubectl scale rc helloworld --replicas=3
- Expose it as an external service:
kubectl expose rc helloworld --port=8080 --target-port=8080 --type=LoadBalancer
- Make changes to
Helloworld.groovy
- Build the container as v2:
docker build -t helloworld:v2 .
- Tag it:
docker tag -f helloworld:v2 gcr.io/${PROJECT_ID}/helloworld:v2
- Push it:
gcloud docker push gcr.io/${PROJECT_ID}/helloworld:v2
- Rolling update:
kubectl rolling-update frontend --image=gcr.io/${PROJECT_ID}/helloworld:v2 --update-periods=5s