Skip to content

Commit

Permalink
Merge pull request #580 from aidanwhiteley/new-react-client
Browse files Browse the repository at this point in the history
New react client
  • Loading branch information
aidanwhiteley authored Oct 30, 2024
2 parents 38d5551 + 4a3c2f3 commit 39827b8
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 212 deletions.
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ WEB_HEALTHCHECK_TEST=curl --fail localhost/api/books || exit 1
# #############################################################################
# Environment variables used by the books microservice
# #############################################################################
# Set to 0 for random port (if using multiple instances of the microservice in containers) or a specific port e.g. 8080
SPRING_SERVER_PORT=0
# Used in signing the JWTs that secure access to the application. YOU MUST CHANGE THIS.
# Set to 0 for random port or a specific port e.g. 8080 if not exposing to host
SPRING_SERVER_PORT=8080
# Used in signing the JWTs that secure access to the application. YOU MUST CHANGE THIS when running in production
# See com.aidanwhiteley.books.controller.jwt.JwtUtils::createRandomBase64EncodedSecretKey for example code
# to generate a suitable SecretKey
JAVA_BOOKS_JWT_SECRET_KEY=wMYg4eYtigrQRSrqpI4ugQbK6BwutoAzXZ5jmK4nrybeOYkMbJrScOHmMQvld0RjHWWfyCx+foRk2lL7XbGQMA==
Expand Down Expand Up @@ -59,4 +59,4 @@ SPRING_BOOT_ADMIN_USERNAME=anAdminUser-CHANGE_ME
SPRING_BOOT_ADMIN_PASSWORD=aPassword-CHANGE_ME
# This value allows Spring Boot Admin to get actuator data from the access controlled books microservice.
# Get this value from the application logs if JAVA_BOOKS_ALLOW_ACTUATOR_USER_CREATION is true. Varies with JWT_SECRET_KEY
JAVA_BOOKS_ACTUATOR_ONLY_JWT_TOKEN=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJMT0NBTF9BQ1RVQVRPUl9VU0VSIiwiaXNzIjoiQ2xvdWR5Qm9va0NsdWIiLCJwcm92aWRlciI6IkxPQ0FMIiwibmFtZSI6IkFjdHVhdG9yIFVzZXIiLCJyb2xlcyI6IjIiLCJpYXQiOjE2OTY3ODY4NDAsImV4cCI6MTcyODMyMjg0MH0.opC3bWIaV6jKreyqs57-OwvQI4aOdMt3-JYoDYznezW7sf-Gd0bzOtXCNJHKLAYJU4HsJgTBGMExCRNPJlZNgQ
JAVA_BOOKS_ACTUATOR_ONLY_JWT_TOKEN=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJMT0NBTF9BQ1RVQVRPUl9VU0VSIiwiaXNzIjoiQ2xvdWR5Qm9va0NsdWIiLCJwcm92aWRlciI6IkxPQ0FMIiwibmFtZSI6IkFjdHVhdG9yIFVzZXIiLCJyb2xlcyI6IjIiLCJpYXQiOjE3MzAxNDgyMzQsImV4cCI6MTc2MTY4NDIzNH0.62pSmCT4IrdQEIP95nWPEFszKcAaZ1tZ3R1tPI1JxZp8nwD88QtL5-md79NKmv3j7xCMlIPnmBJwwA-93AsbZQ
181 changes: 78 additions & 103 deletions README.md

Large diffs are not rendered by default.

45 changes: 26 additions & 19 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Creates and run the Docker containers for the
#
# a) the books web tier SPA
# - github repository - https://github.com/aidanwhiteley/books-web
# - 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
Expand All @@ -21,23 +21,21 @@
#

# This docker-compose file expects to see a .env file in the same directory.
# This version retrieved from Git must be edited for your usage but will basically work without any edits
# 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!).

version: '3.7'

services:

# This container is built using the commands detailed in the Dockerfile
# at https://github.com/aidanwhiteley/books-web
# Change the image name to aidanwhiteley/books-web-angular (i.e. no "-gateway") to
# 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-angular:
container_name: books-web-angular-container
image: aidanwhiteley/books-web-angular-gateway:v0.1.1
web-tier-react:
container_name: books-web-react-container
image: aidanwhiteley/books-web-react-gateway:v0.1.1
restart: unless-stopped
ports:
- 80:80
Expand All @@ -51,7 +49,10 @@ services:
start_period: "30s"
retries: 3
depends_on:
- api-gateway-tier
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
Expand All @@ -70,7 +71,8 @@ services:
- "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
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
Expand All @@ -94,7 +96,7 @@ services:

# 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-angular
# 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
Expand All @@ -103,7 +105,7 @@ services:
# 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.30.4-RELEASE
image: aidanwhiteley/books-api-java:0.50.3-RELEASE
restart: unless-stopped
environment:
- "SPRING_PROFILES_ACTIVE=${JAVA_BOOKS_SPRING_PROFILE}"
Expand All @@ -122,9 +124,13 @@ services:
- "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
- service-registry-tier
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
Expand All @@ -138,7 +144,7 @@ services:
# 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.5-focal
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:
Expand All @@ -153,8 +159,8 @@ services:
- 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"
#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"
Expand All @@ -181,4 +187,5 @@ services:
- "JAVA_BOOKS_ACTUATOR_ONLY_JWT_TOKEN=${JAVA_BOOKS_ACTUATOR_ONLY_JWT_TOKEN}"
- "SERVICE_REGISTRY=${SERVICE_REGISTRY}"
depends_on:
- service-registry-tier
service-registry-tier:
condition: service_started
10 changes: 1 addition & 9 deletions src/main/resources/application-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,11 @@ wiremock:
books:
autoAuthUser: false

client:
enableCORS: true # Note - this value overriden in the IntegrationTest base test class
allowedCorsOrigin: http://localhost:9000
postLogonUrl: http://localhost:9000/
xsrfHeader: X-XSRF

google:
books:
api:
searchUrl: http://localhost:${wiremock.server.port}/books/v1/volumes?q=
getByIdUrl: http://localhost:${wiremock.server.port}/books/v1/volumes/
countryCode: country=GB
maxResults: maxResults=30
connectTimeout: 500
readTimeout: 750

Expand All @@ -77,7 +69,7 @@ books:
users:
default:
admin:
email: "exmaple@example.com" # The remote email address for the user that will be automatically made an admin on first logon
email: "example@example.com" # The remote email address for the user that will be automatically made an admin on first logon
registrationAdminEmail:
enabled: false
emailFrom: "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-cloudy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ books:

client:
enableCORS: false
postLogonUrl: /
postLogonUrl: https://cloudybookclub.com/?logged-on=y

google:
books:
Expand Down
13 changes: 5 additions & 8 deletions src/main/resources/application-dev-mongo-java-server-no-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,25 @@ books:

client:
enableCORS: true # Note - this value overriden in the IntegrationTest base test class
allowedCorsOrigin: http://localhost:9000
postLogonUrl: http://localhost:9000/
allowedCorsOrigin: http://localhost:5173
postLogonUrl: http://localhost:5173/
xsrfHeader: X-XSRF

google:
books:
api:
searchUrl: http://localhost:${wiremock.server.port}/books/v1/volumes?q=
getByIdUrl: http://localhost:${wiremock.server.port}/books/v1/volumes/
countryCode: country=GB
maxResults: maxResults=30
connectTimeout: 500
readTimeout: 750

connecTimeout: 200
readTimeout: 300
reload:
development:
data: true # Whether the contents of the /src/main/resources/sample_data will be reloaded into the database at application startup. Deletes all existing data!!!

users:
default:
admin:
email: "exmaple@example.com" # The remote email address for the user that will be automatically made an admin on first logon
email: "example@example.com" # The remote email address for the user that will be automatically made an admin on first logon
registrationAdminEmail:
enabled: false
emailFrom: "[email protected]"
Expand Down
7 changes: 0 additions & 7 deletions src/main/resources/application-dev-mongo-java-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,12 @@ logging:
ApplicationRegistrator: ERROR

books:
client:
enableCORS: false # Note - this value overriden in the IntegrationTest base test class
allowedCorsOrigin: http://localhost:9000
postLogonUrl: http://localhost:5173/?logged-on=y
xsrfHeader: X-XSRF

google:
books:
api:
searchUrl: http://localhost:${wiremock.server.port}/books/v1/volumes?q=
getByIdUrl: http://localhost:${wiremock.server.port}/books/v1/volumes/
countryCode: country=GB
maxResults: maxResults=30
connectTimeout: 2500
readTimeout: 2000

Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/application-dev-mongodb-no-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,13 @@ books:
autoAuthUser: true

client:
enableCORS: true # Note - this value overriden in the IntegrationTest base test class
allowedCorsOrigin: http://localhost:9000
postLogonUrl: http://localhost:9000/
xsrfHeader: X-XSRF
enableCORS: false # Note - this value overriden in the IntegrationTest base test class

google:
books:
api:
searchUrl: http://localhost:${wiremock.server.port}/books/v1/volumes?q=
getByIdUrl: http://localhost:${wiremock.server.port}/books/v1/volumes/
countryCode: country=GB
maxResults: maxResults=30
connectTimeout: 500
readTimeout: 750

Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/application-dev-mongodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,12 @@ books:

client:
enableCORS: true # Note - this value overriden in the IntegrationTest base test class
allowedCorsOrigin: http://localhost:9000
postLogonUrl: http://localhost:9000/
xsrfHeader: X-XSRF

google:
books:
api:
searchUrl: http://localhost:${wiremock.server.port}/books/v1/volumes?q=
getByIdUrl: http://localhost:${wiremock.server.port}/books/v1/volumes/
countryCode: country=GB
maxResults: maxResults=30
connectTimeout: 500
readTimeout: 750

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring:
profiles:
active: dev-mongo-java-server
active: dev-mongo-java-server-no-auth

mvc:
pathmatch:
Expand All @@ -27,11 +27,11 @@ spring:
google:
client-id: NotInSCM1
client-secret: NotInSCM1
redirect-uri: https://cloudybookclub.com/login/oauth2/code/google
redirect-uri: https://localhost:8080/login/oauth2/code/google
facebook:
client-id: NotInSCM2
client-secret: NotInSCM2
redirect-uri: https://cloudybookclub.com/login/oauth2/code/facebook
redirect-uri: https://localhost:8080/login/oauth2/code/facebook
provider:
# Google provides all the info this app needs by default. Facebook needs configuring.
facebook:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<logger name="org.springframework.context" level="WARN" />
<logger name="org.springframework.boot.availability.ApplicationAvailabilityBean" level="INFO" />

<!-- Possibly related to https://github.com/spring-cloud/spring-cloud-commons/issues/1315 -->
<logger name="org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker" level="ERROR" />

<!-- See https://github.com/aidanwhiteley/books/issues/86 -->
<logger name="org.springframework.data.convert.CustomConversions" level="ERROR" />

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/mongo-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# for books.users.default.admin.email.
#
# To build the Docker image use:
# docker build --rm -t aidanwhiteley/books-db-mongodb:5.0.5-focal .
# docker build --rm -t aidanwhiteley/books-db-mongodb:5.0.30-focal .
#
# To run the Dockerfile created image use something like:
# docker run -e MONGO_INITDB_APP_USERNAME=abc -e MONGO_INITDB_APP_PASSWORD=def -e MONGO_INITDB_DATABASE=ghi aidanwhiteley/books-db-mongodb
#
# The Dockerfile created image is expected to be run from a docker-compose that sets the environment variables
# and is also in control of setting the overall MongoDb authorisation settings i.e. requiring authorisation!
#
FROM mongo:5.0.5-focal
FROM mongo:5.0.30-focal
COPY db_init/*.sh /docker-entrypoint-initdb.d/
RUN chmod +x /docker-entrypoint-initdb.d/addUserFromEnvVar.sh
4 changes: 2 additions & 2 deletions src/main/resources/mongo-docker/Dockerfile-demodata
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
# some sample users.
#
# To build the Docker image use:
# docker build --rm -f Dockerfile-demodata -t aidanwhiteley/books-db-mongodb-demodata:5.0.5-focal .
# docker build --rm -f Dockerfile-demodata -t aidanwhiteley/books-db-mongodb-demodata:5.0.30-focal .
#
# To run the Dockerfile created image use something like:
# docker run -e MONGO_INITDB_APP_USERNAME=abc -e MONGO_INITDB_APP_PASSWORD=def -e MONGO_INITDB_DATABASE=ghi aidanwhiteley/books-db-mongodb-demodata
#
# The Dockerfile created image is expected to be run from a docker-compose that sets the environment variables
# and is also in control of setting the overall MongoDb authorisation settings i.e. requiring authorisation!
#
FROM mongo:5.0.5-focal
FROM mongo:5.0.30-focal
COPY db_init/*.js /docker-entrypoint-initdb.d/
COPY db_init/*.sh /docker-entrypoint-initdb.d/
RUN chmod +x /docker-entrypoint-initdb.d/addUserFromEnvVar.sh
1 change: 1 addition & 0 deletions src/main/resources/mongo-docker/db_init/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
2 changes: 0 additions & 2 deletions src/main/resources/mongo-docker/db_init/addUserFromEnvVar.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/bash
# Creates the application Mongo user
# If editing, ensure file has unix style line endings - use dos2unix after editing on Windows
mongo <<EOF
use $MONGO_INITDB_DATABASE;
db.createUser({
Expand Down
Loading

0 comments on commit 39827b8

Please sign in to comment.