diff --git a/.github/workflows/spring-cd.yml b/.github/workflows/spring-cd.yml new file mode 100644 index 0000000..357dcdc --- /dev/null +++ b/.github/workflows/spring-cd.yml @@ -0,0 +1,23 @@ +name: Spring Boot & Gradle CD + +on: + push: + branches: [ "main" ] + +jobs: + cd: + uses: kjiyun/CI-CD-pipeline-standard/.github/workflows/java-gradle-cd.yml@master + # 참고: https://github.com/kjiyun/CI-CD-pipeline-standard + with: + java-version: "17" + distribution: "temurin" + image-name: kahlua-web + write-application-yml: true + secrets: + APPLICATION: ${{ secrets.APPLICATION }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + DOCKER_REPO: ${{ secrets.DOCKER_REPO }} + HOST_ID: ${{ secrets.HOST_ID }} + USERNAME: ${{ secrets.USERNAME }} + PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} \ No newline at end of file diff --git a/.github/workflows/spring-ci.yml b/.github/workflows/spring-ci.yml new file mode 100644 index 0000000..3716375 --- /dev/null +++ b/.github/workflows/spring-ci.yml @@ -0,0 +1,19 @@ +name: Spring Boot & Gradle CI + +on: + pull_request: + branches: [ "main" ] + +jobs: + ci: + uses: kjiyun/CI-CD-pipeline-standard/.github/workflows/java-gradle-ci.yml@master + # 참고: https://github.com/kjiyun/CI-CD-pipeline-standard + with: + java-version: "17" + distribution: "temurin" + build-command: "false" + test-command: "false" + upload-artifacts: true + write-application-yml: true + secrets: + APPLICATION: ${{ secrets.APPLICATION }} \ No newline at end of file diff --git a/.github/workflows/spring-cicd.yml b/.github/workflows/spring-cicd.yml deleted file mode 100644 index 01cbaf4..0000000 --- a/.github/workflows/spring-cicd.yml +++ /dev/null @@ -1,63 +0,0 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -# Repo Action 페이지에 나타날 이름 -name: Spring Boot & Gradle CI/CD - -# Event Trigger -# master branch에 대한 pull request가 close 될 때 동작 -# branch 단위 외에도, tag나 cron 식 등을 사용할 수 있음 -on: - pull_request_target: - branches: [ main ] - types: - - closed - -jobs: - build: - # pull request가 merge된 경우 - if: github.event.pull_request.merged == true - # 실행 환경 지정 - runs-on: ubuntu-24.04 - - # Task의 sequence를 명시한다. - steps: - - uses: actions/checkout@v2 - - - name: Set up JDK 17 - uses: actions/setup-java@v1 - with: - java-version: 17 - ## create application.yaml - - name: make application.yml - run: | - cd ./src/main/resources - touch ./application.yml - echo "${{ secrets.APPLICATION }}" > ./application.yml - shell: bash - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - # Build - - name: Build with Gradle - run: ./gradlew clean build -x test - - ## 웹 이미지 빌드 및 도커허브에 push - - name: web docker build and push - run: | - docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -t ${{ secrets.DOCKER_REPO }}/kahlua-web . - docker push ${{ secrets.DOCKER_REPO }}/kahlua-web - ## docker compose up - - name: executing remote ssh commands using password - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.HOST_ID }} - username: ${{ secrets.USERNAME }} - key: ${{ secrets.PRIVATE_KEY }} - script: | - sudo docker-compose down - sudo docker pull ${{ secrets.DOCKER_REPO }}/kahlua-web - sudo docker-compose up -d - sudo docker image prune -f \ No newline at end of file