Skip to content

Commit 3eb21e5

Browse files
Merge pull request #5 from aleyipsoftwire/exercise-5
Exercise 5
2 parents 61711ca + a27cde0 commit 3eb21e5

File tree

7 files changed

+94
-11
lines changed

7 files changed

+94
-11
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM python:3.9-slim as base
2+
3+
# Set up poetry
4+
ENV POETRY_HOME="/opt/poetry"
5+
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
6+
ENV POETRY_NO_INTERACTION=1
7+
ENV PATH="$POETRY_HOME/bin:$PATH"
8+
RUN apt-get update \
9+
&& apt-get install --no-install-recommends --assume-yes curl
10+
RUN curl -sSL https://install.python-poetry.org | python3 -
11+
12+
# Install dependencies
13+
WORKDIR /app
14+
COPY poetry.lock pyproject.toml /app/
15+
RUN poetry install --no-interaction --no-ansi
16+
17+
COPY todo_app /app/todo_app
18+
19+
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
29+
CMD poetry run gunicorn --bind 0.0.0.0 "todo_app.app:create_app()"

README.md

Lines changed: 30 additions & 4 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

@@ -96,4 +99,27 @@ To generate a new encrypted value or to replace one of the provided values, for
9699
$ ansible-vault encrypt_string --vault-password-file your_password_file --name 'trello_api_key'
97100
```
98101

99-
then enter the value you want to encrypt when prompted.
102+
then enter the value you want to encrypt when prompted.
103+
104+
## Docker
105+
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:
118+
```bash
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
125+
```

poetry.lock

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Flask = "^2.2.5"
1010
python-dotenv = "^0.14.0"
1111
requests = "^2.31.0"
1212
pytest = "^8.0.0"
13+
gunicorn = "^21.2.0"
1314

1415
[tool.poetry.dev-dependencies]
1516

0 commit comments

Comments
 (0)