Merge branch 'infra' of github.com:pamelafox/django-quiz-app into infra
Browse files- .devcontainer/devcontainer.json +1 -1
- .vscode/launch.json +1 -1
- README.md +13 -17
- infra/main.bicep +11 -11
.devcontainer/devcontainer.json
CHANGED
@@ -37,7 +37,7 @@
|
|
37 |
"[python]": {
|
38 |
"editor.formatOnSave": true,
|
39 |
"editor.codeActionsOnSave": {
|
40 |
-
"source.fixAll":
|
41 |
},
|
42 |
"editor.defaultFormatter": "ms-python.black-formatter"
|
43 |
},
|
|
|
37 |
"[python]": {
|
38 |
"editor.formatOnSave": true,
|
39 |
"editor.codeActionsOnSave": {
|
40 |
+
"source.fixAll": "explicit"
|
41 |
},
|
42 |
"editor.defaultFormatter": "ms-python.black-formatter"
|
43 |
},
|
.vscode/launch.json
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
"configurations": [
|
7 |
{
|
8 |
"name": "Python: Django",
|
9 |
-
"type": "
|
10 |
"request": "launch",
|
11 |
"program": "${workspaceFolder}/src/manage.py",
|
12 |
"args": [
|
|
|
6 |
"configurations": [
|
7 |
{
|
8 |
"name": "Python: Django",
|
9 |
+
"type": "debugpy",
|
10 |
"request": "launch",
|
11 |
"program": "${workspaceFolder}/src/manage.py",
|
12 |
"args": [
|
README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
|
|
|
|
1 |
[](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=pamelafox%2Fdjango-quiz-app&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)
|
2 |
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com%2Fpamelafox%2Fdjango-quiz-app)
|
3 |
|
4 |
-
|
5 |
-
# Quizzes app
|
6 |
-
|
7 |
An example Django app that serves quizzes and lets people know how they scored. Quizzes and their questions are stored in a PostgreSQL database. There is no user authentication or per-user data stored.
|
8 |
|
9 |

|
@@ -36,18 +35,17 @@ If you're not using one of those options for opening the project, then you'll ne
|
|
36 |
|
37 |
## Local development
|
38 |
|
39 |
-
|
40 |
1. Create an `.env` file using `.env.sample` as a guide. Set the value of `DBNAME` to the name of an existing database in your local PostgreSQL instance. Set the values of `DBHOST`, `DBUSER`, and `DBPASS` as appropriate for your local PostgreSQL instance. If you're in the devcontainer, copy the values exactly from `.env.sample`.
|
41 |
|
42 |
2. Run the migrations: (Also available as a VS Code task)
|
43 |
|
44 |
-
```
|
45 |
python3 src/manage.py migrate
|
46 |
```
|
47 |
|
48 |
3. Run the local server at port 8000: (Also available as a VS Code task)
|
49 |
|
50 |
-
```
|
51 |
python3 src/manage.py runserver 8000
|
52 |
```
|
53 |
|
@@ -59,9 +57,9 @@ This app comes with the built-in Django admin interface.
|
|
59 |
|
60 |
1. Create a superuser:
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
|
66 |
2. Restart the server and navigate to "/admin"
|
67 |
|
@@ -71,7 +69,7 @@ This app comes with the built-in Django admin interface.
|
|
71 |
|
72 |
Run tests:
|
73 |
|
74 |
-
```
|
75 |
python3 src/manage.py collectstatic
|
76 |
coverage run --source='.' src/manage.py test quizzes
|
77 |
coverage report
|
@@ -79,7 +77,6 @@ coverage report
|
|
79 |
|
80 |
The same tests are also run as a Github action.
|
81 |
|
82 |
-
|
83 |
## Deployment
|
84 |
|
85 |
This repository is set up for deployment on Azure App Service (w/PostgreSQL flexible server) using the configuration files in the `infra` folder.
|
@@ -102,7 +99,7 @@ This repository is set up for deployment on Azure App Service (w/PostgreSQL flex
|
|
102 |
|
103 |
5. To be able to access `/admin`, you'll need a Django superuser. Navigate to the Azure Portal for the App Service, select SSH, and run this command:
|
104 |
|
105 |
-
```
|
106 |
python manage.py createsuperuser
|
107 |
```
|
108 |
|
@@ -141,15 +138,14 @@ Pricing varies per region and usage, so it isn't possible to predict exact costs
|
|
141 |
|
142 |
You can try the [Azure pricing calculator](https://azure.com/e/560b5f259111424daa7eb23c6848d164) for the resources:
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
|
149 |
⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use,
|
150 |
either by deleting the resource group in the Portal or running `azd down`.
|
151 |
|
152 |
-
|
153 |
## Getting help
|
154 |
|
155 |
If you're working with this project and running into issues, please post in **Discussions**.
|
|
|
1 |
+
# Django + PostgreSQL sample app
|
2 |
+
|
3 |
[](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=pamelafox%2Fdjango-quiz-app&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)
|
4 |
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com%2Fpamelafox%2Fdjango-quiz-app)
|
5 |
|
|
|
|
|
|
|
6 |
An example Django app that serves quizzes and lets people know how they scored. Quizzes and their questions are stored in a PostgreSQL database. There is no user authentication or per-user data stored.
|
7 |
|
8 |

|
|
|
35 |
|
36 |
## Local development
|
37 |
|
|
|
38 |
1. Create an `.env` file using `.env.sample` as a guide. Set the value of `DBNAME` to the name of an existing database in your local PostgreSQL instance. Set the values of `DBHOST`, `DBUSER`, and `DBPASS` as appropriate for your local PostgreSQL instance. If you're in the devcontainer, copy the values exactly from `.env.sample`.
|
39 |
|
40 |
2. Run the migrations: (Also available as a VS Code task)
|
41 |
|
42 |
+
```shell
|
43 |
python3 src/manage.py migrate
|
44 |
```
|
45 |
|
46 |
3. Run the local server at port 8000: (Also available as a VS Code task)
|
47 |
|
48 |
+
```shell
|
49 |
python3 src/manage.py runserver 8000
|
50 |
```
|
51 |
|
|
|
57 |
|
58 |
1. Create a superuser:
|
59 |
|
60 |
+
```shell
|
61 |
+
python3 src/manage.py createsuperuser
|
62 |
+
```
|
63 |
|
64 |
2. Restart the server and navigate to "/admin"
|
65 |
|
|
|
69 |
|
70 |
Run tests:
|
71 |
|
72 |
+
```shell
|
73 |
python3 src/manage.py collectstatic
|
74 |
coverage run --source='.' src/manage.py test quizzes
|
75 |
coverage report
|
|
|
77 |
|
78 |
The same tests are also run as a Github action.
|
79 |
|
|
|
80 |
## Deployment
|
81 |
|
82 |
This repository is set up for deployment on Azure App Service (w/PostgreSQL flexible server) using the configuration files in the `infra` folder.
|
|
|
99 |
|
100 |
5. To be able to access `/admin`, you'll need a Django superuser. Navigate to the Azure Portal for the App Service, select SSH, and run this command:
|
101 |
|
102 |
+
```shell
|
103 |
python manage.py createsuperuser
|
104 |
```
|
105 |
|
|
|
138 |
|
139 |
You can try the [Azure pricing calculator](https://azure.com/e/560b5f259111424daa7eb23c6848d164) for the resources:
|
140 |
|
141 |
+
* Azure App Service: Basic Tier with 1 CPU core, 1.75GB RAM. Pricing is hourly. [Pricing](https://azure.microsoft.com/pricing/details/app-service/linux/)
|
142 |
+
* PostgreSQL Flexible Server: Burstable Tier with 1 CPU core, 32GB storage. Pricing is hourly. [Pricing](https://azure.microsoft.com/pricing/details/postgresql/flexible-server/)
|
143 |
+
* Key Vault: Standard tier. Costs are per transaction, a few transactions are used on each deploy. [Pricing](https://azure.microsoft.com/pricing/details/key-vault/)
|
144 |
+
* Log analytics: Pay-as-you-go tier. Costs based on data ingested. [Pricing](https://azure.microsoft.com/pricing/details/monitor/)
|
145 |
|
146 |
⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use,
|
147 |
either by deleting the resource group in the Portal or running `azd down`.
|
148 |
|
|
|
149 |
## Getting help
|
150 |
|
151 |
If you're working with this project and running into issues, please post in **Discussions**.
|
infra/main.bicep
CHANGED
@@ -70,7 +70,7 @@ module postgresServer 'core/database/postgresql/flexibleserver.bicep' = {
|
|
70 |
entraAdministratorName: postgresEntraAdministratorName
|
71 |
entraAdministratorObjectId: postgresEntraAdministratorObjectId
|
72 |
entraAdministratorType: postgresEntraAdministratorType
|
73 |
-
databaseNames: [
|
74 |
allowAzureIPsFirewall: true
|
75 |
allowAllIPsFirewall: postgresAllowAllIPs
|
76 |
}
|
@@ -166,17 +166,17 @@ var secrets = [
|
|
166 |
]
|
167 |
|
168 |
@batchSize(1)
|
169 |
-
module keyVaultSecrets './core/security/keyvault-secret.bicep' = [
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
|
|
|
|
176 |
}
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
|
181 |
module logAnalyticsWorkspace 'core/monitor/loganalytics.bicep' = {
|
182 |
name: 'loganalytics'
|
|
|
70 |
entraAdministratorName: postgresEntraAdministratorName
|
71 |
entraAdministratorObjectId: postgresEntraAdministratorObjectId
|
72 |
entraAdministratorType: postgresEntraAdministratorType
|
73 |
+
databaseNames: [postgresDatabaseName]
|
74 |
allowAzureIPsFirewall: true
|
75 |
allowAllIPsFirewall: postgresAllowAllIPs
|
76 |
}
|
|
|
166 |
]
|
167 |
|
168 |
@batchSize(1)
|
169 |
+
module keyVaultSecrets './core/security/keyvault-secret.bicep' = [
|
170 |
+
for secret in secrets: {
|
171 |
+
name: 'keyvault-secret-${secret.name}'
|
172 |
+
scope: resourceGroup
|
173 |
+
params: {
|
174 |
+
keyVaultName: keyVault.outputs.name
|
175 |
+
name: secret.name
|
176 |
+
secretValue: secret.value
|
177 |
+
}
|
178 |
}
|
179 |
+
]
|
|
|
|
|
180 |
|
181 |
module logAnalyticsWorkspace 'core/monitor/loganalytics.bicep' = {
|
182 |
name: 'loganalytics'
|