-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
138 lines (125 loc) · 4.89 KB
/
action.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
name: 'Docker pipeline'
description: 'Docker Build, AWS ECR Push and Kustomize step'
inputs:
app-name:
description: 'The app name'
required: true
argo-cd-sync:
description: 'Do you want to run the ArgoCD sync for this application in DEV environment?'
required: true
argo-cd-token:
description: 'The ArgoCD token to sync after Kustomize step'
required: false
argo-cd-url:
description: 'The ArgoCD URL to be used in application sync step'
required: false
aws-region:
description: 'AWS region name to assume role'
required: true
dockerfile-name:
description: 'The Dockerfile name'
default: 'Dockerfile'
required: true
k8s-manifest-repo-name:
description: 'The name of K8S manifests repository'
required: true
k8s-manifest-repo-url:
description: 'The URL of K8S manifests repository'
required: true
role-session-name:
description: 'The AWS Session name'
required: true
role-to-assume:
description: 'The AWS OICD role to assume'
required: true
service-github-token:
description: 'The service user token on Git Hub'
required: true
slack-webhook-url:
description: 'The webhook URL to send notifications to slack'
required: true
runs:
using: "composite"
steps:
- name: Configure AWS credentials from AWS account
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ inputs.role-to-assume }}
aws-region: ${{ inputs.aws-region }}
role-session-name: ${{ inputs.role-session-name }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'true'
- name: Get git repository informations
uses: LerianStudio/github-actions-git-informations@main
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
format: 'table'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
exit-code: '0'
- name: Build, tag, and push docker image to Amazon ECR
shell: bash
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ inputs.app-name }}
IMAGE_TAG: ${{ env.RELEASE_VERSION }}
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f ${{ inputs.dockerfile-name }} \
--build-arg GITHUB_USER_TOKEN=${{ inputs.service-github-token }} .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Enable Image Scanning on Push
shell: bash
run: |
aws ecr put-image-scanning-configuration \
--repository-name ${{ inputs.app-name }} \
--image-scanning-configuration scanOnPush=true \
--region ${{ inputs.aws-region }}
- name: Kustomize step
uses: LerianStudio/github-actions-kustomize-argocd-manifests@main
with:
app-name: ${{ inputs.app-name }}
app-registry: ${{ steps.login-ecr.outputs.registry }}
github-actor: ${{ github.actor }}
github-token: '${{ inputs.service-github-token }}'
k8s-manifest-repo-name: '${{ inputs.k8s-manifest-repo-name }}'
k8s-manifest-repo-url: '${{ inputs.k8s-manifest-repo-url }}'
- name: ArgoCD Sync - DEV
if: ${{ env.GITOPS_BRANCH == 'develop' && inputs.argo-cd-sync == true }}
uses: LerianStudio/github-actions-argocd-sync@main
with:
app-name: ${{ inputs.app-name }}
env-prefix: 'dev'
argo-cd-token: ${{ inputs.argo-cd-token }}
argo-cd-url: ${{ inputs.argo-cd-url }}
- name: Slack Notification - failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ inputs.slack-webhook-url }}
SLACK_COLOR: ${{job.status}}
SLACK_USERNAME: GitHub Actions
SLACK_ICON: https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png
SLACK_MESSAGE: 'Deploy da aplicação *${{ inputs.app-name }}* falhou :fire:'
- name: Slack Notification - success
if: ${{ success() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ inputs.slack-webhook-url }}
SLACK_COLOR: ${{job.status}}
SLACK_USERNAME: GitHub Actions
SLACK_ICON: https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png
SLACK_MESSAGE: 'Deploy da aplicação *${{ inputs.app-name }}* realizado com sucesso :rocket:'
- name: Slack Notification - success
if: ${{ success() && env.GITOPS_BRANCH == 'main' }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ inputs.slack-webhook-url }}
SLACK_COLOR: ${{job.status}}
SLACK_USERNAME: GitHub Actions
SLACK_ICON: https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png
SLACK_MESSAGE: 'PR aberto no repositório de GitOps para deploy da aplicação *${{ inputs.app-name }}* em PRODUÇÃO, revisar e fazer merge do PR.'