-
Notifications
You must be signed in to change notification settings - Fork 1
101 lines (90 loc) · 3.18 KB
/
build-push.yaml
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
name: "Build & Push"
on:
push:
branches:
- "develop"
- "hotfix/*"
tags:
- "*"
paths:
- "packages/**"
- "!packages/*/scripts/**"
- ".github/workflows/build-push.yaml"
jobs:
find_dockerfiles:
name: Find Dockerfiles
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.set_packages_output.outputs.packages }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Find packages
id: set_packages_output
run: |
PACKAGES=$(find packages -type f -path "*/Dockerfile" | awk -F'/' '{print $2}' | jq -R -s -c 'split("\n")[:-1]')
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
build_push_image:
name: ${{ matrix.package }}
needs: [find_dockerfiles]
runs-on: ubuntu-latest
environment: dev
permissions:
contents: read
id-token: write
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.find_dockerfiles.outputs.packages) }}
env:
DOCKER_BUILD_SUMMARY: "false"
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ vars.IAM_ROLE_ARN }}
role-session-name: be-monorepo-build-push-${{ github.run_number }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2
- name: Normalize ref name
id: norm_ref
run: |
set -euo pipefail
NORM_REF="$(echo ${{ github.ref_name }} | sed -e 's/\//-/g')"
echo "NORM_REF=$NORM_REF" >> $GITHUB_ENV
- name: (branch) Docker metadata
id: meta_branch
if: ${{ github.ref_type == 'branch' }}
uses: docker/metadata-action@60a0d343a0d8a18aedee9d34e62251f752153bdb
with:
images: ${{ steps.login-ecr.outputs.registry }}/interop-be-${{ matrix.package }}
flavor: |
latest=false
prefix=
suffix=
tags: |
type=raw,value=${{ env.NORM_REF }}
- name: (tag) Docker metadata
id: meta_tag
if: ${{ github.ref_type == 'tag' }}
uses: docker/metadata-action@60a0d343a0d8a18aedee9d34e62251f752153bdb
with:
images: ${{ steps.login-ecr.outputs.registry }}/interop-be-${{ matrix.package }}
flavor: |
latest=false
prefix=
suffix=
tags: |
type=ref,event=tag
- name: Build and push Docker image
id: build_push
uses: docker/build-push-action@a8d35412fb758de9162fd63e3fa3f0942bdedb4d
with:
context: .
file: packages/${{ matrix.package }}/Dockerfile
push: true
tags: ${{ github.ref_type == 'branch' && steps.meta_branch.outputs.tags || steps.meta_tag.outputs.tags }}
labels: ${{ github.ref_type == 'branch' && steps.meta_branch.outputs.labels || steps.meta_tag.outputs.labels }}