Skip to content

Commit

Permalink
Merge pull request #6 from rushilsrivastava/feat/github-actions-poetry
Browse files Browse the repository at this point in the history
👷🏽 Convert build scripts to use poetry
  • Loading branch information
rushilsrivastava authored Jun 26, 2021
2 parents 0b73daf + e9f3da4 commit 27facdf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Install Dependencies
run: python3.8 -m pip install six docker pytest
python-version: "3.9"
- name: Install and configure Poetry
uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install poetry dependencies
run: poetry install --no-interaction --no-root
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Deploy Image
run: bash scripts/build-push.sh
run: |
source .venv/bin/activate
bash scripts/build-push.sh
env:
NAME: ${{ matrix.image.name }}
PYTHON_VERSION: ${{ matrix.image.python_version }}
Expand Down
24 changes: 19 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Install Dependencies
run: python3.8 -m pip install six docker pytest
python-version: "3.9"
- name: Install and configure Poetry
uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install poetry dependencies
run: poetry install --no-interaction --no-root
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Test Image
run: bash scripts/test.sh
run: |
source .venv/bin/activate
bash scripts/test.sh
env:
NAME: ${{ matrix.image.name }}
PYTHON_VERSION: ${{ matrix.image.python_version }}
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,23 @@ docker run -d -p 80:8080 -e GUNICORN_CMD_ARGS="--keyfile=/secrets/key.pem --cert

**Note**: instead of handling TLS/SSL yourself and configuring it in the container, it's recommended to use a "TLS Termination Proxy" like [Traefik](https://docs.traefik.io/). You can read more about it in the [FastAPI documentation about HTTPS](https://fastapi.tiangolo.com/deployment/#https).

#### `UVICORN_ARGS`

Any additional command line settings for Uvicorn can be passed in the `UVICORN_ARGS` environment variable.

Read more about it in the [Uvicorn docs: Settings](https://www.uvicorn.org/settings/).

For example, if you have only one directory you want to watch for reloading, you could set [`--reload-dir`](https://www.uvicorn.org/settings/#development) to the directory, for example:

```bash
docker run -d -p 80:8080 -e UVICORN_ARGS="--reload-dir=/app" myimage
```

#### `PRE_START_PATH`

The path where to find the pre-start script.

By default, set to `/app/prestart.sh`.
By default, set to `/prestart.sh`. The image will check these paths first: `/app/prestart.sh`, `/app/app/prestart.sh`, `/app/scripts/prestart.sh`, and `/app/app/scripts/prestart.sh`.

You can set it like:

Expand All @@ -489,11 +501,11 @@ You can override it by including a file in:
* `/app/app/gunicorn_conf.py`
* `/gunicorn_conf.py`

### Custom `/app/prestart.sh`
### Custom `/prestart.sh`

If you need to run anything before starting the app, you can add a file `prestart.sh` to the directory `/app`. The image will automatically detect and run it before starting everything.

For example, if you want to add Alembic SQL migrations (with SQLALchemy), you could create a `./app/prestart.sh` file in your code directory (that will be copied by your `Dockerfile`) with:
For example, if you want to add Alembic SQL migrations (with SQLALchemy), you could create a `./prestart.sh` file in your code directory (that will be copied by your `Dockerfile`) with:

```bash
#! /usr/bin/env bash
Expand Down

0 comments on commit 27facdf

Please sign in to comment.