-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdocker-compose.yaml
191 lines (183 loc) · 9.31 KB
/
docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Creates and run the Docker containers for the
#
# a) the books web tier SPA
# - github repository - https://github.com/aidanwhiteley/books-react
# b) the books Spring Cloud API gateway
# - github repository - https://github.com/aidanwhiteley/books-gateway
# b) the books Eureka service registry
# - github repository - https://github.com/aidanwhiteley/books-eureka
# d) books api microservice i.e. this project
# - github registry - https://github.com/aidanwhiteley/books
# e) the books Mongo datastore
# - also in this github project - see the src/main/resources/mongo-docker directory
#
#
# Run with commands like the following:
# docker-compose up
# or
# docker-compose up --force-recreate
# or
# docker-compose up --scale api-tier-java=2
#
# This docker-compose file expects to see a .env file in the same directory.
# This version retrieved from Git should be edited for your usage but will basically work without any edits
# if you just want to try stuff out (insecurely!).
services:
# This container is built using the commands detailed in the Dockerfile
# at https://github.com/aidanwhiteley/books-react
# Change the image name to aidanwhiteley/books-web-react (i.e. no "-gateway") to
# use an image where nginx points directly to a single instance of the
# Spring Boot java microservice (expected to be on 8080) rather than to an API gateway container which
# can forward the request to multiple container based instances of the microservice.
# Change the "depends_on" as appropriate.
web-tier-react:
container_name: books-web-react-container
image: aidanwhiteley/books-web-react-gateway:v0.1.1
restart: unless-stopped
ports:
- 80:80
# The health check is an API call that should traverse the web tier, API gateway tier (using the service registry tier)
# to the Java API tier which then makes a call to the Mongo data tier.
# "docker ps" should show the health status
healthcheck:
test: "${WEB_HEALTHCHECK_TEST:-curl --fail localhost/api/books || exit 1}"
interval: "30s"
timeout: "5s"
start_period: "30s"
retries: 3
depends_on:
api-gateway-tier:
condition: service_started
api-tier-java:
condition: service_healthy
# This container is built using Google Jib using the following maven command
# for the project at https://github.com/aidanwhiteley/books-gateway
# mvn compile jib:dockerBuild (see comments in pom.xml).
# The Spring Cloud based API gateway registers with the Eureka based
# service registry and then the active instances of the books microservice
# that have registered with the service registry.
# Comment out this stanza if using the aidanwhiteley/books-web-angular image
# which points to a single books microservice expected to be on port 8080.
api-gateway-tier:
container_name: books-gateway-container
image: aidanwhiteley/books-gateway:0.0.7-RELEASE
restart: unless-stopped
environment:
- "SPRING_PROFILES_ACTIVE=default"
- "SERVICE_REGISTRY=${SERVICE_REGISTRY}"
# Note - healthchecks not easily supportable on JIB based images as the distroless base image has no shell support
depends_on:
service-registry-tier:
condition: service_started
# This container is built using Google Jib using the following maven command
# for the project at https://github.com/aidanwhiteley/books-eureka
# mvn compile jib:dockerBuild (see comments in pom.xml).
# Provides the service registry used by the API Gateway to find instances
# of the books microservice.
# The checked in code leaves the (read only) Eureka web console available
# on https://<docker ip>:8761
# Comment out this stanza if using the aidanwhiteley/books-web-angular image
# which points to a single books microservice expected to be onm port 8080.
service-registry-tier:
container_name: books-service-registry-container
image: aidanwhiteley/books-service-registry:0.0.7-RELEASE
restart: unless-stopped
# Uncomment for debugging by viewing Eureka web console
ports:
- 8761:8761
environment:
- "SPRING_PROFILES_ACTIVE=default"
- "SERVICE_REGISTRY=${SERVICE_REGISTRY}"
# This container is built using Google Jib using the maven command for this project of
# mvn compile jib:dockerBuild (see comments in pom.xml).
# The service name "api-tier-java" is known to the nginx config used by the web-tier-react
# nginx based image.
# Alternatively this tier is accessed by instances of the microservice in this container registering
# with a Eureka service registry and a Spring Cloud API gateway forwarding calls to registered
# microservice instances.
api-tier-java:
# The container_name must be commented out if starting multiple containers for this tier e.g.
# "docker compose up --scale api-tier-java=2"
# container_name: books-api-java-container
image: aidanwhiteley/books-api-java:0.50.3-RELEASE
restart: unless-stopped
environment:
- "SPRING_PROFILES_ACTIVE=${JAVA_BOOKS_SPRING_PROFILE}"
- "MONGO_INITDB_APP_USERNAME=${MONGO_INITDB_APP_USERNAME}"
- "MONGO_INITDB_APP_PASSWORD=${MONGO_INITDB_APP_PASSWORD}"
- "MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE}"
- "MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}"
- "MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}"
- "JAVA_BOOKS_JWT_SECRET_KEY=${JAVA_BOOKS_JWT_SECRET_KEY}"
- "JAVA_BOOKS_RELOAD_DEVELOPMENT_DATA=${JAVA_BOOKS_RELOAD_DEVELOPMENT_DATA}"
- "JAVA_BOOKS_AUTO_AUTH_USER=${JAVA_BOOKS_AUTO_AUTH_USER}"
- "JAVA_BOOKS_ALLOW_ACTUATOR_USER_CREATION=${JAVA_BOOKS_ALLOW_ACTUATOR_USER_CREATION}"
- "SPRING_SERVER_PORT=${SPRING_SERVER_PORT}"
- "SPRING_SECURITY_OUATH2_CLIENT_REGISTRATION_GOOGLE_CLIENT_ID=${SPRING_SECURITY_OUATH2_CLIENT_REGISTRATION_GOOGLE_CLIENT_ID}"
- "SPRING_SECURITY_OUATH2_CLIENT_REGISTRATION_GOOGLE_CLIENT_SECRET=${SPRING_SECURITY_OUATH2_CLIENT_REGISTRATION_GOOGLE_CLIENT_SECRET}"
- "SPRING_SECURITY_OUATH2_CLIENT_REGISTRATION_FACEBOOK_CLIENT_ID=${SPRING_SECURITY_OUATH2_CLIENT_REGISTRATION_FACEBOOK_CLIENT_ID}"
- "SPRING_SECURITY_OUATH2_CLIENT_REGISTRATION_FACEBOOK_CLIENT_SECRET=${SPRING_SECURITY_OUATH2_CLIENT_REGISTRATION_FACEBOOK_CLIENT_SECRET}"
- "SERVICE_REGISTRY=${SERVICE_REGISTRY}"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
depends_on:
data-tier-mongo:
condition: service_healthy
service-registry-tier:
condition: service_started
# This container is built dynamically when the docker-compose up command is issued.
# The service name is known to the spring-boot application-xxxxx.properties file
# used by the active Spring profile specified when starting the api-tier-java service.
#
# To see how the MongoDB is initialised with user creation and (optional) sample data
# loads, see the src/main/resources/mongo-docker directory in this project.
data-tier-mongo:
container_name: books-data-mongodb-container
# To load sample data and users, the image name aidanwhiteley/books-db-mongodb-demodata is used.
# This is typically done when also using a Spring profile (for the api tier) that is suffixed -no-auth.
# To stop this behaviour remove the "-demodata" name from the image and make a couple of edits
# to the .env environment variables file.
image: aidanwhiteley/books-db-mongodb-demodata:5.0.30-focal
restart: unless-stopped
# Uncomment to access the MongoDB directly from the host - perhaps for debugging
#ports:
# - 27017:27017
environment:
- MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE}
- MONGO_DATA_DIR=/data/db
# MONGO_LOG_DIR=/dev/null
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
- MONGO_INITDB_APP_USERNAME=${MONGO_INITDB_APP_USERNAME}
- MONGO_INITDB_APP_PASSWORD=${MONGO_INITDB_APP_PASSWORD}
# The default Mongo log level is too verbose - it obscures what is happening in this demo use
# Comment out for debugging / production
#logging:
# driver: "none"
healthcheck:
test: echo 'db.runCommand({serverStatus:1}).ok' | mongo admin -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --quiet | grep 1
interval: "20s"
timeout: "5s"
start_period: "30s"
retries: 3
# This container is built using Google Jib using the following maven command
# for the project at https://github.com/aidanwhiteley/books-springbootadmin
# mvn compile jib:dockerBuild (see comments in pom.xml).
# Provides a Spring Boot Admin service for monitoring those services that are
# registered in the Service Registry defined at service-registry-tier.
boot-admin-tier:
container_name: books-admin-container
image: aidanwhiteley/books-spring-boot-admin:0.0.7-RELEASE
restart: unless-stopped
# Uncomment to view the Spring Boot Admin console directly rather than via the nginx reverse proxy
ports:
- 8888:8888
environment:
- "SPRING_PROFILES_ACTIVE=container"
- "SPRING_BOOT_ADMIN_USERNAME=${SPRING_BOOT_ADMIN_USERNAME}"
- "SPRING_BOOT_ADMIN_PASSWORD=${SPRING_BOOT_ADMIN_PASSWORD}"
- "JAVA_BOOKS_ACTUATOR_ONLY_JWT_TOKEN=${JAVA_BOOKS_ACTUATOR_ONLY_JWT_TOKEN}"
- "SERVICE_REGISTRY=${SERVICE_REGISTRY}"
depends_on:
service-registry-tier:
condition: service_started