Skip to content

Commit

Permalink
Merge pull request #7 from Flagro/github_actions
Browse files Browse the repository at this point in the history
github actions implementation
  • Loading branch information
Flagro authored Nov 15, 2023
2 parents f51bf5b + e52ec2b commit bc85562
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ DB_USER=postgres
DB_PASSWORD=your-password
DB_HOST=db # This is the service name defined in docker-compose.yml
DB_PORT=5432
ADMIN_USERNAME=admin
ADMIN_EMAIL=email@domain.com
ADMIN_PASSWORD=admin_password
41 changes: 41 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Deploy with Docker on VPS

on:
push:
branches: [ main ]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Deploy to VPS
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
port: 22
script: |
if [ -d "~/PhriniFluentBackend" ]; then
cd ~/PhriniFluentBackend
git pull origin main
else
git clone https://github.com/Flagro/PhriniFluentBackend.git ~/PhriniFluentBackend
cd ~/PhriniFluentBackend
fi
cp .env-example .env
echo "ENVIRONMENT=deployment" >> .env
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "ADMIN_USERNAME=${{ secrets.ADMIN_USERNAME }}" >> .env
echo "ADMIN_EMAIL=${{ secrets.ADMIN_EMAIL }}" >> .env
echo "ADMIN_PASSWORD=${{ secrets.ADMIN_PASSWORD }}" >> .env
sudo ../limited-docker-compose.sh -f docker-compose.prod.yml build
sudo ../limited-docker-compose.sh -f docker-compose.prod.yml up -d
sudo ../limited-docker-compose.sh -f docker-compose.prod.yml exec web python manage.py migrate
sudo ../limited-docker-compose.sh -f docker-compose.prod.yml exec web python manage.py collectstatic --noinput
sudo ../limited-docker-compose.sh -f docker-compose.prod.yml exec web python manage.py createadmin
5 changes: 5 additions & 0 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,8 @@
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CORS_ALLOW_ALL_ORIGINS = True

# Admin user
ADMIN_USERNAME = config('ADMIN_USERNAME')
ADMIN_EMAIL = config('ADMIN_EMAIL')
ADMIN_PASSWORD = config('ADMIN_PASSWORD')
22 changes: 22 additions & 0 deletions phrini_fluent_users/management/commands/createadmin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
from django.conf import settings

class Command(BaseCommand):
help = 'Creates an admin user if it does not exist'

def handle(self, *args, **options):
User = get_user_model()
admin_username = settings.ADMIN_USERNAME
admin_email = settings.ADMIN_EMAIL
admin_password = settings.ADMIN_PASSWORD

if not User.objects.filter(username=admin_username).exists():
User.objects.create_superuser(
username=admin_username,
email=admin_email,
password=admin_password
)
self.stdout.write(self.style.SUCCESS('Successfully created new admin user'))
else:
self.stdout.write(self.style.SUCCESS('Admin user already exists'))

0 comments on commit bc85562

Please sign in to comment.