Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Git
.git
.gitignore
.gitlab-ci.yml

# AWS SAM build artifacts
.aws-sam/
**/.aws-sam/

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
.venv/
*.egg-info/
dist/
build/
*.egg

# IDE
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store

# Documentation
docs/
*.md
LICENSE
NOTICE
CONTRIBUTING.md
CHANGELOG.md

# Test files
tests/
**/tests/
**/test_*.py
**/*_test.py
pytest.ini
.coverage
htmlcov/

# Node (for UI components)
node_modules/
npm-debug.log
yarn-error.log

# Temporary files
*.log
*.tmp
*.temp
.cache/
tmp/
temp/

# Build scripts and configs
samconfig*.toml
template.yaml
template-*.yaml
Makefile
publish.py
publish_container*.py
deploy*.py
update_templates.py

# Notebooks and samples
notebooks/
samples/

# CloudFormation packaged templates
**/*.packaged.yaml
**/packaged.yaml

# Docker files we don't need in context
Dockerfile*
docker-compose*.yml

# Other unnecessary files for Lambda
images/
scripts/
memory-bank/
*.xlsx
*.pdf
*.png
*.jpg
*.jpeg
*.gif
*.ico

# Keep only source code and requirements
!patterns/*/src/**
!lib/idp_common_pkg/**
!src/lambda/**
44 changes: 44 additions & 0 deletions Dockerfile.optimized
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Optimized Dockerfile for Lambda functions with minimal dependencies
# This builds each function with ONLY the dependencies it needs

FROM public.ecr.aws/lambda/python:3.12-arm64 AS builder

# Copy uv from official distroless image
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Build argument for function path
ARG FUNCTION_PATH
ARG INSTALL_IDP_COMMON=true

# Create working directory
WORKDIR /build

# Copy idp_common_pkg and requirements for installation
COPY lib/idp_common_pkg /tmp/idp_common_pkg
COPY ${FUNCTION_PATH}/requirements.txt* /build/

# Install all dependencies including idp_common_pkg in one step
# Note: sed -E works cross-platform because Docker builds run inside Linux container (GNU sed 4.8+)
RUN --mount=type=cache,target=/root/.cache/uv \
if [ -f /build/requirements.txt ]; then \
sed -E 's|^\.\./(\.\./)*lib/idp_common_pkg|/tmp/idp_common_pkg|' /build/requirements.txt > /tmp/requirements.txt && \
uv pip install --python python3.12 --target /opt/python -r /tmp/requirements.txt && \
rm /tmp/requirements.txt; \
fi && \
rm -rf /tmp/idp_common_pkg

# Final stage - minimal runtime
FROM public.ecr.aws/lambda/python:3.12-arm64

# Copy only the installed packages
COPY --from=builder /opt/python /opt/python

# Copy function code
ARG FUNCTION_PATH
COPY ${FUNCTION_PATH}/*.py ${LAMBDA_TASK_ROOT}/

# Set Python path
ENV PYTHONPATH=/opt/python:${LAMBDA_TASK_ROOT}

# Set handler
CMD ["index.handler"]
Loading