📁 Changed TDrive root folder (#16)

📁 Changed TDrive root folder
This commit is contained in:
Montassar Ghanmy
2023-04-11 10:04:29 +01:00
committed by GitHub
parent 3b3f67af07
commit e0615fa867
10548 changed files with 48 additions and 48 deletions
+31
View File
@@ -0,0 +1,31 @@
# First stage: building frontend
FROM node:lts AS build
RUN yarn global add webpack webpack-cli
COPY frontend /tdrive-react/
WORKDIR /tdrive-react/
ENV GENERATE_SOURCEMAP=false
RUN cp /tdrive-react/src/app/environment/environment.ts.dist /tdrive-react/src/app/environment/environment.ts && \
yarn install --network-timeout 1000000000 && \
# cat /tdrive-react/src/app/environment/environment.ts.dist && \
# cat /tdrive-react/src/app/environment/environment.ts && \
yarn build && \
rm -rf node_modules
# Second stage: configuring nginx and copying build artifacts
FROM nginx:latest
COPY docker/tdrive-frontend/nginx.conf /etc/nginx/nginx.conf
COPY docker/tdrive-frontend/site.conf /etc/nginx/sites-available/site.template
COPY docker/tdrive-frontend/redirect.conf /etc/nginx/sites-available/redirect
COPY docker/tdrive-frontend/entrypoint.sh /
COPY docker/tdrive-frontend/self-signed.sh /usr/local/bin/
COPY --from=build /tdrive-react /tdrive-react
RUN chmod +x /entrypoint.sh && rm /etc/nginx/conf.d/default.conf
ENTRYPOINT ["/entrypoint.sh", "$DEV"]
EXPOSE 80
EXPOSE 443
+48
View File
@@ -0,0 +1,48 @@
#!/bin/bash
if [ "$1" = "dev" ]
then
if test -f "/tdrive-react/src/app/environment/environment.ts"; then
echo "Configuration exists, doing nothing."
else
cp /tdrive-react/src/app/environment/environment.ts.dist.dev /tdrive-react/src/app/environment/environment.ts
fi
else
if test -f "/configuration/environment.ts"; then
cp /configuration/environment.ts /tdrive-react/src/app/environment/environment.ts
else
cp /tdrive-react/src/app/environment/environment.ts.dist /tdrive-react/src/app/environment/environment.ts
fi
fi
[[ -d "/etc/nginx/sites-enabled" ]] || mkdir /etc/nginx/sites-enabled
function _selfsigned() {
self-signed.sh
export NGINX_LISTEN="443 ssl"
ln -sf /etc/nginx/sites-available/redirect /etc/nginx/sites-enabled/
}
case $SSL_CERTS in
selfsigned)
_selfsigned
;;
off|no|non|none|false)
export NGINX_LISTEN="80"
sed -i '/ *ssl_/d' /etc/nginx/sites-available/site.template
;;
*)
echo: "SSL_CERTS var not defined setting selfsigned"
export SSL_CERTS=selfsigned
_selfsigned
;;
esac
NODE_HOST="${NODE_HOST:-http://node:3000}"
PHP_UPSTREAM="${PHP_UPSTREAM:-php:9000}"
export NODE_HOST
export PHP_UPSTREAM
envsubst '$${NODE_HOST} $${NGINX_LISTEN}' < /etc/nginx/sites-available/site.template > /etc/nginx/sites-enabled/site
echo "upstream php-upstream { server ${PHP_UPSTREAM}; }" > /etc/nginx/conf.d/upstream.conf
nginx -g "daemon off;"
+65
View File
@@ -0,0 +1,65 @@
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
client_max_body_size 200M;
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
@@ -0,0 +1,7 @@
server {
listen 80;
server_name localhost;
location / {
return 302 https://$server_name$request_uri;
}
}
+52
View File
@@ -0,0 +1,52 @@
#!/bin/bash
# Script to create selfsigned certificates if they don't exist. All certificate
# information can be customized using env variables.
# Licence: GPL
# Note: derivated from https://gitlab.com/live9/docker/containers/openssl/-/blob/master/entrypoint
#
set -eo pipefail
[ "${DEBUG}" = "yes" ] && set -x
SSL_PATH="/etc/nginx/ssl/"
SSL_KEY="${SSL_PATH}/selfsigned.key"
SSL_CERT_REQUEST="${SSL_PATH}/selfsigned.csr"
SSL_CERTIFICATE="${SSL_PATH}/selfsigned.crt"
SSL_DHPARAM_FILE="${SSL_PATH}/dhparam.pem"
# Certificate creation params
SSL_VALID_DAYS="${SSL_VALID_DAYS:-365}"
SSL_SUBJ_COUNTRY="${SSL_SUBJ_COUNTRY:-FR}"
SSL_SUBJ_STATE="${SSL_SUBJ_STATE:-Hauts-de-France}"
SSL_SUBJ_LOCALITY="${SSL_SUBJ_LOCALITY:-Paris}"
SSL_SUBJ_ORG="${SSL_SUBJ_ORG:-Linagora}"
SSL_SUBJ_ORG_UNIT="${SSL_SUBJ_ORG_UNIT:- Tdrive}"
SSL_SUBJ_CN="${SSL_SUBJ_CN:-localhost}"
SSL_SUBJECT="/C=${SSL_SUBJ_COUNTRY}/ST=${SSL_SUBJ_STATE}/L=${SSL_SUBJ_LOCALITY}/O=${SSL_SUBJ_ORG}/OU=${SSL_SUBJ_ORG_UNIT}/CN=${SSL_SUBJ_CN}"
SSL_KEY_LENGTH=${SSL_KEY_LENGTH:-2048}
if [ ! -f ${SSL_CERTIFICATE} ]; then
echo "Creating certificate sigining request..."
mkdir -p ${SSL_PATH}
openssl req \
-newkey rsa:${SSL_KEY_LENGTH} \
-sha256 \
-nodes \
-keyout ${SSL_KEY} \
-out ${SSL_CERT_REQUEST} \
-subj "${SSL_SUBJECT}"
echo "Creating self-signed certificate..."
openssl x509 -req -days ${SSL_VALID_DAYS} \
-in ${SSL_CERT_REQUEST} \
-signkey ${SSL_KEY} \
-out ${SSL_CERTIFICATE}
echo "Creating dhparam file..."
# When SSL_DHPARAM_FILE is present the whole process is done
openssl dhparam -out ${SSL_DHPARAM_FILE}.tmp ${SSL_KEY_LENGTH}
mv ${SSL_DHPARAM_FILE}.tmp ${SSL_DHPARAM_FILE}
echo "Done."
else
echo "Selfsigned certificate already exists, skipping."
fi
+111
View File
@@ -0,0 +1,111 @@
server {
listen ${NGINX_LISTEN};
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_certificate /etc/nginx/ssl/selfsigned.crt;
ssl_certificate_key /etc/nginx/ssl/selfsigned.key;
server_name localhost;
root /tdrive-core/web;
add_header Strict-Transport-Security "max-age=31536000";
location /.well-known {
alias /tdrive-react/build/.well-known/;
gzip on;
gzip_disable "msie6";
add_header Cache-Control "no-store, public, max-age=0";
add_header Cross-Origin-Opener-Policy 'same-origin-allow-popups; report-to="DurableDeepLinkUi"';
add_header Cross-Origin-Resource-Policy "same-site";
add_header Content-Type "application/json; charset=utf-8";
add_header Last-Modified "";
add_header Vary "Sec-Fetch-Dest, Sec-Fetch-Mode, Sec-Fetch-Site";
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "0";
proxy_buffering off;
if_modified_since off;
expires 0s;
allow all;
try_files $uri /index.html;
}
location / {
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
image/svg+xml;
alias /tdrive-react/build/;
allow all;
try_files $uri /index.html;
}
location ~ ^/(internal).* {
proxy_set_header X-Forwarded-Host $host;
proxy_pass ${NODE_HOST};
}
location ~ ^/(plugins).* {
set $target http://plugins_container:8080;
proxy_set_header X-Forwarded-Host $host;
proxy_pass $target;
}
location ~ ^/(api|administration/v2/).* {
proxy_set_header X-Forwarded-Host $host;
proxy_pass ${NODE_HOST};
}
location ~ ^/socket/.* {
proxy_pass ${NODE_HOST};
# this magic is needed for WebSocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
location ~ ^/(ajax|api|administration|upload|bundle|medias).* {
# try to serve file directly, fallback to rewrite
try_files $uri @rewriteapp;
}
location @rewriteapp {
# rewrite all to app.php
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config|dev\/.*)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
}
+52
View File
@@ -0,0 +1,52 @@
# Common node machine
FROM node:lts as node-base
### Install dependancies
RUN apt-get update && \
apt-get install -y ghostscript graphicsmagick wget unoconv libxml2-dev ffmpeg python-is-python3 && \
# upgrade unoconv
wget -N https://raw.githubusercontent.com/dagwieers/unoconv/master/unoconv -O /usr/bin/unoconv && \
chmod +x /usr/bin/unoconv
#Docker mac issue
# RUN apt-get update && apt-get install -y libc6
# RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
### Install TDrive
WORKDIR /usr/src/app
COPY backend/node/package*.json ./
# Test Stage
FROM node-base as test
RUN npm install
COPY backend/node/ .
# Add frontend Stage
FROM node-base as installed-libs
COPY backend/node/ .
#Install dev dependancies for build
RUN NODE_ENV=development npm install && \
#Build in production mode
export NODE_ENV=production && \
npm run build && \
rm -rf node_modules && \
#Install prod dependancies after build
npm install --legacy-peer-deps
# Development Stage
FROM installed-libs as development
ENV NODE_ENV=development
RUN npm install -g pino-pretty && \
npm install -g tsc-watch && \
yarn install
CMD ["npm", "run", "dev:debug"]
# Production Stage
FROM installed-libs as production
EXPOSE 3000
CMD ["npm", "run", "serve"]