Deploy: deploy-k8s.yml 도커허브 로그인 버전 다운그레이드 #8
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 for upload in k8s | |
| # 1. 실행 조건: deploy-k8s 브랜치에 push가 발생했을 때만 실행 | |
| on: | |
| push: | |
| branches: [ "deploy-k8s" ] | |
| # 워크플로우 전체에서 사용할 환경 변수 | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image_tag: ${{ steps.docker_build.outputs.image_tag }} | |
| env: | |
| TAG: ${{ github.run_id }} | |
| permissions: | |
| contents: read | |
| packages: write # Docker 이미지 푸시를 위해 필요 | |
| steps: | |
| - name: 1. 소스 코드 체크아웃 | |
| uses: actions/checkout@v4 | |
| - name: 2. JDK 17 설치 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: 3. Gradle 실행 권한 부여 및 빌드 | |
| run: | | |
| chmod +x ./gradlew | |
| ./gradlew build -x test | |
| - name: 4. Docker Hub 로그인 | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: docker.io | |
| username: ${{ secrets.DEPLOY_USERNAME }} | |
| password: ${{ secrets.DEPLOY_PASSWORD }} | |
| logout: false | |
| - name: 5. 도커 이미지 빌드 및 푸시 | |
| id: docker_build | |
| run: | | |
| IMAGE_TAG=$(echo $GITHUB_SHA | cut -c1-7) | |
| echo "Building and pushing image: ${{ env.IMAGE_NAME }}:$IMAGE_TAG" | |
| docker build -t ${{ secrets.DEPLOY_USERNAME }}/codify-upload:${{ env.TAG }} . | |
| docker push ${{ secrets.DEPLOY_USERNAME }}/codify-upload:${{ env.TAG }} | |
| echo "image_tag=${{ env.TAG }}" >> $GITHUB_OUTPUT | |
| # ============================================ | |
| # CD 트리거 Job (매니페스트 업데이트) | |
| # ============================================ | |
| deploy: | |
| # 'build-and-push' job이 성공해야만 실행됨 | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 1. 매니페스트 리포지토리 체크아웃 | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: Codify-2025/k8s-manifests | |
| token: ${{ secrets.DEPLOY_PAT_TOKEN }} | |
| - name: 2. Deployment.yaml 파일의 이미지 태그 업데이트 | |
| working-directory: ./deploy/upload | |
| run: | | |
| sed -i "s|image: ${{ secrets.DEPLOY_USERNAME }}/codify-upload:.*|image: ${{ secrets.DEPLOY_USERNAME }}/codify-upload:${{ needs.build-and-push.outputs.image_tag }}|" deployment.yaml | |
| - name: 3. 변경된 매니페스트 커밋 및 푸시 | |
| run: | | |
| git config --global user.name 'dylee00' | |
| git config --global user.email 'dylee6820@gmail.com' | |
| git add . | |
| if git diff-index --quiet HEAD; then | |
| echo "No changes to commit." | |
| else | |
| git commit -m "Deploy: Update upload image to ${{ needs.build-and-push.outputs.image_tag }}" | |
| git push | |
| fi |