From 49b0504513a87d108081d354fba35d90f1f9a486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Jos=C3=A9=20Camacho?= Date: Tue, 12 Mar 2024 10:04:30 -0600 Subject: [PATCH] [DH-5575] Add env var to change the container port (#423) --- .env.example | 2 ++ Dockerfile | 8 ++++++-- docker-compose.yml | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index c81c5444..73a8370d 100644 --- a/.env.example +++ b/.env.example @@ -43,3 +43,5 @@ MONGODB_DB_PASSWORD = 'admin' S3_AWS_ACCESS_KEY_ID= S3_AWS_SECRET_ACCESS_KEY= ONLY_STORE_CSV_FILES_LOCALLY = False # Set to True if only want to save generated CSV files locally instead of S3. Note that if stored locally they should be treated as ephemeral, i.e., they will disappear when the engine is restarted. + +CORE_PORT = 80 # This env var defines the port that will be exposed by the container. It serves as the configuration for both the internal and external container ports. diff --git a/Dockerfile b/Dockerfile index 20daeb4f..4673935e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,10 @@ RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt COPY . /app -EXPOSE 80 +# Set default CORE_PORT to 80 if not provided +ARG CORE_PORT=80 +ENV CORE_PORT=${CORE_PORT} -CMD ["uvicorn", "dataherald.app:app", "--host", "0.0.0.0", "--port", "80"] +EXPOSE ${CORE_PORT} + +CMD ["uvicorn", "dataherald.app:app", "--host", "0.0.0.0", "--port", "${CORE_PORT}"] diff --git a/docker-compose.yml b/docker-compose.yml index f2817d96..af64a2e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,8 +5,10 @@ services: context: . dockerfile: Dockerfile ports: - - "80:80" - command: uvicorn dataherald.app:app --host 0.0.0.0 --port 80 --log-config log_config.yml --log-level debug --reload + - "${CORE_PORT:-80}:${CORE_PORT:-80}" + environment: + - CORE_PORT=${CORE_PORT:-80} + command: uvicorn dataherald.app:app --host 0.0.0.0 --port ${CORE_PORT:-80} --log-config log_config.yml --log-level debug --reload stdin_open: true tty: true volumes: