Repository navigation
84 lines (70 loc) · 2.32 KB
/
Copy pathlambda-code-evaluator-v2.yml
File metadata and controls
84 lines (70 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Build and Push to Amazon ECR
on:
push:
branches:
- main
paths:
- 'lambda-code-evaluator-v2/**'
- '!lambda-code-evaluator-v2/README.md'
- '.github/workflows/lambda-code-evaluator-v2.yml'
jobs:
lint-and-format:
name: Lint and Format Code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install Black and Flake8
run: |
pip install black flake8
- name: Run Black (Auto-format)
run: |
black lambda-code-evaluator-v2 --check
- name: Run Flake8 (Linting)
run: |
flake8 lambda-code-evaluator-v2
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: lambda-code-evaluator-v2
needs: lint-and-format
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: lambda-code-evaluator-v2
IMAGE_TAG: ${{ github.sha }}
run: |
echo "Building image..."
docker build -t $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG .
echo "Pushing image..."
docker push $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Update Lambda Function
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: lambda-code-evaluator-v2
IMAGE_TAG: ${{ github.sha }}
run: |
echo "Updating Lambda function..."
aws lambda update-function-code \
--function-name docker-code-evaluator-v2 \
--image-uri $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Log out of Amazon ECR
if: always()
run: docker logout ${{ steps.login-ecr.outputs.registry }}