EasyDeployer steps

Source code is available at this url:



  • Pulling git latest commits.
#!/bin/bashecho $'\n-----Updating git local branch-----\n'
cd ../../
git reset --hard
echo $'pulling from git...'
git pull
echo $'\n-----Done-----\n'
cd Runner/scripts
  • Updating apt-get and install dependencies.
#!/bin/bashcd ../../echo $'\n-----Updating local packages-----\n'
sudo apt-get update
echo $'\n-----Installing dependencies-----\n'
sudo apt-get install python3-pip python3-dev nginx
echo $'\n-----Done-----\n'
cd Runner/scripts
  • Creating Virtualenv and activate.
#!/usr/bin/env bashset -eecho $'\n-----Initiating Venv-----\n'
cd ../../
if [ -d venv/ ];
echo $'\n-----Removing existing venv directory-----\n';
sudo rm -Rf ../../venv;
echo $'\n-----Creating venv-----\n'
python3 -m venv venv
source venv/bin/activate
echo $'\n-----Activating venv-----\n'
echo $'\n-----Done-----\n'
cd Runner/scripts
  • Installing flask, gunicorn project requirements from requirements.txt .
#!/bin/bashecho $'\n-----Installing Gunicorn-----\n'
cd ../../
pip3 install gunicorn flaskecho $'\n-----Installing requirements.txt-----\n'
pip3 install -r requirements.txt
echo $'\n-----Done-----\n'
cd Runner/scripts
  • Closing all processes on port 5000 and binding gunicorn and deactivate venv.
#!/usr/bin/env bashset -e
echo $'\n-----Binding local to gunicorn-----\n'
cd ../../
sudo fuser -k 5000/tcp
gunicorn --bind wsgi:app &
echo $'\n-----Deactivating venv-----\n'deactivateecho $'\n-----Done-----\n'
cd Runner/scripts
  • Setting up app.service and creating app.sock into your project.
#!/bin/bashecho $'\n-----Creating systemd unit file-----\n'
cd ../../
if [ /etc/systemd/system/app.service ];
echo $'\n-----Removing existing app.service-----\n';
sudo rm /etc/systemd/system/app.service;
echo $'\n-----Creating app.service-----\n'var_username=$USERecho "Created gunicorn with $1 worker processes to start"
systemd_content=$'[Unit]\n# specifies metadata and dependencies\nDescription=Gunicorn instance to serve project\nAfter=network.target\n# tells the init system to only start this after the networking target has been reached\n# We will give our regular user account ownership of the process since it owns all of the relevant files\n[Service]\n# Service specify the user and group under which our process will run.\nUser='$var_username$'\n# give group ownership to the www-data group so that Nginx can communicate easily with the Gunicorn processes.\nGroup=www-data\n# Well then map out the working directory and set the PATH environmental variable so that the init system knows where our the executables for the process are located (within our virtual environment).\nWorkingDirectory='$DIR$'\nEnvironment="PATH='$DIR$'/venv/bin"\n# Well then specify the commanded to start the service\nExecStart='$DIR$'/venv/bin/gunicorn --workers '$var_workers$' --bind unix:app.sock -m 007 wsgi:app\n# This will tell systemd what to link this service to if we enable it to start at boot. We want this service to start when the regular multi-user system is up and running:\n[Install]\nWantedBy=multi-user.target'
echo "$systemd_content" > $systemd_path
systemctl daemon-reload
echo $'\n-----Starting app-----\n'
sudo systemctl start app
sudo systemctl enable app
echo $'\n-----Done-----\n'
cd Runner/scripts
  • Creating Nginx files with server_ip and config the sites-available with sites-enabled and linking them togather.
#!/bin/bashcd ../../if [ /etc/nginx/sites-available/app ];
echo $'\n-----Removing existing nginx app-----\n';
sudo rm /etc/nginx/sites-available/app;
sudo rm /etc/nginx/sites-enabled/app;
systemctl daemon-reload
echo $'\n-----Creating nginx configuration-----\n';
echo "setting $1 as server domain"
config=$'server {\n\tlisten 80;\n\tserver_name '$var_server_ip$';\n\nlocation / {\n\tinclude proxy_params;\n\tproxy_pass http://unix:'$DIR$'/app.sock;\n\t}\n}\n'
echo $'\n-----Creating nginx sites-available-----\n';
echo "$config" > $nginx_path
echo $'\n-----Linking nginx server-----\n';
sudo ln -s $nginx_path /etc/nginx/sites-enabled
echo $'\n-----Testing nginx server-----\n';
sudo nginx -t
echo $'\n-----Restarting nginx server-----\n';
sudo systemctl restart nginx
echo $'\n-----Adjusting firewall to allow access to nginx server-----\n';
sudo ufw allow 'Nginx Full'
echo $'\n-----Done-----\n';
cd Runner/scripts
  • Creating a bash to pass arguments to the specific bash file.
#!/bin/bashecho $'\n-----Welcome to the EasyDeployer-----\n'cd scripts
source git_reset_and_pull.sh
source install_apt_tools.sh
source init_venv.sh
source install_requirements.sh
source setup_gunicorn.sh
source setup_systemd.sh $2
source config_nginx.sh $1
echo $'\n-----Deployment Completed-----\n'

Bashes directory:



$ cd Runner/
$ source execute.sh example.com 3



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store