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.
- Set the PROJECT_ID:
export PROJECT_ID=$(gcloud config get-value core/project)
- Tag it:
docker tag 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 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
- Build the docker images in the examples directory for the projects helloworld-service, guestbook-service and helloworld-ui
- Get the project id from above:
echo ${PROJECT_ID}
- In the examples/kubernetes-1.6 directory run the following commands to deploy the examples to Google Container Engine.
- Modify the helloworldservice-deployment-v1.yaml to point to the docker image you pushed above. In the yaml file modify image to be
image: gcr.io/${PROJECT_ID}/helloworld
(replacing ${PROJECT_ID} with the actual project id). - Deploy the helloworld service:
kubectl apply -f helloworldservice-deployment-v1.yaml -f helloworldservice-service.yaml
- Get the external IP of helloworld-service:
kubectl get services
- Browse to http://EXTERNAL_IP:8080/hello/world
- Deploy redis:
kubectl apply -f redis-deployment.yaml -f redis-service.yaml
- Deploy mysql:
kubectl apply -f mysql-pvc.yaml -f mysql-deployment.yaml -f mysql-service.yaml
- Repeat the same thing to deploy the guestbook service by modifying and applying guestbookservice-deployment.yaml and guestbookservice-service.yaml files.
- The helloworld ui calls the guestbook service on startup, so wait until the guest book service has a status of Running by calling:
kubectl get pods
and looking for the pod guestbook-service-* - Repeat the same thing to deploy the helloworld ui by modifying and applying helloworldui-deployment-v1.yaml and helloworldui-service.yaml files.
- Get the external IP of helloworld ui by running
kubectl get services
and browse to the EXTERNAL IP - View the status of the services by getting the name of the pod:
kubectl get pods
and then browsing the logs of the pod:kubectl logs -f helloworld-ui-3415022828-1h37t