-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (79 loc) · 3.46 KB
/
main.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
89
90
91
92
name: Build Spring Application and Push to ECR
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: '17'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Spring Application with Secrets
env:
SPRING_DATASOURCE_URL: ${{ secrets.SPRING_DATASOURCE_URL }}
SPRING_DATASOURCE_USERNAME: ${{ secrets.SPRING_DATASOURCE_USERNAME }}
SPRING_DATASOURCE_PASSWORD: ${{ secrets.SPRING_DATASOURCE_PASSWORD }}
run: ./gradlew clean bootJar
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.INFRA_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.INFRA_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Log in to Amazon ECR
run: aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin "${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com"
- name: Generate image tag
id: get_version
run: echo "version=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_OUTPUT
- name: Build and Push Docker Image
env:
ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com
ECR_REPOSITORY: aiwa-project/member
IMAGE_TAG: ${{ steps.get_version.outputs.version }}
run: |
docker build \
--build-arg AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \
--build-arg AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \
--build-arg SPRING_DATASOURCE_URL="${{ secrets.SPRING_DATASOURCE_URL }}" \
--build-arg SPRING_DATASOURCE_USERNAME="${{ secrets.SPRING_DATASOURCE_USERNAME }}" \
--build-arg SPRING_DATASOURCE_PASSWORD="${{ secrets.SPRING_DATASOURCE_PASSWORD }}" \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
. && \
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG && \
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Checkout Helm chart repository
uses: actions/checkout@v3
with:
repository: AWS-Cloud-School-6/AIWA-MCP-Helm
path: AIWA-MCP-Helm
token: ${{ secrets.PAT_AIWA_MEMBER_TOKEN }}
- name: Update Helm chart
run: |
cd AIWA-MCP-Helm/aiwa-member
if [ ! -f values.yaml ]; then
echo "Error: values.yaml not found in $(pwd)"
exit 1
fi
sed -i "s|tag: .*|tag: \"${{ steps.get_version.outputs.version }}\"|" values.yaml
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add values.yaml
if git diff --staged --quiet; then
echo "No changes to commit in values.yaml"
else
git commit -m "Update image tag to ${{ steps.get_version.outputs.version }}"
git push || { echo "Failed to push changes"; exit 2; }
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}