update style in service-architecture #184
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: Change detection and Image tagging with github sha (DEV) | |
| on: | |
| push: | |
| paths-ignore: | |
| - "deployment/**" | |
| - "scripts/**" | |
| - ".github/**" | |
| - "kubernetes/**" | |
| branches: [develop] | |
| workflow_dispatch: | |
| jobs: | |
| detect-changes-by-component: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| backend: ${{ steps.filter.outputs.backend }} | |
| frontend: ${{ steps.filter.outputs.frontend }} | |
| hub-auth: ${{ steps.filter.outputs.hub-auth }} | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - uses: dorny/paths-filter@v2 | |
| id: filter | |
| with: | |
| filters: | | |
| backend: | |
| - 'backend/**' | |
| frontend: | |
| - 'frontend/**' | |
| hub-auth: | |
| - 'hub/auth_server/**' | |
| ci-backend-dev: | |
| needs: [detect-changes-by-component] | |
| if: ${{ needs.detect-changes-by-component.outputs.backend == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Login to Harbor | |
| uses: docker/login-action@v1 | |
| with: | |
| registry: ${{ secrets.HARBOR_REGISTRY }} | |
| username: ${{ secrets.HARBOR_USERNAME }} | |
| password: ${{ secrets.HARBOR_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v2 | |
| with: | |
| context: ./backend | |
| file: ./backend/Dockerfile | |
| push: true | |
| tags: ${{ secrets.HARBOR_REGISTRY }}/code-place-dev/backend:${{ github.sha }}-dev | |
| ci-frontend-dev: | |
| needs: [detect-changes-by-component] | |
| if: ${{ needs.detect-changes-by-component.outputs.frontend == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Login to Harbor | |
| uses: docker/login-action@v1 | |
| with: | |
| registry: ${{ secrets.HARBOR_REGISTRY }} | |
| username: ${{ secrets.HARBOR_USERNAME }} | |
| password: ${{ secrets.HARBOR_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v2 | |
| with: | |
| context: ./frontend | |
| file: ./frontend/Dockerfile | |
| push: true | |
| tags: ${{ secrets.HARBOR_REGISTRY }}/code-place-dev/frontend:${{ github.sha }}-dev | |
| build-args: | | |
| SERVER_NAME=${{ secrets.DEV_SERVER_NAME }} | |
| APP_VERSION=${{ github.sha }}-dev | |
| update-dev-manifest: | |
| needs: [ci-backend-dev, ci-frontend-dev] | |
| if: always() && (needs.ci-backend-dev.result == 'success' || needs.ci-frontend-dev.result == 'success') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| with: | |
| token: ${{ secrets.ACTION_TOKEN }} | |
| fetch-depth: 0 | |
| # NOTE: 기존에 kustomize를 사용하였지만 포멧 문제로 yq로 변경 (junwoo) | |
| # images.[] .name 에 맞는 항목의 newTag 값을 github.sha-dev로 변경 | |
| - name: Update Backend Image Tag | |
| if: needs.ci-backend-dev.result == 'success' | |
| uses: mikefarah/yq@master | |
| with: | |
| cmd: yq -i '(.images[] | select(.name == "backend").newTag) = "${{ github.sha }}-dev"' kubernetes/overlays/dev/kustomization.yaml | |
| - name: Update Frontend Image Tag | |
| if: needs.ci-frontend-dev.result == 'success' | |
| uses: mikefarah/yq@master | |
| with: | |
| cmd: yq -i '(.images[] | select(.name == "frontend").newTag) = "${{ github.sha }}-dev"' kubernetes/overlays/dev/kustomization.yaml | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add kubernetes/overlays/dev/kustomization.yaml | |
| # 변경사항이 없으면 종료 | |
| if git diff-index --quiet HEAD; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| # 충돌 방지를 위해 최신 develop 브랜치로 rebase 후 push | |
| # [skip ci] 태그를 커밋 메시지에 추가하여 추가 CI 실행을 방지 | |
| git commit -m "ci: Update dev image tags to ${{ github.sha }} [skip ci]" | |
| git pull --rebase origin ${{ github.ref_name }} | |
| git push origin ${{ github.ref_name }} |