-
Notifications
You must be signed in to change notification settings - Fork 2
88 lines (74 loc) · 2.74 KB
/
main-build.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: Docker build and push to repository
on:
push:
branches:
- main
jobs:
main_build_image:
permissions:
actions: write
runs-on: ubuntu-latest
outputs:
shortref: ${{ steps.prep.outputs.shortref }}
tags: ${{ steps.prep.outputs.tags }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.ECR_PUBLIC_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.ECR_PUBLIC_SECRET_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Prepare
id: prep
env:
ECR_REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
ECR_REGISTRY_ALIAS: d6h3d6x3
ECR_REPOSITORY: amboss-banco
run: |
DOCKER_IMAGE=$ECR_REGISTRY/$ECR_REGISTRY_ALIAS/$ECR_REPOSITORY
SHORTREF=${GITHUB_SHA::8}
TAGS="${DOCKER_IMAGE}:${SHORTREF}"
# Set output parameters.
echo "shortref=${SHORTREF}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
- name: Check Image
id: image_check
env:
ECR_TAG: ${{ steps.prep.outputs.tags }}
run: docker manifest inspect $ECR_TAG && echo "imageExists=true" >> $GITHUB_OUTPUT || echo "imageExists=false" >> $GITHUB_OUTPUT
- name: Setup Docker Buildx Driver
id: docker_driver_setup
if: ${{ steps.image_check.outputs.imageExists == 'false' }}
uses: docker/setup-buildx-action@v3
- name: Build, tag, and push image to Amazon ECR
id: docker_build
if: ${{ steps.image_check.outputs.imageExists == 'false' }}
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build Outputs
if: ${{ steps.image_check.outputs.imageExists == 'false' }}
run: |
echo "Image ID: ${{ steps.docker_build.outputs.imageid }}"
echo "Image Digest: ${{ steps.docker_build.outputs.digest }}"
- name: Trigger Deployment
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
# Set the required variables
repo_owner="AmbossTech"
repo_name="amboss-banco-ci"
event_type="trigger-workflow"
gh workflow -R $repo_owner/$repo_name -r main run deploy-banco-prod.yaml -f tag=${{ steps.prep.outputs.shortref }}