Skip to content

Commit

Permalink
slim docker with worker
Browse files Browse the repository at this point in the history
  • Loading branch information
franklin050187 committed Jul 17, 2024
1 parent 85d1859 commit aaa0c98
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
46 changes: 36 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
# Use official Python image as the base image
FROM python:3.9
# Use debian:11-slim as the base image for building
FROM debian:11-slim AS build

# Set the working directory in the container
WORKDIR /app
# Install necessary build dependencies and set up Python virtual environment
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes \
python3-venv \
gcc \
libpython3-dev \
unzip \
wget && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip setuptools wheel

# Download the project source code from GitHub
ADD https://github.com/franklin050187/cosmo/archive/refs/heads/docker.zip /app
WORKDIR /app
RUN wget https://github.com/franklin050187/cosmo/archive/refs/heads/docker.zip

# Unzip the downloaded file
RUN unzip docker.zip && rm docker.zip && mv cosmo-docker cosmo

# Change the working directory to the project directory
WORKDIR /app/cosmo

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Install Python dependencies from the provided requirements.txt
RUN /venv/bin/pip install --disable-pip-version-check -r requirements.txt

# Manually clean up the virtual environment
RUN find /venv -type d -name "__pycache__" -exec rm -r {} + && \
find /venv -type f -name "*.pyc" -exec rm -r {} + && \
rm -rf /root/.cache/pip

# Use the build stage as the source for the virtual environment
FROM gcr.io/distroless/python3-debian11

# Copy the virtual environment from the build stage
COPY --from=build /venv /venv

# Copy the application code from the build stage
COPY --from=build /app/cosmo /app

# Set the working directory
WORKDIR /venv

# Expose port 8000
# Expose port
EXPOSE 8000

# Command to start the server
CMD ["python", "server.py"]
# Set the entrypoint to run the app
ENTRYPOINT ["/venv/bin/python3", "/app/server.py"]
18 changes: 9 additions & 9 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,12 +961,12 @@ async def serve_files(request: Request):
app.add_middleware(HTTPSRedirectMiddleware)
# start server
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000, proxy_headers=True, forwarded_allow_ips="*")
# uvicorn.run(
# "server:app",
# host="0.0.0.0",
# port=8000,
# proxy_headers=True,
# forwarded_allow_ips="*",
# workers=5,
# )
# uvicorn.run(app, host="0.0.0.0", port=8000, proxy_headers=True, forwarded_allow_ips="*")
uvicorn.run(
"server:app",
host="0.0.0.0",
port=8000,
proxy_headers=True,
forwarded_allow_ips="*",
workers=5,
)

0 comments on commit aaa0c98

Please sign in to comment.