generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (74 loc) · 2.87 KB
/
build_and_push.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
name: Build and Push Container to ECR, deploy to lambda
on:
workflow_dispatch:
push:
branches: [main]
env:
GITHUB_SHA: ${{ github.sha }}
REGISTRY: ${{ secrets.AWS_ACCOUNT }}.dkr.ecr.ca-central-1.amazonaws.com/list-manager
jobs:
changes:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.filter.outputs.changes }}
steps:
- name: Checkout
uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6 # v2.6.0
- uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
id: filter
with:
filters: |
api: 'api/**'
build-push-and-deploy:
if: needs.changes.outputs.images != '[]'
runs-on: ubuntu-latest
needs: changes
strategy:
fail-fast: false
matrix:
image: ${{ fromJSON(needs.changes.outputs.images) }}
steps:
- name: Checkout
uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6 # v2.6.0
- name: Build container
working-directory: ./${{ matrix.image }}
run: |
docker build \
--build-arg git_sha=$GITHUB_SHA \
-t $REGISTRY/${{ matrix.image }}:$GITHUB_SHA \
-t $REGISTRY/${{ matrix.image }}:latest .
- name: Configure AWS credentials
id: aws-creds
uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838 # v1.7.0
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ca-central-1
- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@261a7de32bda11ba01f4d75c4ed6caf3739e54be # v1.5.3
- name: Push containers to ECR
run: |
docker push $REGISTRY/${{ matrix.image }}:$GITHUB_SHA
docker push $REGISTRY/${{ matrix.image }}:latest
- name: Logout of Amazon ECR
run: docker logout ${{ steps.login-ecr.outputs.registry }}
- name: Deploy lambda
if: matrix.image == 'api' || contains(matrix.image, 'scanners')
run: |
FNAME=$(sed 's/\//-/g' <<< "${{ matrix.image }}")
aws lambda update-function-code \
--function-name "$FNAME" \
--image-uri $REGISTRY/${{ matrix.image }}:latest > /dev/null 2>&1
- name: Migrate Database
if: matrix.image == 'api'
run: |
source .github/workflows/scripts/migrate.sh
migrate
- name: Generate list-manager/${{ matrix.image }}/docker SBOM
uses: cds-snc/security-tools/.github/actions/generate-sbom@f0d609b2a8f51dbb4b1760b02a35fb1aadbae7f1 # v1.1.6
with:
dependency_track_api_key: ${{ secrets.DEPENDENCY_TRACK_API_KEY }}
docker_image: $REGISTRY/${{ matrix.image }}:$GITHUB_SHA
project_name: list-manager/${{ matrix.image }}/docker
project_type: docker