From 36351a01064afc0358e19a7cfb47721b185e7723 Mon Sep 17 00:00:00 2001 From: lowCost Date: Sun, 30 Nov 2025 22:36:40 +0900 Subject: [PATCH] 2025-11-30 home --- .github/workflows/ci-petclinic.yml | 98 ++++++++++++++++++++++++++++++ pom.xml | 6 +- 2 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci-petclinic.yml diff --git a/.github/workflows/ci-petclinic.yml b/.github/workflows/ci-petclinic.yml new file mode 100644 index 000000000..20b30c172 --- /dev/null +++ b/.github/workflows/ci-petclinic.yml @@ -0,0 +1,98 @@ +name: CI - Petclinic EKS + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +# 공통 ENV (필요에 따라 GitHub Variables 대신 여기서 관리 가능) +env: + AWS_REGION: ${{ vars.AWS_REGION || 'ap-northeast-2' }} + ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY || 'eks/petclinic' }} + +jobs: + # 1) Maven 빌드 + 테스트 + build-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + cache: 'maven' + + - name: Maven build & test + run: | + if [ -x "./mvnw" ]; then + ./mvnw -B clean test package + else + mvn -B clean test package + fi + + - name: Archive built JAR (optional) + uses: actions/upload-artifact@v4 + with: + name: petclinic-jar + path: target/*.jar + + # 2) Docker 이미지 빌드 + ECR Push + build-and-push-image: + needs: build-test + runs-on: ubuntu-latest + + # GitHub OIDC로 AWS Role Assume 하려면 필수 + permissions: + id-token: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Configure AWS credentials (OIDC / Assume Role) + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: ecr-login + uses: aws-actions/amazon-ecr-login@v2 + + - name: Set image tag + id: vars + run: | + SHORT_SHA=${GITHUB_SHA::7} + echo "IMAGE_TAG=${SHORT_SHA}" >> $GITHUB_ENV + echo "IMAGE_TAG=${SHORT_SHA}" + + - name: Build Docker image + run: | + ECR_REGISTRY=${{ steps.ecr-login.outputs.registry }} + IMAGE_URI="$ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:${IMAGE_TAG}" + + echo "Building image: $IMAGE_URI" + # Dockerfile이 repo 루트에 있다고 가정, 위치 다르면 -f 경로 지정 + docker build -t "$IMAGE_URI" . + + - name: Push Docker image + run: | + ECR_REGISTRY=${{ steps.ecr-login.outputs.registry }} + IMAGE_URI="$ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:${IMAGE_TAG}" + + docker push "$IMAGE_URI" + + - name: Tag image as latest (only on main) + if: github.ref == 'refs/heads/main' + run: | + ECR_REGISTRY=${{ steps.ecr-login.outputs.registry }} + IMAGE_BASE="$ECR_REGISTRY/${{ env.ECR_REPOSITORY }}" + + docker tag "${IMAGE_BASE}:${IMAGE_TAG}" "${IMAGE_BASE}:latest" + docker push "${IMAGE_BASE}:latest" \ No newline at end of file diff --git a/pom.xml b/pom.xml index 27bf95607..e3a2f692b 100644 --- a/pom.xml +++ b/pom.xml @@ -18,8 +18,8 @@ - 25 - 17 + 21 + 21 UTF-8 UTF-8 @@ -31,7 +31,7 @@ 4.7.0 11.1.0 - 2.42.0 + 2.45.0 0.8.13 0.3.4 1.0.0