Skip to content

Commit fb07985

Browse files
committed
sync with main
1 parent 951dde1 commit fb07985

File tree

8 files changed

+39
-66
lines changed

8 files changed

+39
-66
lines changed

.devcontainer/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
# Dev container
1+
# .devcontainer directory
22

3-
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). It lets you open the repository in a [GitHub codespace](https://docs.github.com/codespaces/overview).
3+
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.
44

5-
The dev container is configured to have the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview), so you can run `azd` commands directly.
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+
- Redis
10+
- [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) (so you can run `azd` commands directly).

.devcontainer/devcontainer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "msdocs-flask-postgresql-sample-app",
2+
"name": "python-app-service-postgresql-redis-infra",
33
"dockerComposeFile": "docker-compose.yml",
44
"service": "app",
55
"workspaceFolder": "/workspace",
66
"features": {
77
"ghcr.io/azure/azure-dev/azd:latest": {}
8-
},
8+
},
99
"customizations": {
1010
"vscode": {
1111
// Add the IDs of extensions you want installed when the container is created.
@@ -51,9 +51,9 @@
5151
}
5252
}
5353
},
54-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
54+
// Use 'forwardPorts' to make a list of ports inside the container available locally. 5000 is for Flask, 8000 is for Django, and 5432 is for PostgreSQL.
5555
"forwardPorts": [
56-
5000, 5432
56+
8000, 5000, 5432
5757
],
5858
// Use 'postCreateCommand' to run commands after the container is created.
5959
// "postCreateCommand": "",

.devcontainer/docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@ services:
2828
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
2929
# (Adding the "ports" property to this file will not forward from a Codespace.)
3030

31+
redis:
32+
image: redis
33+
restart: unless-stopped
34+
3135
volumes:
3236
postgres-data:

.env.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FLASK_DEBUG=True
2-
DBNAME=<database name>
2+
DBNAME=<database-name>
33
DBHOST=<database-hostname>
44
DBUSER=<db-user-name>
55
DBPASS=<db-password>
6-
SECRET_KEY=<secret key>
6+
CACHELOCATION=<redis-cache-url>

.env.sample.devcontainer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ DBNAME=app
33
DBHOST=localhost
44
DBUSER=app_user
55
DBPASS=app_password
6-
SECRET_KEY=flask-insecure-secret-key
6+
CACHELOCATION=redis://redis:6379/0

.github/workflows/python-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
python_version: ["3.8", "3.9", "3.10", "3.11"]
1818
services:
1919
postgres:
20-
image: postgres:11
20+
image: postgres:12
2121
env:
2222
POSTGRES_PASSWORD: postgres
2323
ports:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
.azure
131+
.azure

README.md

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,47 @@ The [requirements.txt](./requirements.txt) has the following packages, all used
1616
| [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> Flask's [dotenv support](https://flask.palletsprojects.com/en/2.1.x/cli/#environment-variables-from-dotenv) sets environment variables automatically from an `.env` file. |
1717
| [flask_wtf](https://pypi.org/project/Flask-WTF/) | Form rendering, validation, and CSRF protection for Flask with WTForms. Uses CSRFProtect extension. |
1818

19-
## Using this project with the Azure Developer CLI (azd)
19+
## Run the sample
2020

21-
This project is designed to work well with the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview),
22-
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:
2322

24-
### 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).
2524

26-
This project has Dev Container support, so you can open it in Github Codespaces or local VS Code with the Dev Containers extension.
25+
1. From the repository root of your fork, select **Code** > **Codespaces** > **+**.
2726

28-
🎥 [Watch a screencast of running the app in Github Codespaces.](https://www.youtube.com/watch?v=r6Hnp9RXUpY)
29-
30-
Steps for running the server:
31-
32-
1. (Optional) If you're unable to open the Dev Container, [create a Python virtual environment](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and activate the virtual environment.
33-
34-
2. Install the requirements:
27+
1. In the codespace terminal, run the following commands:
3528

3629
```shell
30+
# Install requirements
3731
python3 -m pip install -r requirements.txt
38-
```
39-
40-
3. 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 Dev Container, copy the values from `.env.sample.devcontainer`.
41-
42-
4. In the `.env` file, fill in a secret value for `SECRET_KEY`. You can use this command to generate an appropriate value:
43-
44-
```shell
45-
python -c 'import secrets; print(secrets.token_hex())'
46-
```
47-
48-
5. Run the migrations:
49-
50-
```shell
32+
# Create .env with environment variables
33+
cp .env.sample.devcontainer .env
34+
# Run database migrations
5135
python3 -m flask db upgrade
52-
```
53-
54-
6. Run the local server: (or use VS Code "Run" button and select "Run server")
55-
56-
```shell
36+
# Start the development server
5737
python3 -m flask run
5838
```
5939

60-
### Deployment
40+
1. When you see the message `Your application running on port 8000 is available.`, click **Open in Browser**.
41+
42+
### Quick deploy
6143

62-
This repo is set up for deployment on Azure App Service (w/PostGreSQL server) using the configuration files in the `infra` folder.
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.
6345

64-
🎥 [Watch a screencast of deploying and re-deploying the app.](https://www.youtube.com/watch?v=r6Hnp9RXUpY)
46+
🎥 Watch a deployment of the code in [this screencast](https://www
47+
.youtube.com/watch?v=JDlZ4TgPKYc).
6548

6649
Steps for deployment:
6750

6851
1. Sign up for a [free Azure account](https://azure.microsoft.com/free/)
69-
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.)
7053
3. Initialize a new `azd` environment:
7154
7255
```shell
7356
azd init
7457
```
7558
76-
It will prompt you to provide a name (like "flask-app") that will later be used in the name of the deployed resources.
59+
It will prompt you to provide a name (like "flask-app"), which will later be used in the name of the deployed resources.
7760
7861
4. Provision and deploy all the resources:
7962
@@ -93,25 +76,6 @@ Steps for deployment:
9376
azd deploy
9477
```
9578
96-
### CI/CD pipeline
97-
98-
This project includes a Github workflow for deploying the resources to Azure
99-
on every push. That workflow requires several Azure-related authentication secrets to be stored as Github action secrets. To set that up, run:
100-
101-
```shell
102-
azd pipeline config
103-
```
104-
105-
### Monitoring
106-
107-
The deployed resources include a Log Analytics workspace with an Application Insights dashboard to measure metrics like server response time.
108-
109-
To open that dashboard, just run:
110-
111-
```shell
112-
azd monitor --overview
113-
```
114-
11579
## Getting help
11680
11781
If you're working with this project and running into issues, please post in [Issues](/issues).

0 commit comments

Comments
 (0)