Skip to content

Instantly share code, notes, and snippets.

@jaishirb
Forked from osw4l/commands.sh
Created April 29, 2020 02:14
Show Gist options
  • Save jaishirb/1ac7a73ee088fc8be1c5511ee10446f7 to your computer and use it in GitHub Desktop.
Save jaishirb/1ac7a73ee088fc8be1c5511ee10446f7 to your computer and use it in GitHub Desktop.
deploy django-osw4l 2020
sudo su -
# update so
sudo apt update
sudo apt upgrade
# install curl
sudo apt install curl
#install docker-compose via curl
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# install docker-compose via apt-get
sudo apt-get install docker-compose
# check docker compose version
docker–compose –version
# install nginx
sudo apt install nginx
git clone repo
cd repo
# create environment file and updateit
cp .env_template .env
# edit with nano and change DJANGO_PRODUCTION from false to true
# then press ctrl + o to save and ctrl + x to exit
nano .env
# build image
docker-compose build
# up image
docker-compose up -d
# create migrations
docker-compose exec backend python3 manage.py migrate
# restart celery beat
docker-compose restart beat
# create superuser
docker-compose exec backend python3 manage.py createsuperuser
# collect statics, run this to go inisde the backend container
docker-compose run -u root backend bash
# run this when you're inside, and then press ctrl + d to get back
python3 manage.py collectstatic --noinput
# go to nginx
cd /etc/nginx/sites-enabled
# remove old default file
rm default
# create new config file
touch mysite
# update with nano, copy all the content of nginx.conf inside, then save it press
# press ctrl + o to save changes and ctrl + x to exit
nano mysite
# restart nginx
services nginx restart
# go to mysite.com and enjoy it ;)
# if you want add ssl, just follow the next instructions
# You'll need to add the Certbot PPA to your list of repositories.
# To do so, run the following commands on the command line on the machine:
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
# Install Certbot
sudo apt-get install certbot python-certbot-nginx
# Install Certbot
sudo apt-get install certbot python-certbot-nginx
# Run this command to get a certificate and have Certbot edit your Nginx
# configuration automatically to serve it, turning on HTTPS access in a single step.
sudo certbot --nginx
# restart nginx, again
services nginx restart
# go to agan mysite.com , now it have ssl and enjoy it agai ;)
server {
server_name mysite.com;
location / {
proxy_pass http://localhost:3002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_cache_bypass $http_upgrade;
}
location /static {
rewrite (.*) $1 break;
proxy_pass http://127.0.0.1:3002;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment