-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (56 loc) · 1.75 KB
/
buildAndPushImage.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
name: Build and push image to ECR
on:
workflow_call:
inputs:
awsRegion:
type: string
required: false
default: eu-west-1
ecrRepositoryName:
type: string
required: true
directoryPath:
type: string
required: true
imageTag:
type: string
required: false
default: latest
secrets:
awsAccessKeyId:
required: true
awsSecretKey:
required: true
dockerHubUsername:
required: true
dockerHubAccessToken:
required: true
defaults:
run:
shell: bash
jobs:
buildAndPushImage:
name: Build and push image to ECR
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@13d241b293754004c80624b5567555c4a39ffbe3
with:
aws-access-key-id: ${{ secrets.awsAccessKeyId }}
aws-secret-access-key: ${{ secrets.awsSecretKey }}
aws-region: ${{ inputs.awsRegion }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@aaf69d68aa3fb14c1d5a6be9ac61fe15b48453a2
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.dockerHubUsername }}
password: ${{ secrets.dockerHubAccessToken }}
- name: Build, tag, and push image to Amazon ECR
working-directory: ${{ inputs.directoryPath }}
run: |
docker build -t ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecrRepositoryName }}:${{ inputs.imageTag }} .
docker push ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecrRepositoryName }}:${{ inputs.imageTag }}