Skip to content

Merge pull request #37 from AWS-Cloud-School-6/36-feat-credential-경로-변경 #4

Merge pull request #37 from AWS-Cloud-School-6/36-feat-credential-경로-변경

Merge pull request #37 from AWS-Cloud-School-6/36-feat-credential-경로-변경 #4

Workflow file for this run

# Docker Hub에 푸시하는 워크플로우-test-v10
name: Build and Push Docker Image to Docker Hub
on:
push:
# paths-ignore:
# - ".github/workflows/**"
branches:
- main
jobs:
ci-build:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.get_version.outputs.version }}
steps:
# 1. GitHub 저장소의 코드를 체크아웃
- name: Check out the repository
uses: actions/checkout@v4
# 2. JDK 17 설치
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: "temurin"
java-version: "17"
# 3. Gradle Wrapper에 실행 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# 4. Gradle로 빌드
- name: Build with Gradle
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: ./gradlew clean bootJar
# 5. 이미지 태그 생성 (날짜-시간 형식으로 변경)
- name: Generate image tag
id: get_version
run: echo "::set-output name=version::$(date +'%Y%m%d-%H%M%S')"
# 6. AWS 자격 증명 구성
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.INFRA_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.INFRA_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
# 7. AWS ECR login
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# 8. Docker 이미지를 빌드
- name: Build the Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: aiwa-project/aiwa-gcp
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 .
# 9. AWS ECR에 푸시
- name: Push Docker image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: aiwa-project/aiwa-gcp
IMAGE_TAG: ${{ steps.get_version.outputs.version }}
run: |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
# 10. Helm 차트 저장소 체크아웃
- name: Checkout Helm chart repository
uses: actions/checkout@v4
with:
repository: AWS-Cloud-School-6/AIWA-MCP-Helm # Helm 차트 저장소 URL로 변경하세요
path: AIWA-MCP-Helm
token: ${{ secrets.PAT_AIWA_APP_TOKEN }} # 개인 액세스 토큰이 필요할 수 있습니다
# 11. Helm 차트 업데이트
- name: Update Helm chart
run: |
cd AIWA-MCP-Helm/aiwa-gcp
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 1; }
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}