From 113a486325c68daa23a378bab97715f2a06d8145 Mon Sep 17 00:00:00 2001 From: Md Shayon Date: Wed, 31 Jan 2024 01:36:23 +0600 Subject: [PATCH] Auto deploy with linux bash --- auto_deploy.sh | 49 +++++++++++++++++++++++++++++++++++++++ client/utils/keys.ts | 3 ++- deploy.sh | 1 - server/core/settings.py | 3 ++- server/gunicorn.service | 14 +++++++++++ server/gunicorn_config.py | 2 ++ server/requirements.txt | 1 + 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 auto_deploy.sh delete mode 100644 deploy.sh create mode 100644 server/gunicorn.service create mode 100644 server/gunicorn_config.py diff --git a/auto_deploy.sh b/auto_deploy.sh new file mode 100644 index 0000000..7a7d7c1 --- /dev/null +++ b/auto_deploy.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +echo "======================================================================================================" +echo "================================ Stop previous projects and delete it ================================" +echo "======================================================================================================" +cd +sudo systemctl stop gunicorn +rm -rf webdevlab +ls -la + +echo "======================================================================================================" +echo "================================ Clone repository from github ========================================" +echo "======================================================================================================" +git clone git@github.com:MdSamsuzzohaShayon/webdevlab.git +ls -la + + +echo "======================================================================================================" +echo "================================ Deploy Django =======================================================" +echo "======================================================================================================" +cd /home/shayon/webdevlab/server +python3 -m venv .venv +source .venv/bin/activate +echo "# Django Dot Environment" > .env +nano .env +nano core/settings.py +pip install -r requirements.txt +./manage.py makemigrations +./manage.py migrate +sudo systemctl daemon-reload +sudo systemctl restart gunicorn +# gunicorn core:application --check-config +deactivate +cd + +echo "======================================================================================================" +echo "================================ Deploy Nuxt.js ======================================================" +echo "======================================================================================================" +cd /home/shayon/webdevlab/client +echo "# Nuxt.js Dot Environment" > .env +nano .env +nano utils/keys.ts +npm install +npm run build +npm run generate +sudo rm -rf /var/www/html +sudo cp -r .output/public /var/www/html +cd +ls -la \ No newline at end of file diff --git a/client/utils/keys.ts b/client/utils/keys.ts index da8bb7c..bd9dffb 100644 --- a/client/utils/keys.ts +++ b/client/utils/keys.ts @@ -1 +1,2 @@ -export const FRONTEND_URL: string = 'http://localhost:3000' \ No newline at end of file +export const FRONTEND_URL: string = 'http://localhost:3000'; +// export const FRONTEND_URL: string = 'https://webdevlab.org'; \ No newline at end of file diff --git a/deploy.sh b/deploy.sh deleted file mode 100644 index cc1f786..0000000 --- a/deploy.sh +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash \ No newline at end of file diff --git a/server/core/settings.py b/server/core/settings.py index acb8587..b3a6307 100644 --- a/server/core/settings.py +++ b/server/core/settings.py @@ -40,7 +40,7 @@ DEBUG = False ALLOWED_HOSTS = [ - # 'http://localhost:3000', + 'localhost', ] @@ -99,6 +99,7 @@ CORS_ALLOWED_ORIGINS = [ 'http://localhost:3000', + os.environ["FRONTEND_URL"] ] WSGI_APPLICATION = 'core.wsgi.application' diff --git a/server/gunicorn.service b/server/gunicorn.service new file mode 100644 index 0000000..0683c16 --- /dev/null +++ b/server/gunicorn.service @@ -0,0 +1,14 @@ +# /etc/systemd/system/gunicorn.service +[Unit] +Description=gunicorn daemon for webdevlab +After=network.target + +[Service] +User=shayon +Group=shayon +WorkingDirectory=/home/shayon/webdevlab/server +ExecStart=/home/shayon/webdevlab/server/.venv/bin/gunicorn core.wsgi:application + + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/server/gunicorn_config.py b/server/gunicorn_config.py new file mode 100644 index 0000000..159cd80 --- /dev/null +++ b/server/gunicorn_config.py @@ -0,0 +1,2 @@ +bind = "0.0.0.0:8000" +workers = 3 \ No newline at end of file diff --git a/server/requirements.txt b/server/requirements.txt index ad7f5fb..4849ee7 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -19,3 +19,4 @@ sqlparse==0.4.4 text-unidecode==1.3 typing_extensions==4.9.0 urllib3==2.1.0 +gunicorn==21.2.0