diff --git a/Dockerfile b/Dockerfile index 3c8100b..d4fd640 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,9 @@ 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 +FROM gcr.io/distroless/python3-debian12:latest COPY --from=build /venv /venv COPY ./gantry /app/gantry +COPY ./db /app/db WORKDIR /app ENTRYPOINT ["/venv/bin/python", "-m", "gantry"] diff --git a/db/schema.sql b/db/schema.sql index a9dc104..d26036b 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -1,6 +1,6 @@ PRAGMA foreign_keys = ON; -CREATE TABLE nodes ( +CREATE TABLE IF NOT EXISTS nodes ( id INTEGER PRIMARY KEY, uuid TEXT NOT NULL UNIQUE, hostname TEXT NOT NULL, @@ -11,7 +11,7 @@ CREATE TABLE nodes ( instance_type TEXT NOT NULL ); -CREATE TABLE jobs ( +CREATE TABLE IF NOT EXISTS jobs ( id INTEGER PRIMARY KEY, pod TEXT NOT NULL UNIQUE, node INTEGER NOT NULL, diff --git a/gantry/__main__.py b/gantry/__main__.py index a420f94..8d1f54f 100644 --- a/gantry/__main__.py +++ b/gantry/__main__.py @@ -18,7 +18,11 @@ async def init_db(app: web.Application): db = await aiosqlite.connect(os.environ["DB_FILE"]) - await db.execute("PRAGMA foreign_keys = ON;") + # create a database with the schema if it doesn't exist + # otherwise, this is a noop + with open("db/schema.sql") as f: + await db.executescript(f.read()) + await db.commit() app["db"] = db yield await db.close()