Skip to content

Commit

Permalink
Merge pull request #5 from bobokun/docker-alpine
Browse files Browse the repository at this point in the history
Dockerfile: Switch to Alpine base and streamline dependencies
  • Loading branch information
MattFaz authored Jul 23, 2024
2 parents 9cda92c + 7c37502 commit 4fd3856
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
FROM python:3.12-slim
# Use Python 3.12 Alpine as the base image
FROM python:3.12-alpine

# Set up build argument and environment variable for branch name
ARG BRANCH_NAME=main
ENV BRANCH_NAME=${BRANCH_NAME}

# Set the Tini version
ENV TINI_VERSION=v0.19.0

# Set up build argument and environment variable for config directory
ARG CONFIG_DIR=/config
ENV CONFIG_DIR=/config

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt /

# install packages
RUN echo "**** install system packages ****" \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
git \
bash \
curl \
wget \
jq \
grep \
sed \
coreutils \
findutils \
gcc \
libffi-dev \
rustc \
cargo \
tini \
&& pip3 install --no-cache-dir --upgrade pip \
&& pip3 install --no-cache-dir --upgrade --requirement /requirements.txt \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /requirements.txt /tmp/* /var/tmp/*

COPY . .
# Install necessary system dependencies and Tini
RUN apk add --no-cache gcc musl-dev libffi-dev tini

# Copy the rest of the application code into the container
COPY . .

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade -r /requirements.txt && pip install -e .

# Create a volume for the config directory
VOLUME /config

# Expose port 8000 for the FastAPI application
EXPOSE 8000
ENTRYPOINT ["/sbin/tini", "-s", "/app/copy-config.sh", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

# Set the entrypoint to run the application using Tini as the init process
ENTRYPOINT ["/sbin/tini", "-s", "--", "/app/copy-config.sh", "fastapi", "run", "main.py", "--host", "0.0.0.0", "--port", "8000"]

0 comments on commit 4fd3856

Please sign in to comment.