Skip to content

Commit 07f1e47

Browse files
committed
Final changes to make it work with Azure App Service
1 parent 1f77176 commit 07f1e47

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Dockerfile

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
# Pull a pre-built alpine docker image with nginx and python3 installed
22
FROM tiangolo/uwsgi-nginx:python3.6-alpine3.7
33

4+
# Set the port on which the app runs; make both values the same.
5+
#
6+
# IMPORTANT: When deploying to Azure App Service, go to the App Service on the Azure
7+
# portal, navigate to the Applications Settings blade, and create a setting named
8+
# WEBSITES_PORT with a value that matches the port here (the Azure default is 80).
9+
# You can also create a setting through the App Service Extension in VS Code.
410
ENV LISTEN_PORT=8000
511
EXPOSE 8000
612

13+
# Indicate where uwsgi.ini lives
14+
ENV UWSGI_INI uwsgi.ini
15+
16+
# Tell nginx where static files live. Typically, developers place static files for
17+
# multiple apps in a shared folder, but for the purposes here we can use the one
18+
# app's folder. Note that when multiple apps share a folder, you should create subfolders
19+
# with the same name as the app underneath "static" so there aren't any collisions
20+
# when all those static files are collected together, as when using Django's
21+
# collectstatic command.
22+
ENV STATIC_URL /app/static_collected
23+
724
# Copy the app files to a folder and run it from there
825
WORKDIR /app
926
ADD . /app
1027

28+
# Make app folder writeable for the sake of db.sqlite3, and make that file also writeable.
29+
# Ideally you host the database somewhere else so that the app folders can remain read only.
30+
# Without these permissions you see the errors "unable to open database file" and
31+
# "attempt to write to a readonly database", respectively, whenever the app attempts to
32+
# write to the database.
33+
RUN chmod g+w /app
34+
RUN chmod g+w /app/db.sqlite3
35+
36+
# Make sure dependencies are installed
1137
RUN python3 -m pip install -r requirements.txt
12-
CMD ["uwsgi", "uwsgi.ini"]

uwsgi.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
chdir = .
33
module = web_project.wsgi:application
44
env = DJANGO_SETTINGS_MODULE=web_project.settings
5-
protocol = http
6-
socket = 127.0.0.1:8000
75
uid = 1000
86
master = true
97
threads = 2

web_project/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
SECRET_KEY = '2gult1d96#@#b2%tz+k9x1q%-4(%f@va-!sbv*q&$t^gpp8-_='
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
26+
# If you set to False, also add "localhost" to ALLOWED_HOSTS or else
27+
# you'll get "Bad Request" when running locally.
2628
DEBUG = True
2729

30+
# When deploying to Azure App Service, add you <name>.azurewebsites.net
31+
# domain to ALLOWED_HOSTS; you get an error message if you forget.
2832
ALLOWED_HOSTS = []
2933

3034

0 commit comments

Comments
 (0)