infra :: gemini git workflow quota 오류 수정 #139
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline with GitHub Actions for K8S | |
| on: | |
| push: | |
| branches: [ "infra/cicd-test", "chatforyou_v2", "feat/126"] | |
| # branches: [ "master-webrtc-catchmind", "infra/cicd-test" ] | |
| # pull_request: | |
| # branches: [ "master" ] | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| backend: ${{ steps.filter.outputs.backend }} | |
| frontend: ${{ steps.filter.outputs.frontend }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Filter changes | |
| id: filter | |
| uses: dorny/paths-filter@v3 | |
| with: | |
| filters: | | |
| backend: | |
| - 'springboot-backend/**' | |
| frontend: | |
| - 'nodejs-frontend/**' | |
| backend-deploy: | |
| name: Build And Deploy Backend K8S | |
| needs: changes | |
| if: needs.changes.outputs.backend == 'true' | |
| environment: chatforyou-back-env | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| env: | |
| K8S_NAMESPACE: chatforyou | |
| DEPLOYMENT_NAME: chatforyou-v03 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('springboot-backend/**/*.gradle*') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: Run backend unit tests | |
| run: | | |
| cd springboot-backend | |
| ./gradlew test --no-daemon | |
| # @ExternalTest 태그 테스트는 build.gradle excludeTags 'external'로 자동 제외 | |
| # 제외 대상: Redis(RedisServiceImplTest), Kafka(KafkaTest), 외부 HTTP(CookieCheckEventTest) | |
| # CI 실행 대상: Pure Mockito, MockMvc 슬라이스 테스트 전체 | |
| - name: Configure Kubeconfig | |
| uses: azure/k8s-set-context@v3 | |
| with: | |
| method: kubeconfig | |
| kubeconfig: ${{ secrets.KUBE_CONFIG }} | |
| - name: Generate TIMESTAMP in KST | |
| id: timestamp | |
| run: | | |
| export TZ=Asia/Seoul | |
| TIMESTAMP=$(date '+%Y%m%d%H%M%S') | |
| echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV | |
| echo "IMAGE_URI=ghcr.io/sejonj/chatforyou:$TIMESTAMP" >> $GITHUB_ENV | |
| - name: Build Docker Image | |
| run: | | |
| cd springboot-backend | |
| docker build --file Dockerfile -t $IMAGE_URI . | |
| cd .. | |
| - name: Push Docker Image to GitHub Packages | |
| env: | |
| CR_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "$CR_PAT" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| docker push $IMAGE_URI | |
| - name: Deploy to Kubernetes | |
| run: | | |
| kubectl set image deployment/$DEPLOYMENT_NAME \ | |
| chatforyou-container=$IMAGE_URI \ | |
| -n $K8S_NAMESPACE | |
| kubectl rollout status deployment/$DEPLOYMENT_NAME -n $K8S_NAMESPACE | |
| frontend-deploy: | |
| name: Build And Deploy Frontend K8S | |
| needs: changes | |
| if: needs.changes.outputs.frontend == 'true' | |
| environment: chatforyou-back-env | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| env: | |
| K8S_NAMESPACE: chatforyou | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Configure Kubeconfig | |
| uses: azure/k8s-set-context@v3 | |
| with: | |
| method: kubeconfig | |
| kubeconfig: ${{ secrets.KUBE_CONFIG }} | |
| - name: Generate TIMESTAMP in KST | |
| id: timestamp | |
| run: | | |
| export TZ=Asia/Seoul | |
| TIMESTAMP=$(date '+%Y%m%d%H%M%S') | |
| echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV | |
| echo "FRONT_IMAGE_URI=ghcr.io/sejonj/chatforyou-frontend:$TIMESTAMP" >> $GITHUB_ENV | |
| - name: Build Frontend Docker Image | |
| run: | | |
| cd nodejs-frontend | |
| docker build -t $FRONT_IMAGE_URI . | |
| cd .. | |
| - name: Push Frontend Docker Image | |
| env: | |
| CR_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "$CR_PAT" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| docker push $FRONT_IMAGE_URI | |
| - name: Deploy Frontend to Kubernetes | |
| run: | | |
| FRONT_DEPLOYMENT_NAME=chatforyou-frontend-v03 | |
| kubectl set image deployment/$FRONT_DEPLOYMENT_NAME \ | |
| chatforyou-frontend-container=$FRONT_IMAGE_URI \ | |
| -n $K8S_NAMESPACE | |
| kubectl rollout status deployment/$FRONT_DEPLOYMENT_NAME -n $K8S_NAMESPACE |