-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Flagro/github_actions
github actions implementation
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |