-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
175 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Deploy on push to test ACA branch | ||
|
||
on: | ||
push: | ||
branches: | ||
- mbarton/azure-container-apps | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout GitHub Action' | ||
uses: actions/checkout@main | ||
|
||
- name: 'Login via Azure CLI' | ||
uses: azure/login@v2 | ||
with: | ||
client-id: ${{ secrets.AZURE_CLIENT_ID }} | ||
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
|
||
- name: 'Run CI script' | ||
env: | ||
AZURE_REGISTRY_NAME: ${{ secrets.AZURE_REGISTRY_NAME }} | ||
AZURE_CONFIG_STORAGE_ACCOUNT: ${{ secrets.AZURE_CONFIG_STORAGE_ACCOUNT }} | ||
AZURE_CONFIG_FILE_SHARE: ${{ secrets.AZURE_CONFIG_FILE_SHARE }} | ||
AZURE_STAGING_APP_NAME: ${{ secrets.AZURE_STAGING_APP_NAME }} | ||
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }} | ||
run: s/ci |
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
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 |
---|---|---|
@@ -1,10 +1,30 @@ | ||
import threading | ||
|
||
from django.apps import AppConfig | ||
|
||
from .management.commands.write_azure_pg_password_file import write_azure_pg_password_file | ||
|
||
def periodically_update_azure_pg_password_file(): | ||
update_interval = 60 * 15 # 15 minutes | ||
|
||
def _periodically_update_azure_pg_password_file(): | ||
write_azure_pg_password_file() | ||
|
||
thread = threading.Timer(update_interval, _periodically_update_azure_pg_password_file) | ||
thread.daemon = True | ||
thread.start() | ||
|
||
thread = threading.Timer(update_interval, _periodically_update_azure_pg_password_file) | ||
thread.daemon = True | ||
thread.start() | ||
|
||
class Epilepsy12Config(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'epilepsy12' | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "epilepsy12" | ||
|
||
def ready(self) -> None: | ||
import epilepsy12.signals | ||
|
||
periodically_update_azure_pg_password_file() | ||
|
||
return super().ready() |
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,32 @@ | ||
import os | ||
import json | ||
import subprocess | ||
import logging | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
_build_info = None | ||
|
||
def get_build_info_from_dot_git_folder(): | ||
try: | ||
result = subprocess.run('s/get-build-info', stdout = subprocess.PIPE) | ||
return json.loads(result.stdout) | ||
except: | ||
logger.exception("Error getting git data from repository") | ||
return { | ||
"active_git_branch": "[branch name not found]", | ||
"latest_git_commit": "[latest commit hash not found]", | ||
} | ||
|
||
def get_build_info(request=None): | ||
global _build_info | ||
|
||
if not _build_info: | ||
try: | ||
with open("build_info.json", "r") as f: | ||
_build_info = json.load(f) | ||
except: | ||
# Running in dev | ||
_build_info = get_build_info_from_dot_git_folder() | ||
|
||
return _build_info |
This file was deleted.
Oops, something went wrong.
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
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,34 @@ | ||
#!/bin/bash -e | ||
|
||
az acr login --name ${AZURE_REGISTRY_NAME} | ||
|
||
# Download .env file (--query avoids outputting all the info about the blob in our public logs) | ||
az storage file download \ | ||
--auth-mode login \ | ||
--enable-file-backup-request-intent \ | ||
--account-name ${AZURE_CONFIG_STORAGE_ACCOUNT} \ | ||
--share-name ${AZURE_CONFIG_FILE_SHARE} \ | ||
--query 'size' \ | ||
--path .env --dest envs/.env | ||
|
||
# Burn in build info (git hash, branch etc) into the image | ||
s/get-build-info > build_info.json | ||
|
||
docker compose build | ||
|
||
# Tests (against local Postgres) | ||
docker compose up -d | ||
s/test | ||
docker compose down | ||
|
||
# Push to Azure | ||
azure_tag="${AZURE_REGISTRY_NAME}.azurecr.io/e12-django:${GITHUB_SHA}" | ||
docker tag e12-django:built ${azure_tag} | ||
docker push ${azure_tag} | ||
|
||
# Deploy to Azure Container Apps | ||
az containerapp revision copy \ | ||
--name ${AZURE_STAGING_APP_NAME} \ | ||
--resource-group ${AZURE_RESOURCE_GROUP} \ | ||
--image ${azure_tag} \ | ||
--query 'properties.provisioningState' |
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,10 @@ | ||
#!/bin/bash | ||
|
||
git_hash=$(git rev-parse HEAD) | ||
branch_name=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
if [[ "${git_hash}" == 'HEAD' ]]; then | ||
git_hash='unknown' | ||
fi | ||
|
||
echo "{\"latest_git_commit\":\"${git_hash}\",\"active_git_branch\":\"${branch_name}\"}" |
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,6 @@ | ||
#!/bin/bash -e | ||
|
||
python manage.py collectstatic --noinput | ||
python manage.py migrate | ||
python manage.py seed --mode=seed_groups_and_permissions | ||
python manage.py runserver 0.0.0.0:8000 |
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,12 @@ | ||
#!/bin/bash -e | ||
|
||
python manage.py write_azure_pg_password_file | ||
python manage.py migrate | ||
python manage.py seed --mode=seed_groups_and_permissions | ||
|
||
gunicorn \ | ||
--bind=0.0.0.0:8000 \ | ||
--timeout 600 \ | ||
--access-logfile '-' \ | ||
--access-logformat '%({x-forwarded-for}i)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' \ | ||
rcpch-audit-engine.wsgi |