From 0c38484dcf8fa6eeee9dc7db1a988dcfe8ee323d Mon Sep 17 00:00:00 2001 From: Rushil Srivastava Date: Fri, 25 Jun 2021 22:27:49 -0400 Subject: [PATCH 1/2] :construction_worker: Convert build scripts to use poetry --- .github/workflows/deploy.yml | 24 +++++++++++++++++++----- .github/workflows/test.yml | 24 +++++++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 70eaf722..6e402025 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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/install-poetry@v1.1.1 + 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 }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26c459b0..96e65b09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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/install-poetry@v1.1.1 + 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 }} From e9f3da4f6d66f8e6dcd4631198c50ce46b64dfc0 Mon Sep 17 00:00:00 2001 From: Rushil Srivastava Date: Sat, 26 Jun 2021 00:30:23 -0400 Subject: [PATCH 2/2] :memo: Add relevant documentation --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 54c4fb82..6e6afb81 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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