|
1 | | -# AWS Example SAM Deploy: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/deploying-using-github.html |
2 | 1 | name: Deploy Lambda |
3 | 2 | on: |
4 | 3 | push: |
|
15 | 14 | - ".github/workflows/deploy_lambda.yml" |
16 | 15 |
|
17 | 16 | env: |
18 | | - DEPLOY_LAMBDA: "true" |
19 | 17 | STACK_NAME: api-python |
20 | 18 | AWS_REGION: us-east-2 |
21 | 19 | LOGGING_LEVEL: INFO |
|
24 | 22 | jobs: |
25 | 23 | sam-deploy: |
26 | 24 | runs-on: ubuntu-latest |
27 | | - if: ${{ env.DEPLOY_LAMBDA == 'true' }} |
28 | 25 | steps: |
29 | 26 | - uses: actions/checkout@v4 |
| 27 | + |
30 | 28 | - uses: actions/setup-python@v5 |
31 | 29 | with: |
32 | 30 | python-version: "3.12" |
33 | | - cache: "poetry" |
| 31 | + |
| 32 | + - name: Install and configure Poetry |
| 33 | + uses: snok/install-poetry@v1 |
| 34 | + with: |
| 35 | + version: 1.7.1 |
| 36 | + virtualenvs-create: true |
| 37 | + |
| 38 | + - name: Load cached dependencies |
| 39 | + id: cached-poetry-dependencies |
| 40 | + uses: actions/cache@v3 |
| 41 | + with: |
| 42 | + path: .venv |
| 43 | + key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} |
| 44 | + |
| 45 | + - name: Install dependencies |
| 46 | + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' |
| 47 | + run: poetry install --no-interaction |
| 48 | + |
34 | 49 | - name: Run tests |
35 | | - run: | |
36 | | - pip install poetry |
37 | | - poetry install --no-interaction |
38 | | - poetry run pytest |
| 50 | + run: poetry run pytest |
39 | 51 |
|
40 | | - - uses: aws-actions/configure-aws-credentials@v1 |
| 52 | + - uses: aws-actions/configure-aws-credentials@v4 |
41 | 53 | with: |
42 | 54 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
43 | 55 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
44 | 56 | aws-region: ${{ env.AWS_REGION }} |
45 | 57 |
|
| 58 | + - name: Login to Amazon ECR |
| 59 | + uses: aws-actions/amazon-ecr-login@v2 |
| 60 | + |
| 61 | + - name: Generate image tag |
| 62 | + id: image-tag |
| 63 | + run: | |
| 64 | + IMAGE_TAG=$(git rev-parse --short HEAD) |
| 65 | + echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV |
| 66 | +
|
46 | 67 | - name: Get ECR URI |
| 68 | + id: ecr-uri |
47 | 69 | run: | |
48 | 70 | REPO_URI=$(aws cloudformation describe-stacks \ |
49 | 71 | --stack-name ${{ env.STACK_NAME }} \ |
50 | 72 | --query 'Stacks[0].Outputs[?OutputKey==`RepositoryUri`].OutputValue' \ |
51 | 73 | --output text) |
| 74 | + if [ -z "$REPO_URI" ]; then |
| 75 | + echo "Failed to get ECR repository URI" |
| 76 | + exit 1 |
| 77 | + fi |
52 | 78 | echo "REPO_URI=${REPO_URI}" >> $GITHUB_ENV |
53 | 79 |
|
54 | | - - name: Login to Amazon ECR |
55 | | - uses: aws-actions/amazon-ecr-login@v1 |
56 | | - |
57 | | - - name: Generate image tag |
58 | | - run: | |
59 | | - IMAGE_TAG=$(git rev-parse --short HEAD) |
60 | | - echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV |
61 | | -
|
62 | 80 | - name: Build and push image |
63 | 81 | run: | |
64 | | - docker build -f deploy/docker/Dockerfile -t ${{ env.REPO_URI }}:${{ env.IMAGE_TAG }} . |
| 82 | + docker build -f deploy/aws_sam/Dockerfile -t ${{ env.REPO_URI }}:${{ env.IMAGE_TAG }} . |
65 | 83 | docker push ${{ env.REPO_URI }}:${{ env.IMAGE_TAG }} |
66 | 84 |
|
67 | 85 | - uses: aws-actions/setup-sam@v2 |
68 | | - - run: | |
| 86 | + |
| 87 | + - name: Deploy with SAM |
| 88 | + run: | |
69 | 89 | cd deploy/aws_sam |
70 | 90 | sam deploy \ |
| 91 | + --stack-name ${{ env.STACK_NAME }} \ |
71 | 92 | --no-confirm-changeset \ |
72 | 93 | --no-fail-on-empty-changeset \ |
73 | 94 | --parameter-overrides \ |
|
76 | 97 | Workers="${{ env.WORKERS }}" \ |
77 | 98 | PostgresUri="${{ secrets.POSTGRES_URI }}" \ |
78 | 99 | Neo4jUri="${{ secrets.NEO4J_URI }}" \ |
79 | | - Neo4jPassword="${{ secrets.NEO4J_PASSWORD }}" |
| 100 | + Neo4jPassword="${{ secrets.NEO4J_PASSWORD }}" \ |
0 commit comments