Skip to content

Commit 6eb5a68

Browse files
Merge pull request #213 from MathisVerstrepen/hotfix
fix: improve docker security, reliability and default performance
2 parents 7149231 + baff904 commit 6eb5a68

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

docker/api.Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ FROM python:3.11-slim
3535
ENV PYTHONDONTWRITEBYTECODE=1
3636
ENV PYTHONUNBUFFERED=1
3737

38+
RUN apt-get update \
39+
&& apt-get install -y --no-install-recommends \
40+
git \
41+
openssh-client \
42+
&& rm -rf /var/lib/apt/lists/*
43+
3844
# Create a non-root user and group for security
3945
RUN groupadd --system appuser || true && useradd --system -g appuser appuser
4046

@@ -46,6 +52,9 @@ ENV PATH="/opt/venv/bin:$PATH"
4652

4753
WORKDIR /app
4854

55+
# Create data directories needed by the application
56+
RUN mkdir -p /app/data/user_files /app/data/cloned_repos
57+
4958
# Copy application code, ensuring it's owned by the non-root user
5059
COPY --chown=appuser:appuser ./api/app .
5160
COPY --chown=appuser:appuser ./api/alembic.ini .
@@ -55,9 +64,5 @@ COPY --chown=appuser:appuser ./api/migrations ./migrations
5564
ENV API_PORT=8000
5665
EXPOSE 8000
5766

58-
# Switch to the non-root user
59-
USER appuser
60-
6167
# Use the shell form of CMD to allow environment variable substitution.
62-
# This fixes the syntax error in the original CMD.
6368
CMD gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:${API_PORT}

docker/docker-compose.prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ services:
2828
image: ghcr.io/mathisverstrepen/meridian/backend:${IMAGE_TAG:-latest}
2929

3030
container_name: ${NAME}_api
31-
command: sh -c "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port ${API_PORT}"
31+
command: sh -c "chown -R appuser:appuser /app/data && su appuser -c 'alembic upgrade head && gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:${API_PORT}'"
3232
ports:
3333
- "${API_PORT}:${API_PORT}"
3434
depends_on:

docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services:
3232
context: ..
3333
dockerfile: docker/api.Dockerfile
3434
container_name: ${NAME}_api
35-
command: sh -c "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port ${API_PORT}"
35+
command: sh -c "chown -R appuser:appuser /app/data && su appuser -c 'alembic upgrade head && gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:${API_PORT}'"
3636
ports:
3737
- "${API_PORT}:${API_PORT}"
3838
depends_on:

0 commit comments

Comments
 (0)