From 9dca0851db4e6abf0e76f533570002f76c8fb9fc Mon Sep 17 00:00:00 2001 From: Matthew Evans <7916000+ml-evs@users.noreply.github.com> Date: Tue, 14 Nov 2023 10:51:28 +0000 Subject: [PATCH] Add Dockerfile for easier deployment of registry (#50) * Add Dockerfile for easier deployment of registry * Add README note * Add docker build in CI * Fix old typo in README * Hit endpoints in same workflow step * Add healthcheck to docker container --- .github/workflows/validate.yml | 22 ++++++++++++++++++++++ Dockerfile | 23 +++++++++++++++++++++++ README.md | 19 ++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 64458a0..33efbc1 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -56,3 +56,25 @@ jobs: - name: Run database ingestion tasks run: | invoke validate-entries + + build: + runs-on: ubuntu-latest + steps: + - name: Check Docker build + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: true + - name: Build image + run: | + docker build . -t marda-registry + + - name: Launch image + run: | + docker run -d --env PORT=8080 -p 8080:8080 marda-registry + - name: Hit registry endpoints + run: | + sleep 5 + curl http://localhost:8080/filetypes | jq + curl http://localhost:8080/extractors| jq + curl http://localhost:8080/redoc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f97e0de --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +from python:3.11-slim-buster + +env PORT=8000 +workdir /app + +# Copy local version of the registry and install reqs +copy requirements.txt /app +run pip install -r requirements.txt + +copy schemas /app/schemas +copy marda_registry /app/marda_registry +copy tasks.py /app + +# Regenerate models from the current schemas +run invoke regenerate-models + +# Validate all entries against the schema +run invoke validate-entries + +cmd uvicorn marda_registry.app:app --host 0.0.0.0 --port ${PORT} + +healthcheck --interval=5m --timeout=3s --start-period=10s \ + cmd curl --fail http://localhost:${PORT} || exit 1 diff --git a/README.md b/README.md index 6faef19..1a0c15e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,24 @@ invoke regenerate-models From the repository root directory, launch the server with uvicorn: ``` -uvicorn src.marda_registry.app:app +uvicorn marda_registry.app:app ``` then navigate to http://localhost:5000 to test. + +## Deployment + +The registry app can be easily deployed via the given [Dockerfile](./Dockerfile). +After cloning the repository (with submodules, following the instructions above), the image can be built for a given schema version by running + +```shell +docker build . -t marda-registry +``` + +and then launched with + +```shell +docker run -p 8080 --env PORT=8080 marda-registry +``` + +or equivalent command.