Build and Deploy Lithops Runtime #10
This file contains hidden or 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: Build and Deploy Lithops Runtime | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'Dockerfile' | |
| - '.lithops/config' | |
| workflow_dispatch: | |
| permissions: | |
| id-token: write | |
| contents: read | |
| env: | |
| PYTHON_VERSION: '3.12' | |
| RUNTIME_NAME: 'cubed-runtime' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Read AWS region from config | |
| id: config | |
| run: | | |
| region=$(python3 -c " | |
| import yaml | |
| with open('.lithops/config') as f: | |
| c = yaml.safe_load(f) | |
| print(c['aws']['region'].strip()) | |
| ") | |
| echo "region=$region" >> $GITHUB_OUTPUT | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
| aws-region: ${{ steps.config.outputs.region }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install Lithops | |
| run: pip install 'lithops[aws]' | |
| - name: Copy Lithops config | |
| run: | | |
| mkdir -p ~/.lithops | |
| cp .lithops/config ~/.lithops/config | |
| - name: Delete existing runtime | |
| run: lithops runtime delete -d ${{ env.RUNTIME_NAME }} -b aws_lambda | |
| - name: Build runtime | |
| run: lithops runtime build ${{ env.RUNTIME_NAME }} -b aws_lambda -f Dockerfile | |
| - name: Grant Lambda access to ECR repository | |
| run: | | |
| set -euo pipefail | |
| runtime="${{ env.RUNTIME_NAME }}" | |
| repo=$(aws ecr describe-repositories \ | |
| --query 'repositories[].repositoryName' \ | |
| --output text | tr '\t' '\n' | grep "$runtime" | head -1) | |
| echo "Setting ECR policy on: $repo" | |
| aws ecr set-repository-policy \ | |
| --repository-name "$repo" \ | |
| --policy-text '{ | |
| "Version": "2012-10-17", | |
| "Statement": [{ | |
| "Sid": "LambdaECRAccess", | |
| "Effect": "Allow", | |
| "Principal": {"Service": "lambda.amazonaws.com"}, | |
| "Action": ["ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer"] | |
| }] | |
| }' | |
| - name: Deploy runtime | |
| run: lithops runtime deploy ${{ env.RUNTIME_NAME }} -b aws_lambda |