AAE-4023 fix BASE_PATH as / (#6397)

This commit is contained in:
Marcello Teodori 2020-11-30 22:59:31 +01:00 committed by GitHub
parent f3e5dfecec
commit 419c47b87e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 149 additions and 74 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ node_modules
bundles
workspace.xml
.idea/
*.iml
.env.*
.env
dist/

View File

@ -1,12 +1,29 @@
FROM nginx:stable-alpine
LABEL version="3.0.0"
# 1. Generate licenses
ARG PROJECT_NAME=demo-shell
FROM node:12.16.2-alpine3.9 AS builder
WORKDIR /usr/src/alfresco
COPY package.json package.json
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
COPY ./docker/entrypoint.sh /
RUN mkdir -p ./licenses && \
yarn licenses list > ./licenses/licenses.txt && \
yarn licenses generate-disclaimer > ./licenses/disclaimer.txt
WORKDIR /usr/share/nginx/html
COPY dist/$PROJECT_NAME .
# 2. Generate image
ENTRYPOINT [ "/entrypoint.sh" ]
FROM nginxinc/nginx-unprivileged:1.19.3-alpine
ARG PROJECT_NAME
COPY docker/default.conf.template /etc/nginx/templates/
COPY docker/docker-entrypoint.d/* /docker-entrypoint.d/
COPY dist/$PROJECT_NAME /usr/share/nginx/html/
COPY dist/$PROJECT_NAME/app.config.json /etc/nginx/templates/app.config.json.template
COPY --from=builder /usr/src/alfresco/licenses /usr/share/nginx/html/
USER root
RUN chmod a+w -R /etc/nginx/conf.d
USER 101
ENV BASE_PATH=/
ENV NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx/conf.d

View File

@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<title>ACS APS ADF Application with Angular CLI</title>
<base href="/">
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="favicon-96x96.png" sizes="96x96">

7
docker/build.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
echo building $1
npm install
npm run build $*

View File

@ -0,0 +1,55 @@
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html;
rewrite ^([^.]*[^/])$ $1/ permanent;
location ${BASE_PATH} {
set $EVAL_BASE_PATH "${BASE_PATH}";
if ($EVAL_BASE_PATH = "/") {
root /usr/share/nginx/html;
}
index index.html index.htm;
alias /usr/share/nginx/html;
}
location ~ /app.config.json {
alias ${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json;
}
#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;
#}
}

View File

@ -1,81 +1,79 @@
#!/bin/sh
if [ -n "${APP_CONFIG_AUTH_TYPE}" ];then
set -e
echo Running sed on "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
if [ -n "${APP_CONFIG_AUTH_TYPE}" ]; then
sed -e "s/\"authType\": \".*\"/\"authType\": \"${APP_CONFIG_AUTH_TYPE}\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_IDENTITY_HOST}" ]; then
replace="\/"
encodedIdentity=${APP_CONFIG_IDENTITY_HOST//\//$replace}
sed -e "s/\"identityHost\": \".*\"/\"identityHost\": \"$encodedIdentity\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_OAUTH2_HOST}" ];then
if [ -n "${APP_CONFIG_OAUTH2_HOST}" ]; then
replace="\/"
encoded=${APP_CONFIG_OAUTH2_HOST//\//$replace}
sed -e "s/\"host\": \".*\"/\"host\": \"${encoded}\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_OAUTH2_CLIENTID}" ];then
if [ -n "${APP_CONFIG_OAUTH2_CLIENTID}" ]; then
sed -e "s/\"clientId\": \".*\"/\"clientId\": \"${APP_CONFIG_OAUTH2_CLIENTID}\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_OAUTH2_IMPLICIT_FLOW}" ];then
if [ -n "${APP_CONFIG_OAUTH2_IMPLICIT_FLOW}" ]; then
sed -e "s/\"implicitFlow\": [^,]*/\"implicitFlow\": ${APP_CONFIG_OAUTH2_IMPLICIT_FLOW}/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_OAUTH2_SILENT_LOGIN}" ];then
if [ -n "${APP_CONFIG_OAUTH2_SILENT_LOGIN}" ]; then
sed -e "s/\"silentLogin\": [^,]*/\"silentLogin\": ${APP_CONFIG_OAUTH2_SILENT_LOGIN}/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI}" ];then
if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI}" ]; then
replace="\/"
encoded=${APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI//\//$replace}
sed -e "s/\"redirectSilentIframeUri\": \".*\"/\"redirectSilentIframeUri\": \"${encoded}\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_LOGIN}" ];then
if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_LOGIN}" ]; then
replace="\/"
encoded=${APP_CONFIG_OAUTH2_REDIRECT_LOGIN//\//$replace}
sed -e "s/\"redirectUri\": \".*\"/\"redirectUri\": \"${encoded}\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_LOGOUT}" ];then
if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_LOGOUT}" ]; then
replace="\/"
encoded=${APP_CONFIG_OAUTH2_REDIRECT_LOGOUT//\//$replace}
sed -e "s/\"redirectUriLogout\": \".*\"/\"redirectUriLogout\": \"${encoded}\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [[ -n "${APP_CONFIG_BPM_HOST}" ]]
then
if [[ -n "${APP_CONFIG_BPM_HOST}" ]]; then
replace="\/"
encoded=${APP_CONFIG_BPM_HOST//\//$replace}
sed -e "s/\"bpmHost\": \".*\"/\"bpmHost\": \"${encoded}\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [[ -n "${APP_CONFIG_ECM_HOST}" ]]
then
if [[ -n "${APP_CONFIG_ECM_HOST}" ]]; then
replace="\/"
encoded=${APP_CONFIG_ECM_HOST//\//$replace}
sed -e "s/\"ecmHost\": \".*\"/\"ecmHost\": \"${encoded}\"/g" \
-i ./app.config.json
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
if [[ -n "${BASE_PATH}" ]]
then
sed s%href=\"/\"%href=\""${BASE_PATH}"\"%g \
-i ./index.html
if [ -n "${APP_CONFIG_APPS_DEPLOYED}" ]; then
sed -e "s/\"alfresco-deployed-apps\": \[.*\]/\"alfresco-deployed-apps\": ${APP_CONFIG_APPS_DEPLOYED}/g" \
-i "${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json"
fi
nginx -g "daemon off;"

View File

@ -1,35 +0,0 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.html$ {
add_header Cache-Control "private, no-cache, no-store, must-revalidate";
add_header Expires "Sat, 01 Jan 2000 00:00:00 GMT";
add_header Pragma no-cache;
}
location ~ ^/[a-zA-Z0-9_-]+/ {
try_files $uri $uri/ /index.html;
}
}
}

11
docker/run-demo-shell.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e
[[ "$BUILD_ENABLED" == "true" ]] && $(dirname $0)/build.sh
env \
PROJECT_NAME=demo-shell \
BASE_PATH=${BASE_PATH:-/adf} \
DOCKER_IMAGE_REPO=alfresco/demo-shell \
$(dirname $0)/run.sh

21
docker/run.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e
docker rmi -f $DOCKER_IMAGE_REPO
docker build --build-arg PROJECT_NAME=$PROJECT_NAME -t $DOCKER_IMAGE_REPO .
echo http://localhost:8080$BASE_PATH
docker run --rm -it \
--env APP_CONFIG_AUTH_TYPE=$APP_CONFIG_AUTH_TYPE \
--env APP_CONFIG_IDENTITY_HOST=$APP_CONFIG_IDENTITY_HOST \
--env APP_CONFIG_OAUTH2_HOST=$APP_CONFIG_OAUTH2_HOST \
--env APP_CONFIG_OAUTH2_CLIENTID=$APP_CONFIG_OAUTH2_CLIENTID \
--env APP_CONFIG_OAUTH2_IMPLICIT_FLOW=$APP_CONFIG_OAUTH2_IMPLICIT_FLOW \
--env APP_CONFIG_OAUTH2_SILENT_LOGIN=$APP_CONFIG_OAUTH2_SILENT_LOGIN \
--env APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI=$APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI \
--env APP_CONFIG_OAUTH2_REDIRECT_LOGIN=$APP_CONFIG_OAUTH2_REDIRECT_LOGIN \
--env APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=$APP_CONFIG_OAUTH2_REDIRECT_LOGOUT \
--env APP_CONFIG_BPM_HOST=$APP_CONFIG_BPM_HOST \
--env APP_CONFIG_ECM_HOST=$APP_CONFIG_ECM_HOST \
--env BASE_PATH=$BASE_PATH \
--user 1000:1000 --publish 8080:8080 $DOCKER_IMAGE_REPO