reduce Lambda asset size #442
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test and Deploy | |
# Triggers on pushes to main, dev and tags. | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
- dev | |
tags: | |
- 'v*' | |
paths: | |
# Only run test and docker publish if some code have changed | |
- 'pyproject.toml' | |
- 'infrastructure/aws/**' | |
- 'titiler/**' | |
- '.pre-commit-config.yaml' | |
# Run tests on pull requests. | |
pull_request: | |
env: | |
LATEST_PY_VERSION: '3.10' | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
jobs: | |
tests: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.9', '3.10', '3.11'] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install uv | |
uses: astral-sh/setup-uv@v3 | |
with: | |
version: "0.5.*" | |
enable-cache: true | |
- name: Set up Python ${{ matrix.python-version }} | |
run: uv python install ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
uv sync --all-extras | |
- name: run pre-commit | |
if: ${{ matrix.python-version == env.LATEST_PY_VERSION }} | |
run: | | |
uv run pre-commit run --all-files | |
- name: Run tests | |
run: uv run pytest | |
deploy: | |
needs: [tests] | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: infrastructure/aws | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: arn:aws:iam::444055461661:role/github-actions-role-eodc | |
role-session-name: samplerolesession | |
aws-region: us-west-2 | |
- name: Set up node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 18 | |
- name: Install uv | |
uses: astral-sh/setup-uv@v3 | |
with: | |
version: "0.5.*" | |
enable-cache: true | |
- name: Install dependencies | |
run: | | |
uv sync --only-group deployment | |
uv run npm install | |
- name: CDK Synth | |
run: uv run --only-group deployment npm run cdk -- synth | |
- name: Check Asset Sizes | |
run: | | |
MAX_SIZE_BYTES=262144000 # 262 MB in bytes | |
for dir in cdk.out/asset.*; do | |
if [ -d "$dir" ]; then | |
size=$(du -sb "$dir" | cut -f1) | |
if [ "$size" -gt $MAX_SIZE_BYTES ]; then | |
echo "Directory $dir exceeds 262 MB with size $size bytes (max: $MAX_SIZE_BYTES bytes)." | |
exit 1 # Exit with failure if any asset directory is too large | |
fi | |
echo "Asset directory $dir size: $size bytes" | |
fi | |
done | |
echo "All asset directories are within size limits." | |
# Build and deploy to the development environment whenever there is a push to main or dev | |
- name: Build & Deploy Development | |
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' | |
run: uv run npm run cdk -- deploy titiler-xarray-development --require-approval never | |
env: | |
TITILER_XARRAY_PYTHONWARNINGS: ignore | |
TITILER_XARRAY_DEBUG: True | |
STACK_ALARM_EMAIL: ${{ secrets.ALARM_EMAIL }} | |
STACK_STAGE: development | |
# Build and deploy to production deployment whenever there a new tag is pushed | |
- name: Build & Deploy Production | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: uv run npm run cdk -- deploy titiler-xarray-production --require-approval never | |
env: | |
TITILER_XARRAY_PYTHONWARNINGS: ignore | |
TITILER_XARRAY_DEBUG: True | |
STACK_ALARM_EMAIL: ${{ secrets.ALARM_EMAIL }} | |
STACK_STAGE: production |