-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (74 loc) · 2.88 KB
/
aws.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
name: Build and Push Docker Image to ECR
on:
push:
branches:
- main
- develop
- fix/github-action
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Build JAR
run: ./gradlew build -x test
- name: Determine ECR Repository
id: ecr_repo
run: |
REPO_NAME="auth"
echo "repo=${REPO_NAME}" >> $GITHUB_OUTPUT
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "environment=prod" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
echo "environment=stag" >> $GITHUB_OUTPUT
else
echo "environment=stag" >> $GITHUB_OUTPUT
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Docker Build and Push
run: |
docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }} .
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }}
- name: Checkout Private Repository
uses: actions/checkout@v4
with:
repository: NTF-marketplace/devops
fetch-depth: 0
ref: develop
token: ${{ secrets.PAT }}
- name: Replace image tag in helm values (LOCAL)
uses: mikefarah/yq@master
env:
IMAGE_TAG: ${{ github.sha }}
with:
cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}/values.yaml'
- name: Commit helm chart changes
env:
IMAGE_TAG: ${{ github.sha }}
run: |
cd chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}
git config --global user.email "[email protected]"
git config --global user.name "dongdorrong"
git add values.yaml
git commit --message "ci: update ${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }} image tag to $IMAGE_TAG"
- name: Push commit
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT }}
repository: NTF-marketplace/devops
branch: develop