-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (66 loc) · 2.51 KB
/
Copy pathdeploy-lambda-function.yaml
File metadata and controls
82 lines (66 loc) · 2.51 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
name: Deploy Lambda Function
on:
workflow_call:
secrets:
ACCOUNT_ID:
required: true
permissions:
contents: read
packages: read
id-token: write
jobs:
deploy-lambda:
runs-on: ubuntu-latest
env:
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
steps:
- uses: actions/checkout@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set image tags
id: meta
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
echo "[+] Current tags: ${VERSION}, latest"
echo "tags=${VERSION},latest" >> $GITHUB_OUTPUT
else
echo "[+] Current tag: latest"
echo "tags=latest" >> $GITHUB_OUTPUT
fi
- name: Pull Lambda container image
run: |
TAGS="${{ steps.meta.outputs.tags }}"
PRIMARY_TAG=$(echo "$TAGS" | cut -d',' -f1)
docker pull ghcr.io/bblue530/repovault_lambda:$PRIMARY_TAG
- name: Configure AWS credentials via OIDC
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.ACCOUNT_ID }}:role/repovault-github-ci-cd-deploy-upload-oidc-role
aws-region: eu-north-1
- name: Push image to ECR and Update Lambda
run: |
TAGS="${{ steps.meta.outputs.tags }}"
PRIMARY_TAG=$(echo "$TAGS" | cut -d',' -f1)
IFS=',' read -ra TAG_ARRAY <<< "$TAGS"
aws ecr describe-repositories --repository-names repovault_lambda || \
aws ecr create-repository --repository-name repovault_lambda
docker login \
--username AWS \
--password $(aws ecr get-login-password --region eu-north-1) \
$ACCOUNT_ID.dkr.ecr.eu-north-1.amazonaws.com
for TAG in "${TAG_ARRAY[@]}"; do
echo "[+] Tagging and pushing: $TAG"
docker tag \
ghcr.io/bblue530/repovault_lambda:$PRIMARY_TAG \
$ACCOUNT_ID.dkr.ecr.eu-north-1.amazonaws.com/repovault_lambda:$TAG
docker push \
$ACCOUNT_ID.dkr.ecr.eu-north-1.amazonaws.com/repovault_lambda:$TAG
done
aws lambda update-function-code \
--function-name repovault_lambda \
--image-uri $ACCOUNT_ID.dkr.ecr.eu-north-1.amazonaws.com/repovault_lambda:$PRIMARY_TAG