Skip to content

Commit a27cde0

Browse files
Multistage
1 parent 9d97b4a commit a27cde0

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.git
2+
.github
3+
.idea
4+
.pytest_cache
5+
.venv
6+
.vscode
7+
ansible
8+
**/__pycache__
9+
.env*
10+
.gitignore
11+
.gitpod.yml
12+
.python-version
13+
Dockerfile

.env.template

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
# Needed because of the presence of the "todo_app" folder
33
FLASK_APP=todo_app/app
44

5-
# Turn on debug mode (which enables reloading on code changes and the interactive debugger: https://flask.palletsprojects.com/en/2.3.x/config/#DEBUG)
6-
FLASK_DEBUG=true
7-
85
TRELLO_API_KEY=<DELIBERATELY MISSING>
96
TRELLO_API_TOKEN=<DELIBERATELY MISSING>
107
TRELLO_BOARD_ID=<DELIBERATELY MISSING>

.env.test

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
# Needed because of the presence of the "todo_app" folder
33
FLASK_APP=todo_app/app
44

5-
# Turn on debug mode (which enables reloading on code changes and the interactive debugger: https://flask.palletsprojects.com/en/2.3.x/config/#DEBUG)
6-
FLASK_DEBUG=true
7-
85
TRELLO_API_KEY=TRELLO_API_KEY
96
TRELLO_API_TOKEN=TRELLO_API_TOKEN
107
TRELLO_BOARD_ID=TRELLO_BOARD_ID

Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.9-slim
1+
FROM python:3.9-slim as base
22

33
# Set up poetry
44
ENV POETRY_HOME="/opt/poetry"
@@ -14,7 +14,16 @@ WORKDIR /app
1414
COPY poetry.lock pyproject.toml /app/
1515
RUN poetry install --no-interaction --no-ansi
1616

17-
# Run project
1817
COPY todo_app /app/todo_app
18+
1919
EXPOSE 8000
20+
21+
FROM base as production
22+
23+
ENV FLASK_DEBUG=false
24+
CMD poetry run gunicorn --bind 0.0.0.0 "todo_app.app:create_app()"
25+
26+
FROM base as development
27+
28+
ENV FLASK_DEBUG=true
2029
CMD poetry run gunicorn --bind 0.0.0.0 "todo_app.app:create_app()"

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ Replace the board and list ids with the respective ids from your Trello board.
4747
## Running the App
4848

4949
Once the all dependencies have been installed, start the Flask app in development mode within the Poetry environment by running:
50+
5051
```bash
5152
$ poetry run flask run
5253
```
5354

5455
You should see output similar to the following:
56+
5557
```bash
5658
* Serving Flask app 'todo_app/app'
5759
* Debug mode: on
@@ -62,6 +64,7 @@ Press CTRL+C to quit
6264
* Debugger is active!
6365
* Debugger PIN: 113-666-066
6466
```
67+
6568
Now visit [`http://localhost:5000/`](http://localhost:5000/) in your web browser to view the app.
6669

6770
## Running the Tests
@@ -79,9 +82,9 @@ $ poetry run pytest
7982
3. Replace the IP address in the `inventory` file with the IP address(es) of the managed VM(s)
8083
4. Create a file `ansible-pw.txt` containing the vault password
8184
5. Run the following command in the `ansible` directory, to provision the VM:
82-
```bash
83-
$ ansible-playbook playbook.yml -i inventory --vault-password-file ansible-pw.txt
84-
```
85+
```bash
86+
$ ansible-playbook playbook.yml -i inventory --vault-password-file ansible-pw.txt
87+
```
8588

8689
### Note on env variables
8790

@@ -100,7 +103,23 @@ then enter the value you want to encrypt when prompted.
100103

101104
## Docker
102105

106+
Run the project with mounting:
107+
```bash
108+
docker build --target development --tag todo-app:dev .
109+
docker run -dit \
110+
--name todo-app-dev \
111+
-p 8000:8000 \
112+
--env-file .env \
113+
--mount type=bind,source="$(pwd)/todo_app",target=/app/todo_app,readonly \
114+
todo-app:dev
115+
```
116+
117+
Run the project in production environment:
103118
```bash
104-
docker build --tag todo-app .
105-
docker run -p 8000:8000 --env-file .env todo-app
119+
docker build --target production --tag todo-app:prod .
120+
docker run -dit \
121+
--name todo-app-prod \
122+
-p 8000:8000 \
123+
--env-file .env \
124+
todo-app:prod
106125
```

0 commit comments

Comments
 (0)