does this build

This commit is contained in:
Jun-te Kim 2025-07-18 16:22:27 +00:00
parent 39a1eb29d5
commit 72b5b60b20

View file

@ -1,49 +1,41 @@
# ----------- Build Stage (with Poetry) -----------
FROM python:3.12-slim as builder
# ---------- Stage 1: Build (Poetry) ----------
FROM public.ecr.aws/lambda/python:3.12 as builder
ENV PIP_NO_CACHE_DIR=1
ENV PATH="/root/.local/bin:$PATH" \
PIP_NO_CACHE_DIR=1 \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Install Poetry
RUN pip install poetry
RUN curl -sSL https://install.python-poetry.org | python3 -
# Set working directory
WORKDIR /app
# Copy Poetry files and your source code
# Copy poetry config and install deps
COPY pyproject.toml poetry.lock ./
RUN poetry config virtualenvs.create false \
&& poetry install --only main --no-interaction --no-ansi \
&& rm -rf ~/.cache
# Copy source code
COPY etl/ etl/
COPY deployment/lambda/extractor_and_loader/docker/app.py .
# Export main dependencies
RUN poetry export -f requirements.txt --without-hashes --only main -o requirements.txt
# Install into /python (Lambda expects this structure)
RUN pip install --no-deps -r requirements.txt --target /python
# Optionally: strip cache, pyc, and tests to reduce size
RUN find /python -type d -name "tests" -exec rm -rf {} + \
&& find /python -type f -name "*.pyc" -delete
# ----------- Runtime Stage (Slim and Clean) -----------
# ---------- Stage 2: Runtime (Slim + RIC) ----------
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
# Install Lambda RIC
# Install AWS Lambda Runtime Interface Client
RUN pip install awslambdaric
# Copy installed dependencies and app code from builder
COPY --from=builder /python /var/task
COPY --from=builder /app/etl /var/task/etl
# Set working directory
WORKDIR /var/task
# Copy Lambda handler
COPY deployment/lambda/extractor_and_loader/docker/app.py .
# Copy minimal runtime files from builder
COPY --from=builder /app /var/task
# Set Lambda entrypoint and handler
# Lambda entrypoint
ENTRYPOINT ["python3", "-m", "awslambdaric"]
CMD ["app.handler"]