Skip to content

Commit 0e9a7e0

Browse files
authored
ci/cd prepare
1 parent 11eee99 commit 0e9a7e0

2 files changed

Lines changed: 99 additions & 7 deletions

File tree

.github/workflows/prod_codejam.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions
4+
5+
name: Build and deploy Python app to Azure Web App - codejam
6+
7+
on:
8+
push:
9+
branches:
10+
- prod
11+
workflow_dispatch:
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read #This is required for actions/checkout
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python version
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.12'
26+
27+
- name: Create and start virtual environment
28+
run: |
29+
python -m venv venv
30+
source venv/bin/activate
31+
32+
- name: Install dependencies
33+
run: pip install -r requirements.txt
34+
35+
- name: Collecting Static Files
36+
run: python manage.py collectstatic
37+
38+
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
39+
40+
- name: Zip artifact for deployment
41+
run: zip release.zip ./* -r
42+
43+
- name: Upload artifact for deployment jobs
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: python-app
47+
path: |
48+
release.zip
49+
!venv/
50+
51+
deploy:
52+
runs-on: ubuntu-latest
53+
needs: build
54+
environment:
55+
name: 'Production'
56+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
57+
permissions:
58+
id-token: write #This is required for requesting the JWT
59+
contents: read #This is required for actions/checkout
60+
61+
steps:
62+
- name: Download artifact from build job
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: python-app
66+
67+
- name: Unzip artifact for deployment
68+
run: unzip release.zip
69+
70+
71+
- name: Login to Azure
72+
uses: azure/login@v2
73+
with:
74+
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_A1461F18A7404A3CBAB83496FA9FBF54 }}
75+
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_FE4FF5F0DF1C4FDBA2B05ED3985C4E88 }}
76+
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_611DAA6BB9FE4E498D5999B897745E1B }}
77+
78+
- name: 'Deploy to Azure Web App'
79+
uses: azure/webapps-deploy@v3
80+
id: deploy-to-webapp
81+
with:
82+
app-name: 'codejam'
83+
slot-name: 'Production'
84+

CodeJammers/settings.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
For the full list of settings and their values, see
1010
https://docs.djangoproject.com/en/3.2/ref/settings/
1111
"""
12-
12+
import os
1313
from pathlib import Path
1414

1515
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@@ -23,9 +23,10 @@
2323
SECRET_KEY = "django-insecure-_6u#7#ymw$!=d17pf*p%#_r7yt7fv@d0&xx@5%z(vr4@7@f@2w"
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
26+
DEBUG = False
2727

28-
ALLOWED_HOSTS = []
28+
ALLOWED_HOSTS = ['*']
29+
CSRF_TRUSTED_ORIGINS = ['http://*', 'https://*.azurewebsites.net']
2930

3031

3132
# Application definition
@@ -48,6 +49,7 @@
4849
"django.contrib.auth.middleware.AuthenticationMiddleware",
4950
"django.contrib.messages.middleware.MessageMiddleware",
5051
"django.middleware.clickjacking.XFrameOptionsMiddleware",
52+
'whitenoise.middleware.WhiteNoiseMiddleware',
5153
]
5254

5355
ROOT_URLCONF = "CodeJammers.urls"
@@ -75,9 +77,13 @@
7577
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
7678

7779
DATABASES = {
78-
"default": {
79-
"ENGINE": "django.db.backends.sqlite3",
80-
"NAME": str(BASE_DIR / "db.sqlite3"),
80+
'default': {
81+
'ENGINE': 'django.db.backends.postgresql',
82+
'NAME': 'railway',
83+
'USER': 'postgres',
84+
'PASSWORD': os.getenv('postgrespwd'),
85+
'HOST': 'shuttle.proxy.rlwy.net',
86+
'PORT': '50602',
8187
}
8288
}
8389

@@ -118,4 +124,6 @@
118124
# Static files (CSS, JavaScript, Images)
119125
# https://docs.djangoproject.com/en/3.2/howto/static-files/
120126

121-
STATIC_URL = "/static/"
127+
STATIC_URL = "/static/"
128+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
129+
STATIC_ROOT = BASE_DIR / 'staticfiles'

0 commit comments

Comments
 (0)