From b4d91051ad9ff7322055c13f4f8d2e51b13a2ccf Mon Sep 17 00:00:00 2001 From: Mark Hobson Date: Fri, 15 Sep 2023 13:33:51 +0100 Subject: [PATCH] GH-1: Build Docker image --- .github/workflows/ci.yml | 5 +++++ Dockerfile | 11 +++++++++++ README.md | 22 ++++++++++++++++++++++ pyproject.toml | 3 ++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa5f4f75..106b3f32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,3 +28,8 @@ jobs: - name: Run tests run: pytest + + - name: Build image + uses: docker/build-push-action@v4 + with: + tags: schemes diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a6a5b89c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.10 + +ENV PORT 5000 + +WORKDIR /usr/src/app +COPY schemes ./schemes +COPY pyproject.toml . + +RUN pip install --no-cache-dir . + +CMD [ "sh", "-c", "gunicorn --bind 0.0.0.0:${PORT} 'schemes:create_app()'" ] diff --git a/README.md b/README.md index 67a245f7..5d2b2dee 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,28 @@ 1. Open http://127.0.0.1:5000 +## Running locally as a container + +1. Build the Docker image: + + ```bash + docker build -t schemes . + ``` + +1. Run the Docker image: + + ```bash + docker run --rm -it -p 5000:5000 schemes + ``` + +1. Open http://127.0.0.1:5000 + +The server can also be run on a different port by specifying the `PORT` environment variable: + +```bash +docker run --rm -it -e PORT=8000 -p 8000:8000 schemes +``` + ## Running tests 1. Install the dev dependencies: diff --git a/pyproject.toml b/pyproject.toml index eddf178c..6ff07e3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,8 @@ name = "schemes" version = "1.0.0" dependencies = [ - "flask" + "flask", + "gunicorn" ] [project.optional-dependencies]