Skip to content

Commit 32bd534

Browse files
Merge pull request #7 from aleyipsoftwire/exercise-8
Exercise 8
2 parents cede31c + 477a2a7 commit 32bd534

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

Dockerfile

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

33
# Set up poetry
44
ENV POETRY_HOME="/opt/poetry"
@@ -12,22 +12,22 @@ RUN curl -sSL https://install.python-poetry.org | python3 -
1212
# Install dependencies
1313
WORKDIR /app
1414
COPY poetry.lock pyproject.toml /app/
15-
RUN poetry install --no-interaction --no-ansi
15+
RUN poetry config virtualenvs.create false --local && poetry install --no-interaction --no-ansi
1616

1717
COPY todo_app /app/todo_app
1818

1919
EXPOSE 8000
2020

21-
FROM base as test
21+
FROM base AS test
2222

23-
ENTRYPOINT poetry run pytest
23+
ENTRYPOINT ["poetry", "run", "pytest"]
2424

25-
FROM base as production
25+
FROM base AS production
2626

2727
ENV FLASK_DEBUG=false
28-
CMD poetry run gunicorn --bind 0.0.0.0 "todo_app.app:create_app()"
28+
CMD ["poetry", "run", "gunicorn", "--bind", "0.0.0.0", "todo_app.app:create_app()"]
2929

30-
FROM base as development
30+
FROM base AS development
3131

3232
ENV FLASK_DEBUG=true
33-
CMD poetry run gunicorn --bind 0.0.0.0 "todo_app.app:create_app()"
33+
CMD ["poetry", "run", "gunicorn", "--bind", "0.0.0.0", "todo_app.app:create_app()"]

README.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# DevOps Apprenticeship: Project Exercise
22

3-
> If you are using GitPod for the project exercise (i.e. you cannot use your local machine) then you'll want to launch a VM using the [following link](https://gitpod.io/#https://github.com/CorndelWithSoftwire/DevOps-Course-Starter). Note this VM comes pre-setup with Python & Poetry pre-installed.
3+
> If you are using GitPod for the project exercise (i.e. you cannot use your local machine) then you'll want to launch a
4+
> VM using the [following link](https://gitpod.io/#https://github.com/CorndelWithSoftwire/DevOps-Course-Starter).
5+
> Note this VM comes pre-setup with Python & Poetry pre-installed.
46
57
## System Requirements
68

7-
The project uses poetry for Python to create an isolated environment and manage package dependencies. To prepare your system, ensure you have an official distribution of Python version 3.8+ and install Poetry using one of the following commands (as instructed by the [poetry documentation](https://python-poetry.org/docs/#system-requirements)):
9+
The project uses poetry for Python to create an isolated environment and manage package dependencies.
10+
To prepare your system, ensure you have an official distribution of Python version 3.8+
11+
and install Poetry using one of the following commands
12+
(as instructed by the [poetry documentation](https://python-poetry.org/docs/#system-requirements)):
813

914
### Poetry installation (Bash)
1015

@@ -20,23 +25,27 @@ curl -sSL https://install.python-poetry.org | python3 -
2025

2126
You can check poetry is installed by running `poetry --version` from a terminal.
2227

23-
**Please note that after installing poetry you may need to restart VSCode and any terminals you are running before poetry will be recognised.**
28+
**Please note that after installing poetry you may need to restart VSCode and any terminals you are running before
29+
poetry will be recognised.**
2430

2531
## Dependencies
2632

27-
The project uses a virtual environment to isolate package dependencies. To create the virtual environment and install required packages, run the following from your preferred shell:
33+
The project uses a virtual environment to isolate package dependencies.
34+
To create the virtual environment and install required packages, run the following from your preferred shell:
2835

2936
```bash
3037
$ poetry install
3138
```
3239

33-
You'll also need to clone a new `.env` file from the `.env.template` to store local configuration options. This is a one-time operation on first setup:
40+
You'll also need to clone a new `.env` file from the `.env.template` to store local configuration options.
41+
This is a one-time operation on first setup:
3442

3543
```bash
3644
$ cp .env.template .env # (first time only)
3745
```
3846

39-
The `.env` file is used by flask to set environment variables when running `flask run`. This enables things like development mode (which also enables features like hot reloading when you make a file change).
47+
The `.env` file is used by flask to set environment variables when running `flask run`.
48+
This enables things like development mode (which also enables features like hot reloading when you make a file change).
4049

4150
### Trello
4251

@@ -46,7 +55,8 @@ Replace the board and list ids with the respective ids from your Trello board.
4655

4756
## Running the App
4857

49-
Once the all dependencies have been installed, start the Flask app in development mode within the Poetry environment by running:
58+
Once all the dependencies have been installed, start the Flask app in development mode within the Poetry environment by
59+
running:
5060

5161
```bash
5262
$ poetry run flask run
@@ -104,6 +114,7 @@ then enter the value you want to encrypt when prompted.
104114
## Docker
105115

106116
Run the project with mounting:
117+
107118
```bash
108119
docker build --target development --tag todo-app:dev .
109120
docker run -dit \
@@ -115,6 +126,7 @@ docker run -dit \
115126
```
116127

117128
Run tests:
129+
118130
```bash
119131
docker build --target test --tag todo-app:test .
120132
docker run -it \
@@ -123,6 +135,7 @@ docker run -it \
123135
```
124136

125137
Run the project in production environment:
138+
126139
```bash
127140
docker build --target production --tag todo-app:prod .
128141
docker run -dit \
@@ -131,3 +144,26 @@ docker run -dit \
131144
--env-file .env \
132145
todo-app:prod
133146
```
147+
148+
## Deployment
149+
150+
### Building the Docker image
151+
152+
1. Logging into DockerHub locally, with `docker login`
153+
2. Building the image, with `docker build --target production --tag <user_name>/todo-app:prod .`
154+
3. Pushing the image, with `docker push <user_name>/todo_app:prod`
155+
156+
### Deploying to Azure App Services
157+
158+
1. First create an App Service Plan:
159+
`az appservice plan create --resource-group <resource_group_name> -n <appservice_plan_name> --sku B1 --is-linux`
160+
2. Then create the Web App:
161+
`az webapp create --resource-group <resource_group_name> --plan <appservice_plan_name> --name <webapp_name> --deployment-container-image-name docker.io/<user_name>/todo-app:prod`
162+
3. Set up environment variables individually via
163+
`az webapp config appsettings set -g <resource_group_name> -n <webapp_name> --settings FLASK_APP=todo_app/app`
164+
4. The app should now be deployed to `http://<webapp_name>.azurewebsites.net/`
165+
166+
### Update the image
167+
168+
When the image is updated and pushed to DockerHub, run `curl -x POST '<webhook>'`.
169+
The webhook URL can be found under Deployment Center on the app service's page in the Azure portal

0 commit comments

Comments
 (0)