-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (143 loc) · 4.7 KB
/
deploy-to-ecr.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Build Docker image and push
on:
workflow_call:
inputs:
aws_account_id:
required: true
description: Destination AWS Account
type: string
environment:
required: true
description: "Build environment, effects image tag prefix."
type: string
runs-on:
required: false
description: 'Platform to execute on. Default ["self-hosted", "cere-io-large"]'
type: string
default: '["self-hosted", "cere-io-large"]'
aws_region:
required: false
description: "Destination AWS region. Default us-west-2"
type: string
default: 'us-west-2'
file:
required: false
description: "Path to the Dockerfile. Default: ./Dockerfile"
type: string
default: './Dockerfile'
context:
required: false
description: "Build's context. Defaults ./"
type: string
default: './'
repository:
required: false
description: "Image repository. Defaults to github repository name."
type: string
default: ${{ github.event.repository.name }}
custom_tag:
required: false
description: "Additional custom tag for the built docker image."
type: string
default: ''
build_artifact:
required: false
description: "Additional Persistent artifact from another job."
type: string
default: ''
configure_host_command:
required: false
description: "Additional command to configure host"
type: string
default: ''
timeout:
required: false
description: "Timeout in minutes for the job execution. Defaults 15."
type: number
default: 15
tmate_on:
required: false
description: ''
type: boolean
default: false
secrets:
NPM_TOKEN:
required: false
DB_PASSWORD:
required: false
DB_USER:
required: false
DOCKERHUB_USERNAME:
required: false
DOCKERHUB_TOKEN:
required: false
outputs:
version:
description: Docker image tag.
value: ${{ jobs.deploy-to-ecr.outputs.version }}
jobs:
deploy-to-ecr:
name: Build docker image, push to ECR.
runs-on: ${{ fromJSON(inputs.runs-on) }}
permissions:
contents: read
id-token: write
timeout-minutes: ${{ inputs.timeout }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
if: ${{ inputs.artifact != '' }}
with:
name: ${{ inputs.build_artifact }}
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::${{ inputs.aws_account_id }}:role/github
role-session-name: ${{ github.event.repository.name }}
aws-region: ${{ inputs.aws_region }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Configure host
if: ${{ inputs.configure_host_command != '' }}
run: ${{ inputs.configure_host_command }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_READ }}
- name: Setup tmate session
if: ${{ inputs.tmate_on }}
uses: mxschmitt/action-tmate@v3
with:
detached: true
limit-access-to-actor: false
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Process version
id: version
run: |
echo "image_tag=${{ inputs.environment }}-${{ github.run_attempt}}-$(git rev-parse --short HEAD)" >> "$GITHUB_ENV"
- name: Custom image tag
if: ${{ inputs.custom_tag != '' }}
run: |
echo "custom_image_full_tag=${{ steps.login-ecr.outputs.registry }}/${{ inputs.repository }}:${{ inputs.custom_tag }}" >> "$GITHUB_ENV"
- name: Build and push docker image to ECR
uses: docker/build-push-action@v3
with:
context: ${{ inputs.context }}
file: ${{ inputs.file }}
push: true
no-cache: true
build-args: |
NPM_TOKEN=${{ secrets.NPM_TOKEN_READ }}
ENV_FILE_NAME=${{ inputs.environment }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
DB_USER=${{ secrets.DB_USER }}
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ inputs.repository }}:${{ env.image_tag }}
${{ env.custom_image_full_tag }}
outputs:
version: ${{ env.image_tag }}