|
| 1 | +name: Deploy Python Lambda |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ['main'] |
| 6 | + paths: ['src/backend/**'] |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + AWS_REGION: us-east-2 |
| 11 | + ECR_REPOSITORY: mdst/mini-copilot |
| 12 | + CONTAINER_NAME: mini-copilot |
| 13 | + LAMBDA_FUNCTION_NAME: mini-copilot-lambda |
| 14 | + |
| 15 | +jobs: |
| 16 | + deploy: |
| 17 | + name: Deploy |
| 18 | + runs-on: ubuntu-latest |
| 19 | + environment: production |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Configure AWS credentials |
| 26 | + uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83 |
| 27 | + with: |
| 28 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 29 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 30 | + aws-region: ${{ env.AWS_REGION }} |
| 31 | + |
| 32 | + - name: Login to Amazon ECR |
| 33 | + id: login-ecr |
| 34 | + uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a |
| 35 | + |
| 36 | + - name: Build, tag, and push image to Amazon ECR |
| 37 | + id: build-image |
| 38 | + working-directory: ./src/backend |
| 39 | + env: |
| 40 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 41 | + IMAGE_TAG: ${{ github.sha }} |
| 42 | + run: | |
| 43 | + # Build a docker container and push it to ECR |
| 44 | + aws s3 cp s3://mini-copilot/trained/ ./trained --recursive |
| 45 | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . |
| 46 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 47 | + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT |
| 48 | +
|
| 49 | + - name: Update Lambda Function |
| 50 | + run: | |
| 51 | + aws lambda update-function-code --function-name ${{ env.LAMBDA_FUNCTION_NAME }} \ |
| 52 | + --region ${{ env.AWS_REGION }} \ |
| 53 | + --image-uri ${{ steps.build-image.outputs.image }} |
0 commit comments