Merge branch 'feature/terms-upadte' into develop #94
Workflow file for this run
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: Build and Push Docker Images | |
| permissions: | |
| contents: write # 리포지토리 컨텐츠 쓰기 권한 | |
| packages: write # 패키지 쓰기 권한 | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # v로 시작하는 태그에 대해 실행 | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Push Git Tags (Ensure it's available in Jenkins) | |
| run: | | |
| git fetch --tags --force | |
| git push origin --tags # 원격 저장소에 태그 강제 푸시 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.TREENUT }} | |
| - name: Install Node.js and build react-frontpage | |
| run: | | |
| cd nginx/react-frontpage | |
| npm install | |
| npx update-browserslist-db@latest | |
| npm run build || true | |
| env: | |
| NODE_VERSION: '20' # Node.js 버전은 20이상을 사용 | |
| - name: Create .env files for Docker build | |
| run: | | |
| echo "${{ secrets.DOCKER_ENV }}" > .env | |
| mkdir -p mongo && echo "${{ secrets.MONGO_ENV }}" > ./mongo/.env | |
| mkdir -p fastapi/src && echo "${{ secrets.FASTAPI_ENV }}" > ./fastapi/src/.env | |
| mkdir -p ./springboot/src/main/resources | |
| echo "${{ secrets.SPRING_ENV }}" > ./springboot/src/main/resources/application.properties | |
| echo "${{ secrets.SPRING_SWAGGER_ENV }}" > ./springboot/src/main/resources/application.yml | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| if: startsWith(github.ref, 'refs/tags/') | |
| with: | |
| name: Release ${{ github.ref_name }} | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| files: | | |
| docker-compose.yml # .env 파일 제거 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push Nginx image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: ./nginx | |
| push: true | |
| tags: | | |
| ghcr.io/treenut-kr/nginx:latest | |
| ghcr.io/treenut-kr/nginx:${{ github.ref_name }} | |
| - name: Build and push FastAPI image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: ./fastapi | |
| push: true | |
| tags: | | |
| ghcr.io/treenut-kr/fastapi:latest | |
| ghcr.io/treenut-kr/fastapi:${{ github.ref_name }} | |
| - name: Build and push MySQL image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: ./mysql | |
| push: true | |
| tags: | | |
| ghcr.io/treenut-kr/mysql:latest | |
| ghcr.io/treenut-kr/mysql:${{ github.ref_name }} | |
| - name: Build and push MongoDB image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: ./mongo | |
| push: true | |
| tags: | | |
| ghcr.io/treenut-kr/mongodb:latest | |
| ghcr.io/treenut-kr/mongodb:${{ github.ref_name }} | |
| - name: Build and push SpringBoot image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: ./springboot | |
| push: true | |
| tags: | | |
| ghcr.io/treenut-kr/springboot:latest | |
| ghcr.io/treenut-kr/springboot:${{ github.ref_name }} | |
| notify-jenkins: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # 모든 태그와 히스토리를 가져오기 위해 필요 | |
| - name: Ensure Latest Git Tags in Jenkins | |
| run: | | |
| git fetch --tags --force # 최신 태그 강제 업데이트 | |
| - name: Extract Branch Name from Tag | |
| id: extract_branch | |
| run: | | |
| # GitHub의 ref 정보를 기반으로 브랜치 추출 | |
| BRANCH=$(git branch -r --contains ${{ github.ref }} | head -n 1 | awk -F'/' '{print $2}') | |
| echo "BRANCH=${BRANCH}" >> $GITHUB_ENV | |
| - name: Install jq (if not installed) | |
| run: | | |
| if ! command -v jq &> /dev/null; then | |
| sudo apt-get update && sudo apt-get install -y jq | |
| fi | |
| - name: Trigger Jenkins Deploy | |
| run: | | |
| set -x # 디버그 정보 활성화 | |
| # Jenkins CSRF 토큰 가져오기 | |
| CRUMB=$(curl -s \ | |
| -u "${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }}" \ | |
| "${{ secrets.JENKINS_URL }}/crumbIssuer/api/json" | jq -r '.crumb') | |
| curl -X POST \ | |
| --fail \ | |
| -u "${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }}" \ | |
| -H "Jenkins-Crumb:$CRUMB" \ | |
| -H "Content-Type: application/x-www-form-urlencoded" \ | |
| "${{ secrets.JENKINS_URL }}/job/JMS_Chatbot/buildWithParameters" \ | |
| --data-urlencode "token=${{ secrets.JENKINS_BUILD_TOKEN }}" \ | |
| --data-urlencode "VERSION=${{ github.ref_name }}" \ | |
| --data-urlencode "BRANCH=${BRANCH}" \ | |
| --data-urlencode "RELEASE_URL=https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}" | |
| env: | |
| CURL_DEBUG: "true" # 디버그 정보 활성화 |