Skip to content

Commit e2d4a09

Browse files
committed
Tweaks for deployment/style
1 parent b5cbf46 commit e2d4a09

File tree

5 files changed

+9
-21
lines changed

5 files changed

+9
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
.azure

app.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,18 @@
3232
# Create databases, if databases exists doesn't issue create
3333
# For schema changes, run "flask db migrate"
3434
from models import Restaurant, Review
35-
db.create_all()
36-
db.session.commit()
35+
36+
with app.app_context():
37+
db.create_all()
3738

3839
@app.route('/', methods=['GET'])
3940
def index():
40-
from models import Restaurant
4141
print('Request for index page received')
4242
restaurants = Restaurant.query.all()
4343
return render_template('index.html', restaurants=restaurants)
4444

4545
@app.route('/<int:id>', methods=['GET'])
4646
def details(id):
47-
from models import Restaurant, Review
4847
restaurant = Restaurant.query.where(Restaurant.id == id).first()
4948
reviews = Review.query.where(Review.restaurant==id)
5049
return render_template('details.html', restaurant=restaurant, reviews=reviews)
@@ -57,7 +56,6 @@ def create_restaurant():
5756
@app.route('/add', methods=['POST'])
5857
@csrf.exempt
5958
def add_restaurant():
60-
from models import Restaurant
6159
try:
6260
name = request.values.get('restaurant_name')
6361
street_address = request.values.get('street_address')
@@ -80,7 +78,6 @@ def add_restaurant():
8078
@app.route('/review/<int:id>', methods=['POST'])
8179
@csrf.exempt
8280
def add_review(id):
83-
from models import Review
8481
try:
8582
user_name = request.values.get('user_name')
8683
rating = request.values.get('rating')

azureproject/development.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# Build paths inside the project like this: BASE_DIR / 'subdir'.
55
BASE_DIR = Path(__file__).resolve().parent.parent
66

7-
DEBUG = True
8-
97
DATABASE_URI = 'postgresql+psycopg2://{dbuser}:{dbpass}@{dbhost}/{dbname}'.format(
108
dbuser=os.environ['DBUSER'],
119
dbpass=os.environ['DBPASS'],

azureproject/production.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# SECURITY WARNING: keep the secret key used in production secret!
44
SECRET_KEY = os.getenv('SECRET_KEY', 'flask-insecure-7ppocbnx@w71dcuinn*t^_mzal(t@o01v3fee27g%rg18fc5d@')
55

6-
DEBUG = False
76
ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []
87
CSRF_TRUSTED_ORIGINS = ['https://'+ os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []
98

infra/resources.bicep

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ resource web 'Microsoft.Web/sites@2022-03-01' = {
105105
resource appSettings 'config' = {
106106
name: 'appsettings'
107107
properties: {
108+
SCM_DO_BUILD_DURING_DEPLOYMENT: 'true'
108109
DBHOST: postgresServer.name
109110
DBNAME: flaskDatabase.name
110111
DBUSER: postgresServer.properties.administratorLogin
111112
DBPASS: databasePassword
112-
SCM_DO_BUILD_DURING_DEPLOYMENT: 'true'
113113
SECRET_KEY: secretKey
114+
FLASK_DEBUG: 'False'
114115
}
115116
}
116117

@@ -197,7 +198,7 @@ resource postgresServer 'Microsoft.DBforPostgreSQL/flexibleServers@2022-01-20-pr
197198
}
198199
properties: {
199200
version: '13'
200-
administratorLogin: 'postgres-admin'
201+
administratorLogin: 'postgresadmin'
201202
administratorLoginPassword: databasePassword
202203
storage: {
203204
storageSizeGB: 128
@@ -232,14 +233,5 @@ resource flaskDatabase 'Microsoft.DBforPostgreSQL/flexibleServers/databases@2022
232233
name: 'flask'
233234
}
234235

235-
resource postgresServer_AllowAllWindowsAzureIps 'Microsoft.DBforPostgreSQL/flexibleServers/firewallRules@2022-01-20-preview' = {
236-
parent: postgresServer
237-
name: 'AllowAllWindowsAzureIps'
238-
properties: {
239-
startIpAddress: '0.0.0.0'
240-
endIpAddress: '0.0.0.0'
241-
}
242-
}
243-
244236
output WEB_URI string = 'https://${web.properties.defaultHostName}'
245-
output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsightsResources.outputs.APPLICATIONINSIGHTS_CONNECTION_STRING
237+
output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsightsResources.outputs.APPLICATIONINSIGHTS_CONNECTION_STRING

0 commit comments

Comments
 (0)