Pamela Fox commited on
Commit
eb6044e
·
unverified ·
2 Parent(s): 168de98 c563c63

Merge pull request #8 from pamelafox/improvements

Browse files
.devcontainer/devcontainer.json CHANGED
@@ -30,22 +30,15 @@
30
  ],
31
  "python.defaultInterpreterPath": "/usr/local/bin/python",
32
  "python.linting.enabled": true,
33
- "python.linting.pylintEnabled": true,
34
- "python.linting.pylintArgs": [
35
- "--disable=C0114,C0115,C0116"
36
- ],
37
- "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
38
- "python.formatting.blackPath": "/usr/local/py-utils/bin/black",
39
- "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
40
- "python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
41
- "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
42
- "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
43
- "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
44
- "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
45
- "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
46
  "python.testing.unittestEnabled": false,
47
  "python.testing.pytestEnabled": true,
48
- "workbench.startupEditor": "newUntitledFile"
 
 
 
 
 
 
49
  },
50
 
51
  // Add the IDs of extensions you want installed when the container is created.
@@ -53,6 +46,7 @@
53
  "ms-azuretools.azure-dev",
54
  "ms-python.python",
55
  "ms-python.vscode-pylance",
 
56
  "ms-azuretools.vscode-bicep",
57
  "mtxr.sqltools",
58
  "mtxr.sqltools-driver-pg"
 
30
  ],
31
  "python.defaultInterpreterPath": "/usr/local/bin/python",
32
  "python.linting.enabled": true,
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  "python.testing.unittestEnabled": false,
34
  "python.testing.pytestEnabled": true,
35
+ "[python]": {
36
+ "editor.formatOnSave": true,
37
+ "editor.codeActionsOnSave": {
38
+ "source.fixAll": true
39
+ }
40
+ },
41
+ "python.formatting.provider": "black"
42
  },
43
 
44
  // Add the IDs of extensions you want installed when the container is created.
 
46
  "ms-azuretools.azure-dev",
47
  "ms-python.python",
48
  "ms-python.vscode-pylance",
49
+ "charliermarsh.ruff",
50
  "ms-azuretools.vscode-bicep",
51
  "mtxr.sqltools",
52
  "mtxr.sqltools-driver-pg"
.env.sample CHANGED
@@ -2,3 +2,4 @@ DBHOST=localhost
2
  DBNAME=app
3
  DBUSER=app_user
4
  DBPASS=app_password
 
 
2
  DBNAME=app
3
  DBUSER=app_user
4
  DBPASS=app_password
5
+ SECRET_KEY=
.github/workflows/check.yaml CHANGED
@@ -6,7 +6,7 @@ jobs:
6
  runs-on: ubuntu-latest
7
  services:
8
  postgres:
9
- image: postgres:11
10
  env:
11
  POSTGRES_PASSWORD: postgres
12
  ports:
@@ -38,6 +38,7 @@ jobs:
38
  DBNAME: postgres
39
  DBUSER: postgres
40
  DBPASS: postgres
 
41
  run: |
42
  python manage.py collectstatic
43
  coverage run --source='.' manage.py test quizzes
 
6
  runs-on: ubuntu-latest
7
  services:
8
  postgres:
9
+ image: postgres:13
10
  env:
11
  POSTGRES_PASSWORD: postgres
12
  ports:
 
38
  DBNAME: postgres
39
  DBUSER: postgres
40
  DBPASS: postgres
41
+ SECRET_KEY: django-insecure-key-${{ github.run_id }}-${{ github.run_attempt }}
42
  run: |
43
  python manage.py collectstatic
44
  coverage run --source='.' manage.py test quizzes
README.md CHANGED
@@ -15,23 +15,29 @@ then it's best to first [create a Python virtual environment](https://docs.pytho
15
 
16
  1. Install the requirements:
17
 
18
- ```shell
19
- python3 -m pip install -r requirements-dev.txt
20
- ```
21
 
22
  2. 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`.
23
 
 
 
 
 
 
 
24
  3. Run the migrations:
25
 
26
- ```
27
- python3 manage.py migrate
28
- ```
29
 
30
  4. Run the local server:
31
 
32
- ```
33
- python3 manage.py runserver
34
- ```
35
 
36
  5. Navigate to "/quizzes" (since no "/" route is defined) to verify server is working.
37
 
@@ -79,3 +85,32 @@ azd up
79
  ```
80
  python manage.py createsuperuser
81
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  1. Install the requirements:
17
 
18
+ ```shell
19
+ python3 -m pip install -r requirements-dev.txt
20
+ ```
21
 
22
  2. 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`.
23
 
24
+ 3. Fill in a secret value for `SECRET_KEY`. You can use this command to generate an appropriate value.
25
+
26
+ ```shell
27
+ python -c 'import secrets; print(secrets.token_hex())'
28
+ ```
29
+
30
  3. Run the migrations:
31
 
32
+ ```
33
+ python3 manage.py migrate
34
+ ```
35
 
36
  4. Run the local server:
37
 
38
+ ```
39
+ python3 manage.py runserver
40
+ ```
41
 
42
  5. Navigate to "/quizzes" (since no "/" route is defined) to verify server is working.
43
 
 
85
  ```
86
  python manage.py createsuperuser
87
  ```
88
+
89
+ ## CI/CD pipeline
90
+
91
+ This project includes a Github workflow for deploying the resources to Azure
92
+ on every push to main. That workflow requires several Azure-related authentication secrets
93
+ to be stored as Github action secrets. To set that up, run:
94
+
95
+ ```shell
96
+ azd pipeline config
97
+ ```
98
+
99
+ ### Costs
100
+
101
+ Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage.
102
+
103
+ You can try the Azure pricing calculator for the resources:
104
+
105
+ - 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/)
106
+ - PostgreSQL Flexible Server: Burstable Tier with 1 CPU core, 32GB storage. Pricing is hourly. [Pricing](https://azure.microsoft.com/pricing/details/postgresql/flexible-server/)
107
+ - Virtual Network: Pricing based on data transfer. [Pricing](https://azure.microsoft.com/en-us/pricing/details/virtual-network/)
108
+ - Private DNS Zone: Pricing based on number of zones per region per month. [Pricing](https://azure.microsoft.com/en-in/pricing/details/dns/)
109
+ - Log analytics: Pay-as-you-go tier. Costs based on data ingested. [Pricing](https://azure.microsoft.com/pricing/details/monitor/)
110
+
111
+ ⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use,
112
+ either by deleting the resource group in the Portal or running `azd down`.
113
+
114
+ ## Getting help
115
+
116
+ If you're working with this project and running into issues, please post in **Discussions**.
quizsite/settings.py CHANGED
@@ -22,7 +22,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
22
  # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
23
 
24
  # SECURITY WARNING: keep the secret key used in production secret!
25
- SECRET_KEY = "django-insecure-dfln3fbd4mq*jof)t5($@tlgn98z^a)ar7aw^py7s(j#w^x01q"
26
 
27
  # SECURITY WARNING: don't run with debug turned on in production!
28
  DEBUG = True
 
22
  # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
23
 
24
  # SECURITY WARNING: keep the secret key used in production secret!
25
+ SECRET_KEY = os.getenv("SECRET_KEY")
26
 
27
  # SECURITY WARNING: don't run with debug turned on in production!
28
  DEBUG = True