Skip to content

Commit f8aec68

Browse files
committed
2 parents 2e5bc99 + 5839480 commit f8aec68

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ FLASK_DEBUG=True
22
DBNAME=<database name>
33
DBHOST=<database-hostname>
44
DBUSER=<db-user-name>
5-
DBPASS=<db-password>
5+
DBPASS=<db-password>
6+
SECRET_KEY=<secret key>

.env.sample.devcontainer

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

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto eol=lf
2+
*.{cmd,[cC][mM][dD]} text eol=crlf
3+
*.{bat,[bB][aA][tT]} text eol=crlf

.github/workflows/python-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ jobs:
5151
DBHOST: localhost
5252
DBUSER: postgres
5353
DBPASS: postgres
54+
SECRET_KEY: flask-insecure-key-${{ github.run_id }}-${{ github.run_attempt }}

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,35 @@ which makes it easier to develop apps locally, deploy them to Azure, and monitor
2323

2424
### Local development
2525

26-
This project has devcontainer support, so you can open it in Github Codespaces or local VS Code with the Dev Containers extension.
26+
This project has Dev Container support, so you can open it in Github Codespaces or local VS Code with the Dev Containers extension.
2727

2828
🎥 [Watch a screencast of running the app in Github Codespaces.](https://www.youtube.com/watch?v=r6Hnp9RXUpY)
2929

3030
Steps for running the server:
3131

32-
1. (Optional) If you're unable to open the devcontainer, [create a Python virtual environment](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and activate that.
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 that.
3333

3434
2. Install the requirements:
3535

3636
```shell
3737
python3 -m pip install -r requirements.txt
3838
```
3939

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 devcontainer, copy the values from `.env.sample.devcontainer`.
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`.
4141

42-
4. Run the migrations:
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:
4349

4450
```shell
4551
python3 -m flask db upgrade
4652
```
4753

48-
5. Run the local server: (or use VS Code "Run" button and select "Run server")
54+
6. Run the local server: (or use VS Code "Run" button and select "Run server")
4955
5056
```shell
5157
python3 -m flask run
@@ -60,20 +66,28 @@ This repo is set up for deployment on Azure App Service (w/PostGreSQL server) us
6066
Steps for deployment:
6167
6268
1. Sign up for a [free Azure account](https://azure.microsoft.com/free/)
63-
2. Install the [Azure Dev CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd). (If you opened this repository in a devcontainer, that part will be done for you.)
64-
3. Provision and deploy all the resources:
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.)
70+
3. Initialize a new `azd` environment:
71+
72+
```shell
73+
azd init
74+
```
75+
76+
It will prompt you to provide a name (like "flask-app") that will later be used in the name of the deployed resources.
77+
78+
4. Provision and deploy all the resources:
6579
6680
```shell
6781
azd up
6882
```
6983
70-
It will prompt you to login and to provide a name (like "flask-app") and location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to "centralus") can help, as there are availability constraints for some of the resources.
84+
It will prompt you to login, pick a subscription, and provide a location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to "centralus") can help, as there may be availability constraints for some of the resources.
7185
72-
4. When `azd` has finished deploying, you'll see an endpoint URI in the command output. Visit that URI, and you should see the front page of the restaurant review app! 🎉 If you see an error, open the Azure Portal from the URL in the command output, navigate to the App Service, select Logstream, and check the logs for any errors.
86+
5. When `azd` has finished deploying, you'll see an endpoint URI in the command output. Visit that URI, and you should see the front page of the restaurant review app! 🎉 If you see an error, open the Azure Portal from the URL in the command output, navigate to the App Service, select Logstream, and check the logs for any errors.
7387
7488
![Screenshot of Flask restaurants website](screenshot_website.png)
7589
76-
5. When you've made any changes to the app code, you can just run:
90+
6. When you've made any changes to the app code, you can just run:
7791
7892
```shell
7993
azd deploy

azureproject/production.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
# SECURITY WARNING: keep the secret key used in production secret!
4-
SECRET_KEY = os.getenv('SECRET_KEY', 'flask-insecure-7ppocbnx@w71dcuinn*t^_mzal(t@o01v3fee27g%rg18fc5d@')
4+
SECRET_KEY = os.getenv('SECRET_KEY')
55

66
ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []
77
CSRF_TRUSTED_ORIGINS = ['https://' + os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []

0 commit comments

Comments
 (0)