Skip to content

Commit

Permalink
Made port in uvicorn script dynamic. Added port to env example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fjodor van Rijsselberg authored and Fjodor van Rijsselberg committed Aug 28, 2024
1 parent 16a0a08 commit cae829a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
18 changes: 11 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
FROM python:3.12-slim

ARG BASE_DIR
ARG BASE_DIR=/home/resolution
ARG PORT=9000

ENV PORT=${PORT}
ENV BASE_DIR=${BASE_DIR}
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN useradd -m resolution
RUN useradd -m -u 1000 -s /bin/bash resolution

WORKDIR $BASE_DIR

COPY pyproject.toml .
RUN pip install poetry \
&& poetry config virtualenvs.create false \
&& poetry install
&& poetry install --no-root

USER resolution
COPY . $BASE_DIR/app/
RUN mkdir -p ${BASE_DIR}/logs \
&& touch ${BASE_DIR}/logs/prm.log \
&& chown -R resolution:resolution ${BASE_DIR}

RUN mkdir -p $BASE_DIR/logs \
&& touch $BASE_DIR/logs/prm.log
USER resolution

WORKDIR $BASE_DIR/app
COPY . .

ENTRYPOINT ["bash", "./run.sh"]
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
dockerfile: Dockerfile
args:
BASE_DIR: ${BASE_DIR}
PORT: ${PORT}
container_name: ${FASTAPI_CONTAINER_NAME}
volumes:
- .:/app
Expand All @@ -41,7 +42,7 @@ services:
CELERY_CONFIG: ${CELERY_CONFIG}
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
ports:
- "9000:9000"
- ${PORT}:${PORT}
networks:
- app-network

Expand Down
3 changes: 2 additions & 1 deletion dot_env_example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Misc
CELERY_CONFIG=development
BASE_DIR=/home/resolution
PORT=9000

# Container names
RABBIT_CONTAINER_NAME=pidmr_rabbit
Expand All @@ -18,4 +19,4 @@ RABBITMQ_DEFAULT_PASS=guest
RABBITMQ_PORT=5672

#JWT key
JWT_SECRET_KEY=secret_key
JWT_SECRET_KEY=kaas
3 changes: 2 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
uvicorn main:app --host 0.0.0.0 --port 9000 &
PORT=${PORT:-8080}
uvicorn main:app --host 0.0.0.0 --port "$PORT" &
celery -A main.celery worker -l INFO -Q pid-resolution,pidmr,celery --autoscale=1,10

0 comments on commit cae829a

Please sign in to comment.