Skip to content

Commit e607da9

Browse files
author
Alan Christie
committed
feat: Support for process env
1 parent a0d5c1c commit e607da9

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ ENV PATH=/.venv/bin:$PATH
5151
COPY app/ ./app/
5252
COPY logging.config .
5353
COPY docker-entrypoint.sh .
54+
COPY internal.env ./
55+
COPY public.env ./
5456

5557
# Probes...
5658
COPY probes/*.sh .

app/app.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,24 @@
4141
assert _AMPQ_URL, "ESS_AMPQ_URL environment variable must be set"
4242
_LOGGER.info("AMPQ_URL: %s", _AMPQ_URL)
4343

44-
# Create our local database.
45-
# A table to record allocated Event Streams.
46-
# The table 'id' is an INTEGER PRIMARY KEY and so becomes an auto-incrementing
47-
# value when NONE is passed in as it's value.
44+
# SQLite database path
4845
_DATABASE_PATH = "/data/event-streams.db"
49-
_LOGGER.info("Creating SQLite database (%s)...", _DATABASE_PATH)
50-
_DB_CONNECTION = sqlite3.connect(_DATABASE_PATH)
51-
_CUR = _DB_CONNECTION.cursor()
52-
_CUR.execute(
53-
"CREATE TABLE IF NOT EXISTS es (id INTEGER PRIMARY KEY, uuid TEXT, routing_key TEXT)"
54-
)
55-
_DB_CONNECTION.commit()
56-
_DB_CONNECTION.close()
57-
_LOGGER.info("Created.")
46+
47+
# Logic specific to the 'internal API' process
48+
if os.getenv("IMAGE_ROLE", "").lower() == "internal":
49+
# Create the database.
50+
# A table to record allocated Event Streams.
51+
# The table 'id' is an INTEGER PRIMARY KEY and so becomes an auto-incrementing
52+
# value when NONE is passed in as it's value.
53+
_LOGGER.info("Creating SQLite database (%s)...", _DATABASE_PATH)
54+
_DB_CONNECTION = sqlite3.connect(_DATABASE_PATH)
55+
_CUR = _DB_CONNECTION.cursor()
56+
_CUR.execute(
57+
"CREATE TABLE IF NOT EXISTS es (id INTEGER PRIMARY KEY, uuid TEXT, routing_key TEXT)"
58+
)
59+
_DB_CONNECTION.commit()
60+
_DB_CONNECTION.close()
61+
_LOGGER.info("Created.")
5862

5963

6064
# We use pydantic to declare the model (request payloads) for the internal REST API.

docker-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
# and the internal REST endpoint.
77
# Done by launching two uvicorn instances in parallel.
88
echo "+> Launching uvicorn..."
9-
uvicorn app.app:app_public --host 0.0.0.0 --port 8080 & \
10-
uvicorn app.app:app_internal --host 0.0.0.0 --port 8081
9+
uvicorn app.app:app_public --host 0.0.0.0 --port 8080 --env-file public.env & \
10+
uvicorn app.app:app_internal --host 0.0.0.0 --port --env-file internal.env 8081

internal.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Env settings for the Internal API process
2+
IMAGE_ROLE=internal

logging.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"disable_existing_loggers": "true",
44
"formatters": {
55
"simple": {
6-
"format": "%(asctime)s.%(msecs)03dZ %(module)s.%(funcName)s():%(lineno)d %(levelname)s # %(message)s",
6+
"format": "%(asctime)s.%(msecs)03dZ %(thread)d %(threadName)s %(module)s.%(funcName)s():%(lineno)d %(levelname)s # %(message)s",
77
"datefmt": "%Y-%m-%dT%H:%M:%S"
88
}
99
},

public.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Env settings for the Public (WebSocket) process
2+
IMAGE_ROLE=public

0 commit comments

Comments
 (0)