Skip to content

Commit f4bca7c

Browse files
committed
Merge branch 'master' of github.com:saturnism/spring-boot-docker
2 parents 8c24f60 + 376d262 commit f4bca7c

File tree

2 files changed

+39
-94
lines changed

2 files changed

+39
-94
lines changed

README.md

Lines changed: 4 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,8 @@
1-
This project contains Dockerfile that creates a base image to run Spring Boot applications.
2-
3-
This is not an official Google product.
4-
5-
How to use this image
6-
=====================
7-
8-
Groovy Applications
9-
-------------------
10-
Create a Dockerfile in your project directory:
11-
12-
FROM saturnism/spring-boot:1.2.3-jdk-8-groovy-2.4.3
13-
ADD . $SRC_DIR
14-
15-
You can then build and run the image:
16-
17-
docker build -t myapp
18-
docker run -ti myapp
19-
20-
You'll notice that everytime the container starts, it will resolve all the dependencies.
21-
To avoid this, you can also pre-compile your Groovy application using the `onbuild` image.
22-
23-
In the Dockerfile, use:
24-
25-
FROM saturnism/spring-boot:1.2.3jdk-8-groovy-2.4.3-onbuild
26-
27-
You can then build and run the image just like the previous method:
28-
29-
docker build -t myapp
30-
docker run -ti myapp
31-
32-
33-
Examples
34-
--------
35-
You can find examples under the [Examples](examples/) directory.
36-
37-
Full Demo with Kubernetes
38-
-------------------------
39-
### Videos
1+
Spring Boot with Kubernetes
2+
---------------------------
403
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](https://www.youtube.com/playlist?list=PL4uYfigiauVYH4OwOyq8FGbPQOn-JueEf).
414

425
But specifically, checkout the one from [Jfokus](https://www.youtube.com/watch?v=R2l-tL_1els&index=6&list=PL4uYfigiauVYH4OwOyq8FGbPQOn-JueEf).
436

44-
### Creating a microservice
45-
1. Create a new directory, and change into it: `mkdir hello-live && cd hello-live`
46-
1. Create `Helloworld.groovy`
47-
```
48-
@RestController
49-
class Helloworld {
50-
@RequestMapping("/mul/{x}/{y}")
51-
def mul(@PathVariable int x, @PathVariable int y) {
52-
[ x: x, y: y, result: x * y ]
53-
}
54-
}
55-
```
56-
57-
1. Run it: `spring run .`
58-
1. Build it: `spring jar ~/app.jar .`
59-
1. Run the jar: `java -jar ~/app.jar`
60-
61-
### Containerize the service
62-
1. Create a `Dockerfile`
63-
1. Build the container `docker build -t helloworld .`
64-
1. Run it: `docker run -ti --rm -p 8080:8080 helloworld`
65-
66-
### Deploying to Kubernetes on Google Container Engine
67-
This assumes that you have a Google Cloud Platform account, a Container Engine managed Kubernetes cluster, and the associated Project ID.
68-
69-
1. Set the PROJECT_ID: `export PROJECT_ID=$(gcloud config get-value core/project)`
70-
1. Tag it: `docker tag helloworld gcr.io/${PROJECT_ID}/helloworld`
71-
1. Push it to Google Container Registry, a private repository: `gcloud docker -- push gcr.io/${PROJECT_ID}/helloworld`
72-
1. 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).
73-
1. Scale it: `kubectl scale rc helloworld --replicas=3`
74-
1. Expose it as an external service: `kubectl expose rc helloworld --port=8080 --target-port=8080 --type=LoadBalancer`
75-
76-
### Rolling Update
77-
1. Make changes to `Helloworld.groovy`
78-
1. Build the container as v2: `docker build -t helloworld:v2 .`
79-
1. Tag it: `docker tag helloworld:v2 gcr.io/${PROJECT_ID}/helloworld:v2`
80-
1. Push it: `gcloud docker -- push gcr.io/${PROJECT_ID}/helloworld:v2`
81-
1. Rolling update: `kubectl rolling-update frontend --image=gcr.io/${PROJECT_ID}/helloworld:v2 --update-periods=5s`
82-
83-
### Running the examples in the Google Container Engine
84-
85-
1. Build the docker images in the examples directory for the projects helloworld-service, guestbook-service and helloworld-ui
86-
1. Get the project id from above: `echo ${PROJECT_ID}`
87-
1. In the examples/kubernetes-1.6 directory run the following commands to deploy the examples to Google Container Engine.
88-
1. 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).
89-
1. Deploy the helloworld service: `kubectl apply -f helloworldservice-deployment-v1.yaml -f helloworldservice-service.yaml`
90-
1. Get the external IP of helloworld-service: `kubectl get services`
91-
1. Browse to http://EXTERNAL_IP:8080/hello/world
92-
1. Deploy redis: `kubectl apply -f redis-deployment.yaml -f redis-service.yaml`
93-
1. Deploy mysql: `kubectl apply -f mysql-pvc.yaml -f mysql-deployment.yaml -f mysql-service.yaml`
94-
1. Repeat the same thing to deploy the guestbook service by modifying and applying guestbookservice-deployment.yaml and guestbookservice-service.yaml files.
95-
1. 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-*
96-
1. Repeat the same thing to deploy the helloworld ui by modifying and applying helloworldui-deployment-v1.yaml and helloworldui-service.yaml files.
97-
1. Get the external IP of helloworld ui by running `kubectl get services` and browse to the EXTERNAL IP
98-
1. 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 `
7+
To set everything up, see [Kubernetes Code Lab](http://bit.ly/k8s-lab)
8+
To learn about running this in Istio, see [Istio Code Lab](http://bit.ly/istio-lab)

groovy-onbuild/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
This project contains Dockerfile that creates a base image to run Spring Boot applications.
2+
3+
This is not an official Google product.
4+
5+
How to use this image
6+
=====================
7+
8+
Groovy Applications
9+
-------------------
10+
Create a Dockerfile in your project directory:
11+
12+
FROM saturnism/spring-boot:1.2.3-jdk-8-groovy-2.4.3
13+
ADD . $SRC_DIR
14+
15+
You can then build and run the image:
16+
17+
docker build -t myapp
18+
docker run -ti myapp
19+
20+
You'll notice that everytime the container starts, it will resolve all the dependencies.
21+
To avoid this, you can also pre-compile your Groovy application using the `onbuild` image.
22+
23+
In the Dockerfile, use:
24+
25+
FROM saturnism/spring-boot:1.2.3jdk-8-groovy-2.4.3-onbuild
26+
27+
You can then build and run the image just like the previous method:
28+
29+
docker build -t myapp
30+
docker run -ti myapp
31+
32+
33+
Examples
34+
--------
35+
You can find examples under the [Examples](examples/) directory.

0 commit comments

Comments
 (0)