Skip to content

Commit 4ce814a

Browse files
committed
Dockerizing the app
1 parent a9a3ca5 commit 4ce814a

File tree

6 files changed

+66
-13
lines changed

6 files changed

+66
-13
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
venv/

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,6 @@ venv.bak/
106106
/site
107107

108108
# mypy
109-
.mypy_cache/
109+
.mypy_cache/
110+
111+
.tool-versions

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.8
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY requirements.txt ./
6+
7+
COPY Makefile ./
8+
9+
RUN make install
10+
11+
COPY . .
12+
13+
RUN make serve-setup
14+
15+
EXPOSE 5000
16+
17+
CMD ["sh", "-c", ". /usr/src/app/venv/bin/activate && make serve"]

Makefile

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
.PHONY: venv install
12
UNAME := $(shell uname)
2-
install:
3+
venv:
34
ifeq ($(UNAME), Windows)
4-
py -3 -m venv venv; venv\Scripts\activate.bat;
5+
py -3 -m venv venv;
56
else
6-
virtualenv venv; source ./venv/bin/activate;
7+
python3 -m venv venv
8+
endif
9+
10+
install: venv
11+
ifeq ($(UNAME), Windows)
12+
venv\Scripts\activate.bat; \
13+
pip3 install -r requirements.txt;
14+
else
15+
. venv/bin/activate; \
16+
pip3 install -r requirements.txt;
717
endif
8-
pip3 install -r requirements.txt
918

1019
serve-setup:
11-
flask init-db; flask run;
12-
open-browser:
13-
python3 -m webbrowser "http://127.0.0.1:5000";
14-
serve: open-browser serve-setup
20+
. venv/bin/activate; \
21+
flask init-db;
22+
23+
serve:
24+
. venv/bin/activate; \
25+
flask run --host=0.0.0.0;

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,46 @@ After the above requirements have been met:
5656
cd verify-v2-quickstart-python
5757
```
5858

59-
1. Prepare the environment and install dependencies
59+
2. Prepare the environment and install dependencies
6060

6161
```bash
6262
make install
6363
```
6464

65-
1. Set your environment variables
65+
3. Set your environment variables
6666

6767
```bash
6868
cp .env.example .env
6969
```
7070

7171
See [Twilio Account Settings](#twilio-account-settings) to locate the necessary environment variables.
7272

73-
1. Run the application
73+
4. Set the database
74+
75+
```bash
76+
make serve-setup
77+
```
78+
79+
5. Run the application
7480

7581
```bash
7682
make serve
7783
```
7884

7985
This will start a development server. It will reload whenever you change any files.
8086

81-
1. Navigate to [http://localhost:5000](http://localhost:5000)
87+
6. Navigate to [http://localhost:5000](http://localhost:5000)
8288

8389
That's it!
8490

91+
### Docker
92+
93+
If you have [Docker](https://www.docker.com/) already installed on your machine, you can use our `docker-compose.yml` to setup your project.
94+
95+
1. Make sure you have the project cloned.
96+
2. Setup the `.env` file as outlined in the [Local Development](#local-development) steps.
97+
3. Run `docker-compose up`.
98+
8599
### Tests
86100

87101
You can run the tests locally by typing:

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3.8"
2+
services:
3+
app:
4+
container_name: app
5+
restart: always
6+
build: .
7+
ports:
8+
- "5000:5000"

0 commit comments

Comments
 (0)