-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new step4 with docker-compose. This is only the first step, wh…
…ich is not complete yet. For now, all the paths and jars of the Spring Boot services are prepared.
- Loading branch information
1 parent
fa1cc1c
commit 36e40cd
Showing
14 changed files
with
244 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+306 KB
spring-cloud-example-running-docker-windows-containers-docker-compose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
step4-multiple-spring-boot-apps-docker-compose/ansible-windows-docker-springboot.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
- hosts: "{{host}}" | ||
vars: | ||
base_path: "C:\\spring-boot" | ||
service_registry_name: eureka-serviceregistry | ||
services: | ||
- name: eureka-serviceregistry | ||
path_to_jar: "../../spring-cloud-netflix-docker/eureka-serviceregistry/target/eureka-serviceregistry-0.0.1-SNAPSHOT.jar" | ||
port: 8761 | ||
- name: zuul-edgeservice | ||
path_to_jar: "../../spring-cloud-netflix-docker/zuul-edgeservice/target/zuul-edgeservice-0.0.1-SNAPSHOT.jar" | ||
port: 8080 | ||
- name: weatherbackend | ||
path_to_jar: "../../spring-cloud-netflix-docker/weatherbackend/target/weatherbackend-0.0.1-SNAPSHOT.jar" | ||
port: 8090 | ||
- name: weatherbackend-second | ||
path_to_jar: "../../spring-cloud-netflix-docker/weatherbackend/target/weatherbackend-0.0.1-SNAPSHOT.jar" | ||
port: 8090 | ||
|
||
tasks: | ||
- name: Create base directory C:\spring-boot, if not there | ||
win_file: path={{base_path}} state=directory | ||
|
||
- name: Preparing the Spring Boot App´s Files for later docker-compose run | ||
include: spring-boot-app-prepare.yml | ||
with_items: "{{ vars.services }}" | ||
|
||
- name: Template docker-compose.yml to directory C:\spring-boot | ||
win_template: | ||
src: "templates/docker-compose.j2" | ||
dest: "{{base_path}}\\docker-compose.yml" | ||
|
||
# Run docker-compose | ||
|
||
# Do Healthchecks |
7 changes: 7 additions & 0 deletions
7
step4-multiple-spring-boot-apps-docker-compose/group_vars/all.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# http://docs.ansible.com/ansible/intro_windows.html#windows-how-does-it-work | ||
|
||
ansible_port: 55986 # not 5986, as we would use for non-virtualized environments | ||
ansible_connection: winrm | ||
|
||
# The following is necessary for Python 2.7.9+ when using default WinRM self-signed certificates: | ||
ansible_winrm_server_cert_validation: ignore |
4 changes: 4 additions & 0 deletions
4
...iple-spring-boot-apps-docker-compose/group_vars/ansible-windows-docker-springboot-dev.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# http://docs.ansible.com/ansible/intro_windows.html#windows-how-does-it-work | ||
|
||
ansible_user: vagrant | ||
ansible_password: vagrant |
4 changes: 4 additions & 0 deletions
4
...tiple-spring-boot-apps-docker-compose/group_vars/ansible-windows-docker-springboot-qa.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# http://docs.ansible.com/ansible/intro_windows.html#windows-how-does-it-work | ||
|
||
ansible_user: vagrant | ||
ansible_password: vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ansible-windows-docker-springboot-dev] | ||
127.0.0.1 | ||
|
||
[ansible-windows-docker-springboot-qa] | ||
127.0.0.1 |
39 changes: 39 additions & 0 deletions
39
step4-multiple-spring-boot-apps-docker-compose/spring-boot-app-health-check.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
- name: Obtain the Docker Container´s internal IP address (because localhost doesn´t work for now https://github.com/docker/for-win/issues/458) | ||
win_shell: "docker inspect -f {% raw %}'{{ .NetworkSettings.Networks.nat.IPAddress }}' {% endraw %} {{spring_boot_app.name}} {{ '>' }} container_ip.txt" | ||
|
||
- name: Get the Docker Container´s internal IP address from the temporary txt-file (we have to do this because of templating problems, see http://stackoverflow.com/a/32279729/4964553) | ||
win_shell: cat container_ip.txt | ||
register: win_shell_txt_return | ||
|
||
- name: Define the IP as variable | ||
set_fact: | ||
docker_container_ip: "{{ win_shell_txt_return.stdout.splitlines()[0] }}" | ||
|
||
- debug: | ||
msg: "Your Docker Container has the internal IP {{ docker_container_ip }} --> Let´s do a health-check against this URI: 'http://{{ docker_container_ip }}:{{spring_boot_app.port}}/health'" | ||
|
||
###### Smoke test, if app has booted up correctly | ||
- name: Wait until our Spring Boot app is up & running | ||
win_uri: | ||
url: "http://{{ docker_container_ip }}:{{spring_boot_app.port}}/health" | ||
method: GET | ||
register: health_result | ||
until: health_result.status_code == 200 | ||
retries: 10 | ||
delay: 5 | ||
ignore_errors: yes | ||
|
||
- name: Show some more info, only when health check went wrong | ||
win_uri: | ||
url: "http://{{ docker_container_ip }}:{{spring_boot_app.port}}/health" | ||
method: GET | ||
register: health_bad_result | ||
ignore_errors: yes | ||
when: health_result|failed | ||
|
||
- name: Show some more info, only when health check went wrong | ||
debug: | ||
msg: "The app reacted with: {{health_bad_result}}" | ||
when: health_result|failed | ||
|
24 changes: 24 additions & 0 deletions
24
step4-multiple-spring-boot-apps-docker-compose/spring-boot-app-prepare.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
- name: Defining needed variables | ||
set_fact: | ||
spring_boot_app: | ||
name: "{{ item.name }}" | ||
port: "{{ item.port }}" | ||
jar: "{{ item.path_to_jar }}" | ||
|
||
- name: Preparing the following Spring Boot App´s Files for docker-compose run | ||
debug: | ||
msg: "Processing '{{spring_boot_app.name}}' with port '{{ spring_boot_app.port }}'" | ||
|
||
- name: Create directory C:\spring-boot\spring_boot_app.name, if not there | ||
win_file: path={{base_path}}\\{{spring_boot_app.name}} state=directory | ||
|
||
- name: Template and copy Spring Boot app´s Dockerfile to directory C:\spring-boot\spring_boot_app.name | ||
win_template: | ||
src: "templates/Dockerfile-SpringBoot-App.j2" | ||
dest: "{{base_path}}\\{{spring_boot_app.name}}\\Dockerfile" | ||
|
||
- name: Copy Spring Boot app´s jar-File to directory C:\spring-boot\spring_boot_app.name | ||
win_copy: | ||
src: "{{spring_boot_app.jar}}" | ||
dest: "{{base_path}}\\{{spring_boot_app.name}}\\{{spring_boot_app.name}}.jar" |
44 changes: 44 additions & 0 deletions
44
step4-multiple-spring-boot-apps-docker-compose/spring-boot-app-windows-docker.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
- name: Preparing to run Spring Boot App in Docker Windows Container | ||
debug: | ||
msg: "Processing '{{spring_boot_app.name}}'" | ||
|
||
- name: Define some needed variables | ||
set_fact: | ||
spring_boot_app_path: "{{base_path}}\\{{spring_boot_app.name}}" | ||
|
||
- name: Create directory C:\spring-boot\spring_boot_app.name, if not there | ||
win_file: path={{spring_boot_app_path}} state=directory | ||
|
||
- name: Template and copy Spring Boot app´s Dockerfile to directory C:\spring-boot\spring_boot_app.name | ||
win_template: | ||
src: "templates/Dockerfile-SpringBoot-App.j2" | ||
dest: "{{spring_boot_app_path}}\\Dockerfile" | ||
|
||
- name: Copy Spring Boot app´s jar-File to directory C:\spring-boot\spring_boot_app.name | ||
win_copy: | ||
src: "{{jar_input_path}}" | ||
dest: "{{spring_boot_app_path}}\\{{spring_boot_app.name}}.jar" | ||
|
||
- name: Stop the Service Docker container | ||
win_shell: docker stop {{spring_boot_app.name}} | ||
ignore_errors: yes | ||
|
||
- name: Remove the Service Docker container | ||
win_shell: docker rm {{spring_boot_app.name}} --force | ||
ignore_errors: yes | ||
|
||
- name: Remove the Service Docker image | ||
win_shell: docker rmi {{spring_boot_app.name}}:latest --force | ||
ignore_errors: yes | ||
|
||
- name: Build the Service Docker image | ||
win_shell: docker build . --tag {{spring_boot_app.name}}:latest | ||
args: | ||
chdir: "{{spring_boot_app_path}}" | ||
|
||
- name: Run the Service Docker container | ||
win_shell: "docker run -d --publish {{spring_boot_app.port}}:{{spring_boot_app.port}} --name={{spring_boot_app.name}} --restart=unless-stopped {{spring_boot_app.name}}:latest" | ||
|
||
- name: Healthchecking the Spring Boot app | ||
include: spring-boot-app-health-check.yml |
17 changes: 17 additions & 0 deletions
17
step4-multiple-spring-boot-apps-docker-compose/templates/Dockerfile-SpringBoot-App.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#jinja2: newline_sequence:'\r\n' | ||
FROM springboot-oraclejre-nanoserver:latest | ||
|
||
MAINTAINER Jonas Hecht | ||
|
||
ENV REGISTRY_HOST {{service_registry_name}} | ||
ENV SPRINGBOOT_APP_NAME {{spring_boot_app.name}} | ||
|
||
# Expose the apps Port | ||
EXPOSE {{spring_boot_app.port}} | ||
|
||
# Add Spring Boot app.jar to Container | ||
ADD {{spring_boot_app.name}}.jar app.jar | ||
|
||
# Fire up our Spring Boot app by default | ||
CMD ["java.exe", "-jar app.jar --server.port={{spring_boot_app.port}}"] | ||
|
35 changes: 35 additions & 0 deletions
35
step4-multiple-spring-boot-apps-docker-compose/templates/docker-compose.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#jinja2: newline_sequence:'\r\n' | ||
version: '3.1' | ||
|
||
services: | ||
|
||
eureka-serviceregistry: | ||
build: ./eureka-serviceregistry | ||
ports: | ||
- "8761:8761" | ||
tty: | ||
true | ||
|
||
# no portbinding here - the actual services should be accessible through Zuul proxy | ||
weatherbackend: | ||
build: ./weatherbackend | ||
tty: | ||
true | ||
|
||
# no portbinding here - the actual services should be accessible through Zuul proxy | ||
weatherbackend-second: | ||
build: ./weatherbackend-second | ||
tty: | ||
true | ||
|
||
zuul-edgeservice: | ||
build: ./zuul-edgeservice | ||
ports: | ||
- "8080:8080" | ||
tty: | ||
true | ||
|
||
networks: | ||
default: | ||
external: | ||
name: "nat" |