Skip to content

Commit

Permalink
change base image in second stage to Alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
orenlab committed Apr 9, 2024
1 parent ad9959e commit 2470e76
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# First stage
FROM python:3.12.2-alpine3.19 AS builder

# Copy python deps file
COPY requirements.txt .

# Install some python deps (needed for build psutil and over packages)
RUN apk --no-cache add gcc python3-dev musl-dev linux-headers

# Install dependencies to the venv path
RUN python3 -m venv --without-pip venv
RUN pip install --no-cache --target="/venv/lib/python3.12/site-packages" -r requirements.txt

# Second unnamed stage
FROM python:3.12.2-alpine3.19
FROM alpine:latest

# App workdir
WORKDIR /opt/pytmbot/
Expand All @@ -21,20 +18,25 @@ WORKDIR /opt/pytmbot/
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONPATH=/opt/pytmbot
# Setup PATH env
ENV PATH=/venv/bin:$PATH
# Setup time zone
ENV TZ="Asia/Yekaterinburg"

# Copy .env file with token (prod, dev)
COPY .env /opt/pytmbot
# Сopy only the necessary python files and directories from first stage
COPY --from=builder /usr/local/bin/python3 /usr/local/bin/python3
COPY --from=builder /usr/local/bin/python3.12 /usr/local/bin/python3.12
COPY --from=builder /usr/local/lib/python3.12 /usr/local/lib/python3.12
COPY --from=builder /usr/local/lib/libpython3.12.so.1.0 /usr/local/lib/libpython3.12.so.1.0
COPY --from=builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so

# Copy only the dependencies installation from the 1st stage image
COPY --from=builder /venv /venv

# Copy .env file with token (prod, dev)
COPY .env /opt/pytmbot

# Copy bot files
COPY ./app ./app/
# Copy bot log
COPY ./logs /opt/logs/

# Update base os components
Expand Down

0 comments on commit 2470e76

Please sign in to comment.