Skip to content

Commit

Permalink
containerize gantry and move from spack to requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
cmelone committed Feb 15, 2024
1 parent 89353a1 commit 8ef4801
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 27 deletions.
13 changes: 2 additions & 11 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#------------------------------------------------------------------------
# Load Development Spack Environment (If Spack is installed.)
#
# Run 'direnv allow' from within the cloned repository to automatically
# load the spack environment when you enter the directory.
#------------------------------------------------------------------------
if type spack &>/dev/null; then
. $SPACK_ROOT/share/spack/setup-env.sh
spack env activate -d .
fi
source $HOME/.venvs/gantry/bin/activate

#------------------------------------------------------------------------
# Load Environment Variables from .env (if files exists)
#------------------------------------------------------------------------
if [ -e .env ]; then
source .env
fi
fi
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
__pycache__
.env
spack.lock
.spack-env
db/*.db
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# from https://github.com/GoogleContainerTools/distroless/blob/main/examples/python3-requirements/Dockerfile

# Build a virtualenv using the appropriate Debian release
# * Install python3-venv for the built-in Python3 venv module (not installed by default)
# * Install gcc libpython3-dev to compile C Python modules
# * In the virtualenv: Update pip setuputils and wheel to support building new packages
FROM debian:12-slim AS build
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip setuptools wheel

# Build the virtualenv as a separate step: Only re-execute this step when requirements.txt changes
FROM build AS build-venv
COPY requirements.txt /requirements.txt
RUN /venv/bin/pip install --disable-pip-version-check -r /requirements.txt

# Copy the virtualenv into a distroless image
FROM gcr.io/distroless/python3-debian12:nonroot
COPY --from=build-venv /venv /venv
COPY ./gantry /app/gantry
WORKDIR /app
ENTRYPOINT ["/venv/bin/python", "-m", "gantry"]
28 changes: 28 additions & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Deploy

Gantry is distributed via containers. You can build an image using your favorite container engine:

```bash
podman build -t gantry .
```

In order for the application to run, you'll need to supply two things to the image: environment variables and a database file.

When running locally, you can get by with supplying an env file and volume, like so:

```bash
podman run -it -p 8080:8080 --env-file .env -v DB_PATH:/db gantry
```

When running Gantry within Kubernetes, you could use [persistent volumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/). The only requirement is that the database should exist outside the container for backup and persistence purposes.

## Environment

The following variables should be exposed to the container. Those **bolded** are required and do not have defaults set in the application.

- **`PROMETHEUS_URL`** - should end in `/api/v1`
- `PROMETHEUS_COOKIE` - only needed when Prometheus requires authentication
- **`GITLAB_URL`** - should end in the endpoint for the Spack project API: `/api/v4/projects/2`
- **`GITLAB_API_TOKEN`** - this token should have API read access
- **`GITLAB_WEBHOOK_TOKEN`** - coordinate this value with the collection webhook
- **`DB_FILE`** - path where the application can access the SQLite file
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
profile = "black"
skip_gitignore = true
color_output = true

dependencies = [
"aiohttp",
"aiosqlite"
]
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
aiohttp==3.9.3
aiosignal==1.3.1
aiosqlite==0.19.0
attrs==23.2.0
frozenlist==1.4.1
idna==3.6
multidict==6.0.5
yarl==1.9.4
14 changes: 0 additions & 14 deletions spack.yaml

This file was deleted.

0 comments on commit 8ef4801

Please sign in to comment.