-
Notifications
You must be signed in to change notification settings - Fork 1
126 lines (108 loc) · 4.92 KB
/
build_and_deploy.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Build, Push and Deploy Docker Image
on:
pull_request:
types:
- closed
jobs:
build-push-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Find changed lambda
id: find-lambda
run: |
echo "CHANGED_LAMBDA=$(git diff --name-only HEAD^ HEAD | grep '^lambdas/' | sed 's/lambdas\///' | sed 's/\/.*//' | sort | uniq)" >> $GITHUB_ENV
- name: Print variables
if: ${{ env.CHANGED_LAMBDA != '' }}
run: |
echo "Changed lambda: ${{ env.CHANGED_LAMBDA }}"
- name: Configure AWS credentials for dev
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
aws-region: eu-west-2
- name: Login to Amazon ECR in dev
if: ${{ env.CHANGED_LAMBDA != '' }}
id: login-ecr-dev
uses: aws-actions/amazon-ecr-login@v1
- name: Build and tag Docker images in dev
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: docker/build-push-action@v4
with:
context: lambdas/${{ env.CHANGED_LAMBDA }}/
platforms: linux/amd64
push: true
tags: ${{ steps.login-ecr-dev.outputs.registry }}/${{ env.CHANGED_LAMBDA }}:latest
- name: Update Lambda function in dev
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: appleboy/lambda-action@master
continue-on-error: true # Set to true because Lambdas will go "idle" if not invoked for a while and this make Github Actions fail
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
aws_region: eu-west-2
function_name: ${{ env.CHANGED_LAMBDA }}
image_uri: ${{ steps.login-ecr-dev.outputs.registry }}/${{ env.CHANGED_LAMBDA }}:latest
- name: Configure AWS credentials in test
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST }}
aws-region: eu-west-2
- name: Login to Amazon ECR in test
if: ${{ env.CHANGED_LAMBDA != '' }}
id: login-ecr-test
uses: aws-actions/amazon-ecr-login@v1
- name: Build and tag Docker image in test
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: docker/build-push-action@v4
with:
context: lambdas/${{ env.CHANGED_LAMBDA }}/
platforms: linux/amd64
push: true
tags: ${{ steps.login-ecr-test.outputs.registry }}/${{ env.CHANGED_LAMBDA }}:latest
- name: Update Lambda function in test
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: appleboy/lambda-action@master
continue-on-error: true # Set to true because Lambdas will go "idle" if not invoked for a while and this make Github Actions fail
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST }}
aws_region: eu-west-2
function_name: ${{ env.CHANGED_LAMBDA }}
image_uri: ${{ steps.login-ecr-test.outputs.registry }}/${{ env.CHANGED_LAMBDA }}:latest
- name: Configure AWS credentials in preprod
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PREPROD }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PREPROD }}
aws-region: eu-west-2
- name: Login to Amazon ECR in preprod
if: ${{ env.CHANGED_LAMBDA != '' }}
id: login-ecr-preprod
uses: aws-actions/amazon-ecr-login@v1
- name: Build and tag Docker image in preprod
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: docker/build-push-action@v4
with:
context: lambdas/${{ env.CHANGED_LAMBDA }}/
platforms: linux/amd64
push: true
tags: ${{ steps.login-ecr-preprod.outputs.registry }}/${{ env.CHANGED_LAMBDA }}:latest
- name: Update Lambda function in preprod
if: ${{ env.CHANGED_LAMBDA != '' }}
uses: appleboy/lambda-action@master
continue-on-error: true # Set to true because Lambdas will go "idle" if not invoked for a while and this make Github Actions fail
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_PREPROD }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PREPROD }}
aws_region: eu-west-2
function_name: ${{ env.CHANGED_LAMBDA }}
image_uri: ${{ steps.login-ecr-preprod.outputs.registry }}/${{ env.CHANGED_LAMBDA }}:latest