You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This `.devcontainer` directory contains the configuration for a [dev container](https://docs.github.com/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers) and isn't used by the sample application.
4
+
5
+
The dev container configuration lets you open the repository in a [GitHub codespace](https://docs.github.com/codespaces/overview) or a dev container in Visual Studio Code. For your convenience, the dev container is configured with the following:
6
+
7
+
- Python
8
+
- PostgreSQL
9
+
-[Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) (so you can run `azd` commands directly).
Copy file name to clipboardExpand all lines: README.md
+22-50Lines changed: 22 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,70 +2,61 @@
2
2
3
3
This is a Python web app using the Django framework and the Azure Database for PostgreSQL relational database service. The Django app is hosted in a fully managed Azure App Service. This app is designed to be be run locally and then deployed to Azure. You can either deploy this project by following the tutorial [*Deploy a Python (Django or Flask) web app with PostgreSQL in Azure*](https://docs.microsoft.com/azure/app-service/tutorial-python-postgresql-app) or by using the [Azure Developer CLI (azd)](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) according to the instructions below.
4
4
5
+
Additionally, the sample application demonstrates Azure Redis Cache access by caching the restaurant details page for 60 seconds. You can add the Azure Redis Cache integration in the [secure-by-default web app + database creation wizard](https://portal.azure.com/?feature.customportal=false#create/Microsoft.AppServiceWebAppDatabaseV3), and it's also included in the [AZD template](https://github.com/Azure-Samples/python-app-service-postgresql-infra).
6
+
5
7
## Requirements
6
8
7
-
The [requirements.txt](./requirements.txt) has the following packages:
9
+
The [requirements.txt](./requirements.txt) has the following packages, all used by a typical data-driven Django application:
8
10
9
11
| Package | Description |
10
12
| ------- | ----------- |
11
13
|[Django](https://pypi.org/project/Django/)| Web application framework. |
12
14
|[pyscopg2-binary](https://pypi.org/project/psycopg-binary/)| PostgreSQL database adapter for Python. |
13
15
|[python-dotenv](https://pypi.org/project/python-dotenv/)| Read key-value pairs from .env file and set them as environment variables. In this sample app, those variables describe how to connect to the database locally. <br><br> This package is used in the [manage.py](./manage.py) file to load environment variables. |
14
16
|[whitenoise](https://pypi.org/project/whitenoise/)| Static file serving for WSGI applications, used in the deployed app. <br><br> This package is used in the [azureproject/production.py](./azureproject/production.py) file, which configures production settings. |
17
+
|[django-redis](https://pypi.org/project/django-redis/)| Redis cache backend for Django. |
15
18
16
-
## Using this project with the Azure Developer CLI (azd)
19
+
## Run the sample
17
20
18
-
This project is designed to work well with the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview),
19
-
which makes it easier to develop apps locally, deploy them to Azure, and monitor them.
21
+
This project has a [dev container configuration](.devcontainer/), which makes it easier to develop apps locally, deploy them to Azure, and monitor them. The easiest way to run this sample application is inside a GitHub codespace. Follow these steps:
20
22
21
-
### Local development
23
+
1. Fork this repository to your account. For instructions, see [Fork a repo](https://docs.github.com/get-started/quickstart/fork-a-repo).
22
24
23
-
This project has Dev Container support, so you can open it in Github Codespaces or local VS Code with the Dev Containers extension. If you're unable to open the Dev Container,
24
-
then it's best to first [create a Python virtual environment](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and activate that.
25
+
1. From the repository root of your fork, select **Code** > **Codespaces** > **+**.
25
26
26
-
1.Install the requirements:
27
+
1.In the codespace terminal, run the following commands:
27
28
28
29
```shell
30
+
# Install requirements
29
31
python3 -m pip install -r requirements.txt
30
-
```
31
-
32
-
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 foryour local PostgreSQL instance. If you'rein the Dev Container, copy the values from `.env.sample.devcontainer`.
33
-
34
-
3. In the `.env` file, fill in a secret value for`SECRET_KEY`. You can use this command to generate an appropriate value:
4. Run the migrations: (or use VS Code "Run" button and select"Migrate")
41
-
42
-
```shell
32
+
# Create .env with environment variables
33
+
cp .env.sample.devcontainer .env
34
+
# Run database migrations
43
35
python3 manage.py migrate
44
-
```
45
-
46
-
5. Run the local server: (or use VS Code "Run" button and select"Run server")
47
-
48
-
```shell
36
+
# Start the development server
49
37
python3 manage.py runserver
50
38
```
51
39
52
-
### Deployment
40
+
1. When you see the message `Your application running on port 8000 is available.`, click **Open in Browser**.
53
41
54
-
This repo is set up for deployment on Azure App Service (w/PostGreSQL server) using the configuration files in the `infra` folder.
42
+
### Quick deploy
55
43
56
-
🎥 Watch a deployment of the code in [this screencast](https://www.youtube.com/watch?v=JDlZ4TgPKYc).
44
+
This project is designed to work well with the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview), which makes it easier to develop apps locally, deploy them to Azure, and monitor them.
45
+
46
+
🎥 Watch a deployment of the code in [this screencast](https://www
47
+
.youtube.com/watch?v=JDlZ4TgPKYc).
57
48
58
49
Steps for deployment:
59
50
60
51
1. Sign up for a [free Azure account](https://azure.microsoft.com/free/)
61
-
2. Install the [Azure Dev CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd). (If you opened this repository in a Dev Container, that part will be done for you.)
52
+
2. Install the [Azure Dev CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd). (If you opened this repository in a Dev Container, it's already installed for you.)
62
53
3. Initialize a new `azd` environment:
63
54
64
55
```shell
65
56
azd init
66
57
```
67
58
68
-
It will prompt you to provide a name (like "django-app") that will later be used in the name of the deployed resources.
59
+
It will prompt you to provide a name (like "django-app"), which will later be used in the name of the deployed resources.
69
60
70
61
4. Provision and deploy all the resources:
71
62
@@ -91,25 +82,6 @@ Steps for deployment:
91
82
azd deploy
92
83
```
93
84
94
-
### CI/CD pipeline
95
-
96
-
This project includes a Github workflow for deploying the resources to Azure
97
-
on every push. That workflow requires several Azure-related authentication secrets to be stored as Github action secrets. To set that up, run:
98
-
99
-
```shell
100
-
azd pipeline config
101
-
```
102
-
103
-
### Monitoring
104
-
105
-
The deployed resources include a Log Analytics workspace with an Application Insights dashboard to measure metrics like server response time.
106
-
107
-
To open that dashboard, just run:
108
-
109
-
```shell
110
-
azd monitor --overview
111
-
```
112
-
113
85
## Getting help
114
86
115
87
If you're working with this project and running into issues, please post in [Issues](/issues).
run: echo $'\n\nApp Service app has the following settings:\n' && echo "$WEB_APP_SETTINGS" | jq -r '.[]' | sed 's/\(.*\)/\t- \1/' && echo -e $"\nSee the settings in the portal:\033[1;36m $WEB_APP_CONFIG"
17
+
interactive: true
18
+
continueOnError: true
19
+
windows:
20
+
shell: pwsh
21
+
run: Write-Host "`n`nApp Service app has the following settings:`n" $WEB_APP_SETTINGS | ConvertFrom-Json | ForEach-Object { Write-Host "\t- $_" }
22
+
interactive: true
23
+
continueOnError: true
24
+
postdeploy:
25
+
posix:
26
+
shell: sh
27
+
run: echo -e $"\n\nOpen SSH session to App Service container at:\033[1;36m $WEB_APP_SSH\033[0m" && echo -e $"Stream App Service logs at:\033[1;36m $WEB_APP_LOG_STREAM"
28
+
interactive: true
29
+
continueOnError: true
30
+
windows:
31
+
shell: pwsh
32
+
run: Write-Host "`n`nOpen SSH session to App Service container at:`n" $WEB_APP_SSH; Write-Host "Stream App Service logs at:`n" $WEB_APP_LOG_STREAM
0 commit comments