|
| 1 | +name: Alarm Service CI - Build, Push, and Trigger CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build-push-trigger: |
| 9 | + name: Build, Push Alarm Service Image, and Trigger Jenkins CD |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Log in to Docker Hub |
| 17 | + uses: docker/login-action@v3 |
| 18 | + with: |
| 19 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 20 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 21 | + |
| 22 | + - name: Extract metadata (tags, labels) for Docker |
| 23 | + id: meta |
| 24 | + uses: docker/metadata-action@v5 |
| 25 | + with: |
| 26 | + images: msj9965/alog-alarm # Alarm 서비스 이미지 이름 |
| 27 | + tags: | # 태그 전략: main, latest, sha-short |
| 28 | + type=raw,value=main,enable={{is_default_branch}} |
| 29 | + type=raw,value=latest,enable={{is_default_branch}} |
| 30 | + type=sha,prefix=sha-,format=short |
| 31 | +
|
| 32 | + - name: Build and push Docker image |
| 33 | + uses: docker/build-push-action@v5 |
| 34 | + with: |
| 35 | + context: . |
| 36 | + file: ./Dockerfile # Alarm 서비스 레포지토리의 Dockerfile |
| 37 | + push: true |
| 38 | + tags: ${{ steps.meta.outputs.tags }} |
| 39 | + labels: ${{ steps.meta.outputs.labels }} |
| 40 | + |
| 41 | + - name: Trigger Jenkins CD Pipeline for Alarm Service |
| 42 | + if: success() |
| 43 | + env: |
| 44 | + JENKINS_URL: ${{ secrets.JENKINS_URL }} |
| 45 | + JENKINS_JOB_NAME: ${{ secrets.JENKINS_JOB_NAME_ALARM }} # Alarm 서비스용 Jenkins 작업 이름 Secret |
| 46 | + JENKINS_TRIGGER_TOKEN: ${{ secrets.JENKINS_TRIGGER_TOKEN_ALARM }} # Alarm 서비스용 Jenkins 트리거 토큰 Secret |
| 47 | + JENKINS_USER_ID: ${{ secrets.JENKINS_USER_ID }} |
| 48 | + JENKINS_USER_API_TOKEN: ${{ secrets.JENKINS_USER_API_TOKEN }} |
| 49 | + # Jenkins에 전달할 이미지 태그 (여기서는 'main' 태그를 사용) |
| 50 | + IMAGE_TO_DEPLOY_TAG: main |
| 51 | + run: | |
| 52 | + echo "Triggering Jenkins job: '${JENKINS_JOB_NAME}' for Alarm Service with image tag: '${IMAGE_TO_DEPLOY_TAG}'" |
| 53 | + curl -X POST -u "${JENKINS_USER_ID}:${JENKINS_USER_API_TOKEN}" \ |
| 54 | + "${JENKINS_URL}/job/${JENKINS_JOB_NAME}/buildWithParameters?token=${JENKINS_TRIGGER_TOKEN}&IMAGE_TAG=${IMAGE_TO_DEPLOY_TAG}" |
0 commit comments