Skip to content

Commit

Permalink
build: working single stage
Browse files Browse the repository at this point in the history
  • Loading branch information
pythoninthegrass committed Oct 16, 2024
1 parent b866805 commit 057c5eb
Showing 1 changed file with 21 additions and 46 deletions.
67 changes: 21 additions & 46 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,69 +1,44 @@
# syntax=docker/dockerfile:1.7.0

# Build stage
FROM python:3.8-alpine3.20 AS builder
FROM python:3.8-alpine3.20

# pip env vars
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100

# standardise on locale, don't generate .pyc, enable tracebacks on seg faults
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONFAULTHANDLER=1

# set locale
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
# Add project source
WORKDIR /musicbot
COPY . ./
COPY ./config sample_config

# Install build dependencies
RUN apk update && apk add --no-cache \
RUN apk update && apk add --no-cache --virtual .build-deps \
build-base \
libffi-dev \
libsodium-dev \
git \
&& rm -rf /var/cache/apk/*

WORKDIR /musicbot

# Install pip and dependencies
COPY requirements.txt .
RUN python -m pip install --no-cache-dir --upgrade pip \
&& python -m pip install --no-cache-dir -r requirements.txt

# Final stage
FROM python:3.8-alpine3.20 AS runner

# pip env vars
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100

# standardise on locale, don't generate .pyc, enable tracebacks on seg faults
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONFAULTHANDLER=1

# set locale
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

# Install runtime dependencies
# Install dependencies
RUN apk update && apk add --no-cache \
ca-certificates \
ffmpeg \
gcc \
git \
libffi \
libsodium \
opus-dev \
&& rm -rf /var/cache/apk/*

# Copy only necessary files from builder stage
COPY --from=builder /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# pip env vars
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100

WORKDIR /musicbot
COPY . .
COPY ./config sample_config
# don't generate .pyc, enable tracebacks on seg faults
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONFAULTHANDLER=1

# Install pip dependencies
RUN python -m pip install --no-cache-dir -r requirements.txt

# Clean up build dependencies
RUN apk del .build-deps

# Create volumes for audio cache, config, data and logs
VOLUME ["/musicbot/audio_cache", "/musicbot/config", "/musicbot/data", "/musicbot/logs"]
Expand Down

0 comments on commit 057c5eb

Please sign in to comment.