From a33c9608f083e1182862e00998c2c3702d0e842c Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 1 Nov 2023 14:41:06 +0000 Subject: [PATCH 1/9] change the build command base-href to ./ --- ui/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/package.json b/ui/package.json index 1aa605da5..cc5074034 100644 --- a/ui/package.json +++ b/ui/package.json @@ -5,8 +5,8 @@ "ng": "ng", "start": "ng serve --disable-host-check --host 0.0.0.0", "start_ssl": "ng serve --disable-host-check --host 0.0.0.0 --ssl", - "build": "ng build --base-href='/ui/'", - "watch": "ng build --base-href='/ui/' --watch --configuration development", + "build": "ng build --base-href='./'", + "watch": "ng build --base-href='./' --watch --configuration development", "test": "ng test", "lint": "ng lint", "format:cli": "ng lint && npx prettier .", From f0f4a6e8d5e780c8c1a41f6283083c14e5fec831 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 1 Nov 2023 14:47:34 +0000 Subject: [PATCH 2/9] add nginx image for multi stage build --- ui/Dockerfile | 28 +++++++----- .../etc/nginx/conf.d/default.conf | 44 +++++++++++++++++++ ui/container-files/etc/nginx/nginx.conf | 31 +++++++++++++ 3 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 ui/container-files/etc/nginx/conf.d/default.conf create mode 100644 ui/container-files/etc/nginx/nginx.conf diff --git a/ui/Dockerfile b/ui/Dockerfile index 48ddb0e98..ece9a6d5a 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20.7.0-bullseye-slim +FROM node:20.7.0-bullseye-slim AS ui-build-stage # Create app directory WORKDIR /app @@ -6,7 +6,7 @@ WORKDIR /app # Install some useful utils for debug/test RUN \ apt-get update && \ - apt -y install procps iproute2 net-tools curl iputils-ping vim && \ + apt -y install python3 make gcc g++ && \ rm -rf /var/lib/apt/lists/* # Install app dependencies @@ -14,20 +14,28 @@ RUN \ # where available (npm@5+) COPY package*.json ./ -COPY container-files/* /var/tmp/ - -RUN \ - chmod +x /var/tmp/* && \ - npm install - # If you are building your code for production # RUN npm install --only=production +RUN npm install # Bundle app source COPY . . RUN npm run build -EXPOSE 4200 +FROM nginx + +RUN \ + apt-get update && \ + apt -y install procps vim && \ + rm -rf /var/lib/apt/lists/* + +COPY container-files/ /var/tmp/ + +# Copy files from the ui-build-stage into this new nginx stage +COPY --from=ui-build-stage /app/dist/ui /usr/share/nginx/html + +EXPOSE 80 -ENTRYPOINT /var/tmp/entrypoint.sh +# Use the underlying ENTRYPOINT and CMD provided by the base NGINX image +#ENTRYPOINT /var/tmp/entrypoint.sh diff --git a/ui/container-files/etc/nginx/conf.d/default.conf b/ui/container-files/etc/nginx/conf.d/default.conf new file mode 100644 index 000000000..b1a80321d --- /dev/null +++ b/ui/container-files/etc/nginx/conf.d/default.conf @@ -0,0 +1,44 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} \ No newline at end of file diff --git a/ui/container-files/etc/nginx/nginx.conf b/ui/container-files/etc/nginx/nginx.conf new file mode 100644 index 000000000..ee8c7fd6b --- /dev/null +++ b/ui/container-files/etc/nginx/nginx.conf @@ -0,0 +1,31 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + include /etc/nginx/conf.d/*.conf; +} \ No newline at end of file From 68d2c3d8fa85c5be649daab9557ed3a09bbc694d Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 1 Nov 2023 14:48:54 +0000 Subject: [PATCH 3/9] use the default entrypoint script embedded within the nginx image --- ui/container-files/entrypoint.sh | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 ui/container-files/entrypoint.sh diff --git a/ui/container-files/entrypoint.sh b/ui/container-files/entrypoint.sh deleted file mode 100644 index f93b1d9a2..000000000 --- a/ui/container-files/entrypoint.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -# The NPM "start" command/script is defined in the package.json file in the "scripts" dict -npm start From 1bcb9feca080f46a08bd9f8597f577f2d3118c75 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 1 Nov 2023 22:03:48 +0000 Subject: [PATCH 4/9] Change ng build output path to /dist, change the web service port from 4200 to 8090 --- ui/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/Dockerfile b/ui/Dockerfile index ece9a6d5a..d1ae9bfdc 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -30,12 +30,12 @@ RUN \ apt -y install procps vim && \ rm -rf /var/lib/apt/lists/* -COPY container-files/ /var/tmp/ +COPY container-files/etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf # Copy files from the ui-build-stage into this new nginx stage -COPY --from=ui-build-stage /app/dist/ui /usr/share/nginx/html +COPY --from=ui-build-stage /app/dist/ /usr/share/nginx/html/ -EXPOSE 80 +EXPOSE 8090 # Use the underlying ENTRYPOINT and CMD provided by the base NGINX image #ENTRYPOINT /var/tmp/entrypoint.sh From c185cc3cda9255a7c52231b80bd6291c694416f7 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 1 Nov 2023 22:04:19 +0000 Subject: [PATCH 5/9] Change ng build output path to /dist, change the web service port from 4200 to 8090 --- ui/angular.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/angular.json b/ui/angular.json index d9e6c11c0..a07983c60 100644 --- a/ui/angular.json +++ b/ui/angular.json @@ -17,7 +17,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/ui", + "outputPath": "dist/", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", From ee992630ad7659d9bcf573baa4bd224b98e076f3 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 1 Nov 2023 22:06:44 +0000 Subject: [PATCH 6/9] Change service port from 4200 to 8090 for nginx --- docker-compose.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 084e1416d..c9b84fac3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -172,10 +172,12 @@ services: ui: restart: unless-stopped - image: ${DOCKER_REG}/ui:${TAG:-1} + image: ${DOCKER_REG}/ui:${TAG:} environment: - 'SPRING_PROFILES_ACTIVE=prod' + - OAUTH2_WEB_CLIENT_CONFIGURATION_SECRET=${WEB_CLIENT_CONFIGURATION_SECRET} + - GATEWAY_COOKIE_DOMAIN=${COOKIE_DOMAIN} volumes: - ${LOG_VOLUME:-/var/tmp/}:/logs ports: - - 4200:4200 + - 8090:8090 From b488efad28f6c951a792cf3991ddd356b2532015 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 1 Nov 2023 22:09:41 +0000 Subject: [PATCH 7/9] Change service port, add a rewrite rule to strip /ui from uri path. --- .../etc/nginx/conf.d/default.conf | 27 +++---------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/ui/container-files/etc/nginx/conf.d/default.conf b/ui/container-files/etc/nginx/conf.d/default.conf index b1a80321d..e27c46b6b 100644 --- a/ui/container-files/etc/nginx/conf.d/default.conf +++ b/ui/container-files/etc/nginx/conf.d/default.conf @@ -1,6 +1,5 @@ server { - listen 80; - listen [::]:80; + listen 8090; server_name localhost; #access_log /var/log/nginx/host.access.log main; @@ -8,6 +7,7 @@ server { location / { root /usr/share/nginx/html; index index.html index.htm; + rewrite ^/ui/(.*) /$1 break; } #error_page 404 /404.html; @@ -19,26 +19,5 @@ server { root /usr/share/nginx/html; } - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - #location ~ \.php$ { - # root html; - # fastcgi_pass 127.0.0.1:9000; - # fastcgi_index index.php; - # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - # include fastcgi_params; - #} +} - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} -} \ No newline at end of file From a9427b9bdf9ae36cb2c939e10d1b30393504af1f Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Thu, 2 Nov 2023 12:27:57 +0000 Subject: [PATCH 8/9] Change the build script base-href path to /ui/ to match the path where it is served from on the load balancer --- ui/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/package.json b/ui/package.json index cc5074034..1aa605da5 100644 --- a/ui/package.json +++ b/ui/package.json @@ -5,8 +5,8 @@ "ng": "ng", "start": "ng serve --disable-host-check --host 0.0.0.0", "start_ssl": "ng serve --disable-host-check --host 0.0.0.0 --ssl", - "build": "ng build --base-href='./'", - "watch": "ng build --base-href='./' --watch --configuration development", + "build": "ng build --base-href='/ui/'", + "watch": "ng build --base-href='/ui/' --watch --configuration development", "test": "ng test", "lint": "ng lint", "format:cli": "ng lint && npx prettier .", From 84a82684596e0a9270ad0768839058d21f93e8a5 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Thu, 2 Nov 2023 12:29:23 +0000 Subject: [PATCH 9/9] comment out my ../404 page change for the time being --- ui/container-files/etc/nginx/conf.d/default.conf | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/container-files/etc/nginx/conf.d/default.conf b/ui/container-files/etc/nginx/conf.d/default.conf index e27c46b6b..f61676a2f 100644 --- a/ui/container-files/etc/nginx/conf.d/default.conf +++ b/ui/container-files/etc/nginx/conf.d/default.conf @@ -10,14 +10,15 @@ server { rewrite ^/ui/(.*) /$1 break; } - #error_page 404 /404.html; + # JT. Uncomment the error_page directive below to use the orcid 404 error page in /404 + #error_page 404 ../404; # redirect server error pages to the static page /50x.html # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } + #error_page 500 502 503 504 /50x.html; + #location = /50x.html { + # root /usr/share/nginx/html; + #} }