Skip to content

Commit

Permalink
try faster builds
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Dec 15, 2024
1 parent 95592eb commit 600a8af
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Exclude Python cache files
__pycache__
*.pyc
*.pyo
*.pyd

# Exclude virtual environments
venv/
env/
.venv/
.env/

# Exclude version control directories
.git
.gitignore

# Exclude Dockerfile and Docker-related files if not needed
Dockerfile
docker-compose.yml

# Exclude other unnecessary files and directories
node_modules/
dist/
build/
*.log
*.md
28 changes: 20 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
# Use an updated Python image
FROM python:3.12-bookworm

# Install dependencies
RUN apt-get update && apt-get install -y libsnappy-dev
# Set environment variables to prevent Python from writing .pyc files and buffering stdout/stderr
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Install dependencies in one layer for faster builds
RUN apt-get update && \
apt-get install -y libsnappy-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Install uv package manager
RUN pip install --no-cache-dir uv

# Set the working directory in the container
WORKDIR /app

# First, copy only the requirements.txt file
COPY requirements.txt .
# Copy only requirements.txt first to leverage caching
COPY requirements.txt ./

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Install Python dependencies using uv
RUN uv --install -r requirements.txt

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

# Add .dockerignore to reduce build context
# (Ensure .dockerignore is properly configured to exclude unnecessary files)

# Command to run the application
CMD ["python3", "main.py"]
CMD ["python3", "main.py"]

0 comments on commit 600a8af

Please sign in to comment.