1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

Send pre-compressed assets to the browsers instead of the regular ones

+ improved setup script with some explanations for reverse-proxies
This commit is contained in:
Sylvain 2021-03-10 12:47:01 +01:00
parent cd30e0d8d8
commit f50f5a4058
6 changed files with 92 additions and 6 deletions

View File

@ -3,7 +3,10 @@
## Next release
- Prevent showing error message when testing for old versions during upgrade
- In the email notification, sent to admins on account creation, show the group of the user
- More explanations in the setup script
- Send pre-compressed assets to the browsers instead of the regular ones
- Fix a bug: subscriptions tab is selected by default in statistics, even if the module is disabled
- [TODO DEPLOY] `\curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/scripts/nginx-packs-directive.sh | bash`
## v4.7.5 2021 March 08
- Fix a bug: unable to compile the assets during the upgrade, if the env file has some whitespaces around the equal sign

View File

@ -0,0 +1,80 @@
#!/usr/bin/env bash
yq() {
docker run --rm -i -v "${NGINX_PATH}:/workdir" mikefarah/yq:4 "$@"
}
config()
{
if [ "$(whoami)" = "root" ]
then
echo "It is not recommended to run this script as root. As a normal user, elevation will be prompted if needed."
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "Continue anyway? (Y/n) " confirm </dev/tty
if [[ "$confirm" = "n" ]]; then exit 1; fi
else
if ! groups | grep docker; then
echo "Please add your current user to the docker group."
echo "You can run the following as root: \"usermod -aG docker $(whoami)\", then logout and login again"
echo "current user is not allowed to use docker, exiting..."
exit 1
fi
fi
NGINX_PATH=$(pwd)
TYPE="NOT-FOUND"
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "Is Fab-manager installed at \"$NGINX_PATH\"? (y/N) " confirm </dev/tty
if [ "$confirm" = "y" ]; then
test_docker_compose
while [[ "$TYPE" = "NOT-FOUND" ]]
do
echo "nginx was not found at the current path, please specify the nginx installation path..."
read -e -rp "> " nginxpath </dev/tty
NGINX_PATH="${nginxpath}"
test_docker_compose
done
else
echo "Please run this script from the Fab-manager's installation folder"
exit 1
fi
SERVICE="$(yq eval '.services.*.image | select(. == "nginx*") | path | .[-2]' docker-compose.yml)"
}
test_docker_compose()
{
if [[ -f "$NGINX_PATH/docker-compose.yml" ]]
then
docker-compose -f "$NGINX_PATH/docker-compose.yml" ps | grep nginx
if [[ $? = 0 ]]
then
printf "nginx found at %s\n" "$NGINX_PATH"
TYPE="DOCKER-COMPOSE"
fi
fi
}
proceed_upgrade()
{
find "$NGINX_PATH" -name "*.conf" -exec sed -i -e 's:location ^~ /assets/ {:location ^~ /packs/ {:g' {} \; 2>/dev/null
}
docker_restart()
{
docker-compose -f "$NGINX_PATH/docker-compose.yml" restart "$SERVICE"
}
function trap_ctrlc()
{
echo "Ctrl^C, exiting..."
exit 2
}
upgrade_directive()
{
trap "trap_ctrlc" 2 # SIGINT
config
proceed_upgrade
docker_restart
printf "upgrade complete\n"
}
upgrade_directive "$@"

View File

@ -9,7 +9,7 @@ SLOT_DURATION=60
FEATURE_TOUR_DISPLAY=once
DEFAULT_HOST=demo.fab-manager.com
DEFAULT_PROTOCOL=http
DEFAULT_PROTOCOL=https
DELIVERY_METHOD=smtp
SMTP_ADDRESS=smtp.sendgrid.net

View File

@ -7,7 +7,7 @@ server {
server_name MAIN_DOMAIN;
root /usr/src/app/public;
location ^~ /assets/ {
location ^~ /packs/ {
gzip_static on;
expires max;
add_header Cache-Control public;
@ -43,7 +43,7 @@ server {
root /usr/src/app/public/;
rewrite ^(.*)$ /maintenance.html break;
}
location /.well-known/acme-challenge {
root /etc/letsencrypt/webrootauth;
default_type "text/plain";

View File

@ -28,7 +28,7 @@ server {
ssl_stapling_verify on;
location ^~ /assets/ {
location ^~ /packs/ {
gzip_static on;
expires max;
add_header Cache-Control public;

View File

@ -68,16 +68,18 @@ config()
{
SERVICE="fabmanager"
echo 'We recommend nginx to serve the application over the network (internet). You can use your own solution or let this script install and configure nginx for Fab-manager.'
printf 'If you want to setup install Fab-manager behind a reverse proxy, you may not need to install the integrated nginx.\n'
read -rp 'Do you want install nginx? (Y/n) ' NGINX </dev/tty
if [ "$NGINX" != "n" ]; then
# if the user doesn't want nginx, let him use its own solution for HTTPS
printf "\n\nWe recommend let's encrypt to secure the application with HTTPS. You can use your own certificate or let this script install and configure let's encrypt for Fab-manager.\n"
printf "\n\nWe highly recommend to secure the application with HTTPS. You can use your own certificate or let this script install and configure let's encrypt for Fab-manager."
printf "\nIf this server is publicly available on the internet, you can use Let's encrypt to automatically generate and renew a valid SSL certificate for free.\n"
read -rp "Do you want install let's encrypt? (Y/n) " LETSENCRYPT </dev/tty
if [ "$LETSENCRYPT" != "n" ]; then
printf "\n\nLet's encrypt requires an email address to receive notifications about certificate expiration.\n"
read_email
fi
# if the user doesn't want nginx, let him configure his own solution
# if the user wants to install nginx, configure the domains
printf "\n\nWhat's the domain name where the instance will be active (eg. fab-manager.com)?\n"
read_domain
MAIN_DOMAIN=("${DOMAINS[0]}")
@ -162,6 +164,7 @@ prepare_nginx()
# if nginx is not installed, remove its associated block from docker-compose.yml
echo "Removing nginx..."
yq -i eval 'del(.services.nginx)' docker-compose.yml
printf "The two following configurations are useful if you want to install Fab-manager behind a reverse proxy...\n"
read -rp "Do you want to map the Fab-manager's service to an external network? (Y/n) " confirm </dev/tty
if [ "$confirm" != "n" ]; then
echo "Adding a network configuration to the docker-compose.yml file..."