Skip to content

Commit

Permalink
Merge pull request #79 from GTZ-STUDIO/setup-CD
Browse files Browse the repository at this point in the history
Merge setup-CD into develop
  • Loading branch information
Verzaccii committed Mar 13, 2024
2 parents 51b797f + 9efc94b commit 3c8c9f7
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 1 deletion.
89 changes: 89 additions & 0 deletions .github/workflows/AzureDeployBackend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions

name: Build and deploy Python app to Azure Web App - lvlupgg-backend

on:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.10'

- name: Create and start virtual environment
run: |
cd lvlgg_backend
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: |
cd backend
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Collect static files
run: |
cd backend
python manage.py collectstatic --noinput
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)

- name: Zip artifact for deployment
run: |
cd lvlgg_backend
zip release.zip ./* -r
- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v3
with:
name: python-app
path: |
release.zip
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
permissions:
id-token: write #This is required for requesting the JWT

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: python-app

- name: Unzip artifact for deployment
run: unzip release.zip


- name: Login to Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_D0EC002512024948BEDB0456F467333B }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_9D33C22D6BBE444D99A3A90F855A879F }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_DD88327B9EFA4CF1B3B7A3B7976C1BAB }}

- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'lvlupgg-backend'
slot-name: 'Production'

2 changes: 2 additions & 0 deletions lvlgg_backend/.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[config]
SCM_DO_BUILD_DURING_DEPLOYMENT=true
47 changes: 47 additions & 0 deletions lvlgg_backend/lvlgg_backend/deployment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
from .settings import*
from .settings import BASE_DIR

ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']]
CSRF_TRUSTED_ORIGINS = ['https://' + os.environ['WEBSITE_HOSTNAME']]
DEBUG = False
SECRET_KEY = os.environ['MY_SEECRET_KEY']

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleWare",
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

# CORS_ALLOWED_ORIGINS = ['http://localhost:3000'
# ]

STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage"
},
"staticfiles": {
"BACCKEND": "whitenoise.storage.CompressedStaticFileStorage"
}
}

CONNECTION = os.environ['AZURE_POSTGRESQL_CONNECTIONSTRING']
CONNECTION_STR = {pair.split('=')[0]:pair.split('=')[1] for pair in CONNECTION.split('')}

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": CONNECTION_STR['dbname'],
"HOST": CONNECTION_STR['host'],
"USER": CONNECTION_STR['user'],
"PASSWORD": CONNECTION_STR['password'],
}
}

STATIC_ROOT = BASE_DIR/'staticfiles'
2 changes: 1 addition & 1 deletion lvlgg_backend/lvlgg_backend/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os

from django.core.wsgi import get_wsgi_application

settings_module = 'lvlgg_backend.deployment' if 'WEBSITE_HOSTNAME' in os.environ else 'lvlgg_backend.settings'
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lvlgg_backend.settings')

application = get_wsgi_application()
1 change: 1 addition & 0 deletions lvlgg_backend/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

def main():
"""Run administrative tasks."""
settings_module = 'lvlgg_backend.deployment' if 'WEBSITE_HOSTNAME' in os.environ else 'lvlgg_backend.settings'
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lvlgg_backend.settings')
try:
from django.core.management import execute_from_command_line
Expand Down
Binary file modified lvlgg_backend/requirements.txt
Binary file not shown.

0 comments on commit 3c8c9f7

Please sign in to comment.