From f49cf4d7f8054d87efa1e12055a7ef0c6d3b9872 Mon Sep 17 00:00:00 2001 From: staging new Date: Tue, 22 Jun 2021 10:35:47 +0200 Subject: [PATCH 1/2] add autodeploy bash scripts --- .../build_and_start_login_server.sh | 29 ++++++++++ deployment/bare_metal/build_frontend.sh | 13 +++++ deployment/bare_metal/update_all.sh | 54 +++++++++++++++++++ deployment/bare_metal/update_db_schemas.sh | 9 ++++ 4 files changed, 105 insertions(+) create mode 100755 deployment/bare_metal/build_and_start_login_server.sh create mode 100755 deployment/bare_metal/build_frontend.sh create mode 100755 deployment/bare_metal/update_all.sh create mode 100755 deployment/bare_metal/update_db_schemas.sh diff --git a/deployment/bare_metal/build_and_start_login_server.sh b/deployment/bare_metal/build_and_start_login_server.sh new file mode 100755 index 000000000..b97d1d4a9 --- /dev/null +++ b/deployment/bare_metal/build_and_start_login_server.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# stop login_server running in screen +screen -XS login quit + +# rebuild login-server +cd ../../login_server +if [ ! -d "./build" ] ; then + cd scripts + ./prepare_build.sh + cd .. +fi +cd build +cmake .. +make -j$(nproc) Gradido_LoginServer + +# rebuild locales +cd ../scripts +./compile_pot.sh +cd ../src/LOCALE +cp *.mo *.po /etc/grd_login/LOCALE/ + +cd ../../build/bin + +# start login-server +screen -dmS 'login_server' bash -c './Gradido_LoginServer' + + + diff --git a/deployment/bare_metal/build_frontend.sh b/deployment/bare_metal/build_frontend.sh new file mode 100755 index 000000000..bf6027fec --- /dev/null +++ b/deployment/bare_metal/build_frontend.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# For that to work, node v12.19.0 needs to be installed with nvm for root +# or NPM_BIN Path and NVM_DIR must be adjusted + +cd /var/www/html/gradido/frontend + +NPM_BIN=/root/.nvm/versions/node/v12.19.0/bin/npm + +export NVM_DIR="/root/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm + +$NPM_BIN install +$NPM_BIN run build diff --git a/deployment/bare_metal/update_all.sh b/deployment/bare_metal/update_all.sh new file mode 100755 index 000000000..1213ae146 --- /dev/null +++ b/deployment/bare_metal/update_all.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +EMPTY_UPDATE_HTML=/var/www/html/admin/updating_original.html +UPDATE_HTML=/var/www/html/admin/updating.html +LOCK_FILE=/root/relay.lock +#PROJECT_PATH=/var/www/html/gradido +PROJECT_PATH=/root/code/gradido +SITE_CONFIG=stage1 +UPDATE_SITE_CONFIG=stage1_updating + +# this script can be called for example from webhookrelay.com relay +# to auto-deploy automatic after a update to the master branch + +if [ -f $LOCK_FILE ] ; then + retVal="Already building!" + return "${retVal}" 2>/dev/null || exit "${retVal}" +fi + +touch $LOCK_FILE + +# start with nearly empty html +# needed a nearly empty html page in the folder +cp $EMPTY_UPDATE_HTML $UPDATE_HTML + +# let nginx showing a update page +# needed nginx site-configs in nginx folders +# gradido for running gradido servers +# gradido_updating for showing upddate.html idealy for all pathes +rm /etc/nginx/sites-enabled/$SITE_CONFIG +ln -s /etc/nginx/sites-available/$UPDATE_SITE_CONFIG /etc/nginx/sites-enabled/ +service nginx restart + +# stop login server +screen -XS login quit +echo 'starting with git pull
' >> $UPDATE_HTML +cd $PROJECT_PATH +# git checkout -f master +git pull +cd deployment/bare_metal +echo 'update schemas' >> $UPDATE_HTML +./update_db_schemas.sh +echo 'starting with rebuilding login-server
' >> $UPDATE_HTML +./build_and_start_login_server.sh +echo 'starting with rebuilding frontend
' >> $UPDATE_HTML +./build_frontend.sh + + +# let nginx showing gradido +rm /etc/nginx/sites-enabled/$UPDATE_SITE_CONFIG +ln -s /etc/nginx/sites-available/$SITE_CONFIG /etc/nginx/sites-enabled/ +service nginx restart + +rm $LOCK_FILE + diff --git a/deployment/bare_metal/update_db_schemas.sh b/deployment/bare_metal/update_db_schemas.sh new file mode 100755 index 000000000..48cba596b --- /dev/null +++ b/deployment/bare_metal/update_db_schemas.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# For that to work skeema needed to be installed on system +# in login_server/skeema and community_server/db/skeema skeema configuration files need to be there also in the subfolders +# Update DB Schemas (only the schemas, not the data) + +cd ../../login_server/skeema +skeema push --allow-unsafe +cd ../../community_server/db/skeema +skeema push --allow-unsafe From ac249b46830a8039aec52d30b48084b50a264b6f Mon Sep 17 00:00:00 2001 From: staging new Date: Tue, 22 Jun 2021 10:46:04 +0200 Subject: [PATCH 2/2] use standard path. add nginx example --- deployment/bare_metal/build_frontend.sh | 4 + .../bare_metal/nginx/sites-available/gradido | 73 +++++++++++++++++++ .../nginx/sites-available/gradido_updating | 29 ++++++++ .../bare_metal/nginx/updating_original.html | 1 + deployment/bare_metal/update_all.sh | 7 +- 5 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 deployment/bare_metal/nginx/sites-available/gradido create mode 100644 deployment/bare_metal/nginx/sites-available/gradido_updating create mode 100644 deployment/bare_metal/nginx/updating_original.html diff --git a/deployment/bare_metal/build_frontend.sh b/deployment/bare_metal/build_frontend.sh index bf6027fec..fc0feb747 100755 --- a/deployment/bare_metal/build_frontend.sh +++ b/deployment/bare_metal/build_frontend.sh @@ -11,3 +11,7 @@ export NVM_DIR="/root/.nvm" $NPM_BIN install $NPM_BIN run build +# prezip for faster deliver throw nginx +cd dist +find . -type f -name "*.css" -exec gzip -9 -k {} \; +find . -type f -name "*.js" -exec gzip -9 -k {} \; diff --git a/deployment/bare_metal/nginx/sites-available/gradido b/deployment/bare_metal/nginx/sites-available/gradido new file mode 100644 index 000000000..c32d82483 --- /dev/null +++ b/deployment/bare_metal/nginx/sites-available/gradido @@ -0,0 +1,73 @@ +server { + server_name _; + listen 80; + listen [::]:80; + + include /etc/nginx/common/protect.conf; + include /etc/nginx/common/protect_add_header.conf; + + root /var/www/html/gradido/community_server/webroot; + index index.php; + + gzip_static on; + + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass unix:/run/php/php7.4-fpm.sock; + } + + location ~ /\.ht { + deny all; + } + + location /vue { + alias /var/www/html/gradido/frontend/dist; + index index.html; + + location ~* \.(png)$ { + expires 39d; + } + try_files $uri $uri/ /index.html = 404; + } + + location /account { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Host $host; + rewrite /account/(.*) /$1 break; + + proxy_pass http://127.0.0.1:1200; + proxy_redirect off; + + + } + + location /login_api { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Host $host; + rewrite /login_api/(.*) /$1 break; + + proxy_pass http://127.0.0.1:1201; + proxy_redirect off; + + + } + + + location / { + try_files $uri $uri/ /index.php?$args; + } + + access_log /var/log/nginx/access.log main; + +} diff --git a/deployment/bare_metal/nginx/sites-available/gradido_updating b/deployment/bare_metal/nginx/sites-available/gradido_updating new file mode 100644 index 000000000..df07e3715 --- /dev/null +++ b/deployment/bare_metal/nginx/sites-available/gradido_updating @@ -0,0 +1,29 @@ + +server { + server_name _; + listen 80; + listen [::]:80; + + include /etc/nginx/common/protect.conf; + include /etc/nginx/common/protect_add_header.conf; + + root /var/www/html/; + index updating.html; + + location /account { + alias /var/www/html/; + index updating.html; + } + location /vue { + alias /var/www/html/; + index updating.html; + } + + location ~ /\.ht { + deny all; + } + + access_log /var/log/nginx/access.log main; + +} + diff --git a/deployment/bare_metal/nginx/updating_original.html b/deployment/bare_metal/nginx/updating_original.html new file mode 100644 index 000000000..8975e3970 --- /dev/null +++ b/deployment/bare_metal/nginx/updating_original.html @@ -0,0 +1 @@ +Gradido Servers are updating..., please stand by and try again in some minutes diff --git a/deployment/bare_metal/update_all.sh b/deployment/bare_metal/update_all.sh index 1213ae146..b065a16d4 100755 --- a/deployment/bare_metal/update_all.sh +++ b/deployment/bare_metal/update_all.sh @@ -1,10 +1,9 @@ #!/bin/bash -EMPTY_UPDATE_HTML=/var/www/html/admin/updating_original.html -UPDATE_HTML=/var/www/html/admin/updating.html +EMPTY_UPDATE_HTML=/var/www/html/updating_original.html +UPDATE_HTML=/var/www/html/updating.html LOCK_FILE=/root/relay.lock -#PROJECT_PATH=/var/www/html/gradido -PROJECT_PATH=/root/code/gradido +PROJECT_PATH=/var/www/html/gradido SITE_CONFIG=stage1 UPDATE_SITE_CONFIG=stage1_updating