diff --git a/.github/workflows/.deploy.yml.swp b/.github/workflows/.deploy.yml.swp deleted file mode 100644 index 8aef3590..00000000 Binary files a/.github/workflows/.deploy.yml.swp and /dev/null differ diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 985ee52e..978d31dd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -61,7 +61,7 @@ jobs: # Remove origin was container docker rm -f backend # Pull and Deploy new built docker image with new tag - docker pull blackbean99@econo-recruit:latest + docker pull blackbean99/econo-recruit:latest docker-compose up -d --remove-orphans docker image prune -a -f diff --git a/.github/workflows/dev-deploy.yml b/.github/workflows/dev-deploy.yml new file mode 100644 index 00000000..06607689 --- /dev/null +++ b/.github/workflows/dev-deploy.yml @@ -0,0 +1,104 @@ +name: 개발서버 배포 플로우 + +on: + workflow_call: + secrets: + SSH_HOST: + required: true + SSH_USERNAME: + required: true + SSH_KEY: + required: true + SSH_PORT: + required: true + SLACK_WEBHOOK_URL: + required: true + inputs: + environment: + required: true + type: string + image-tag: + required: true + type: string + spring-profile-active: + required: true + type: string + image-name: + required: true + type: string + service-name: + required: true + type: string + +env: + IMAGE_TAG: 'latest' + ACTIVE_PROFILE: ${{ inputs.spring-profile-active || 'local' }} + ENVIRONMENT: ${{ inputs.environment || 'local' }} + +jobs: + deploy: + runs-on: [ ubuntu-latest ] + name: 서비스 배포하기 + environment: ${{ inputs.environment }} + + permissions: + id-token: write + contents: read + + steps: + - name: GitHub 에서 레포 받아오기 + uses: actions/checkout@v3 + + - name: 개발서버 배포 스크립트 실행 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEV_SSH_HOST }} + username: ${{ secrets.DEV_SSH_USERNAME }} + key: ${{ secrets.DEV_SSH_KEY }} + port: ${{ secrets.DEV_SSH_PORT }} + script: | + cd ./econo-recruit/server + # Remove origin was container + docker rm -f backend + # Pull and Deploy new built docker image with new tag + docker pull blackbean99/econo-recruit:latest + docker-compose up -d --remove-orphans + docker image prune -a -f + + - name: 배포 완료 슬랙 알림 보내기 + uses: 8398a7/action-slack@v3 + with: + status: custom + fields: author, workflowRun, pullRequest + custom_payload: | + { + attachments: [{ + color: '#59f764', + title: '서버 배포 알림', + text: `Econo-Recruit 서버 배포 성공!`, + fields: [ + { + title: '배포 환경', + value: `${process.env.ENVIRONMENT}`, + short: true, + }, + { + title: '배포자', + value: `${process.env.AS_AUTHOR}`, + short: true, + }, + { + title: '워크플로 링크', + value: `${process.env.AS_WORKFLOW_RUN}`, + short: true, + }, + { + title: 'PR 링크', + value: `${process.env.AS_PULL_REQUEST}`, + short: true, + } + ] + }] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 00000000..ccf5c3bb --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,100 @@ +name: 배포 워크플로우 +on: + push: + branches: + - develop + - backend +env: + SPRING_PROFILES_ACTIVE: local + ENVIRONMENT: production + IMAGE_NAME: blackbean99/econo-recruit + SERVICE_NAME: Econovation_Recruit_Server + +concurrency: + group: production + + +jobs: + prepare-environments: + name: 환경 변수 설정 + runs-on: ubuntu-latest + outputs: + image-name: ${{ steps.setup-env.outputs.image-name }} + image-tag: ${{ steps.setup-env.outputs.image-tag }} + spring-profile-active: ${{ steps.setup-env.outputs.spring-profile-active }} + environment: ${{ steps.setup-env.outputs.environment }} + service-name: ${{ steps.setup-env.outputs.service-name }} + + steps: + - name: Github에서 레포 받아오기 + uses: actions/checkout@v3 + + - name: 환경 변수 설정 + id: setup-env + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + run: | + echo "image-name=$IMAGE_NAME" >> $GITHUB_OUTPUT + echo "image-tag=latest" >> $GITHUB_OUTPUT + # $(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "spring-profile-active=$SPRING_PROFILES_ACTIVE" >> $GITHUB_OUTPUT + echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT + echo "service-name=$SERVICE_NAME" >> $GITHUB_OUTPUT + echo "::set-env name=DOCKERHUB_USERNAME::${{ secrets.DOCKERHUB_USERNAME }}" + echo "::set-env name=DOCKERHUB_PASSWORD::${{ secrets.DOCKERHUB_PASSWORD }}" + echo "::set-env name=MYSQL_HOST::${{ secrets.MYSQL_HOST }}" + echo "::set-env name=MYSQL_PORT::${{ secrets.MYSQL_PORT }}" + echo "::set-env name=MYSQL_DATABASE::${{ secrets.MYSQL_DATABASE }}" + echo "::set-env name=MYSQL_USERNAME::${{ secrets.MYSQL_USERNAME }}" + echo "::set-env name=MYSQL_PASSWORD::${{ secrets.MYSQL_PASSWORD }}" + echo "::set-env name=JWT_SECRET::${{ secrets.JWT_SECRET }}" + echo "::set-env name=SONAR_TOKEN::${{ secrets.SONAR_TOKEN }}" + + call-ci-check-workflow: + if: github.event_name == 'push' + name: CI_CHECK(spotless, sonar) 정적분석 + uses: ./.github/workflows/CI_Check.yml + permissions: + id-token: write + contents: read + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + call-build-workflow: + if: github.event_name == 'push' + needs: [ prepare-environments ] + name: 서비스 빌드 + uses: ./.github/workflows/build.yml + permissions: + id-token: write + contents: read + with: + image-tag: 'latest' + # ${{ needs.prepare-environments.outputs.image-tag }} + spring-profile-active: ${{ needs.prepare-environments.outputs.spring-profile-active }} + image-name: ${{ needs.prepare-environments.outputs.image-name }} + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + + call-deploy-workflow: + if: github.event_name == 'push' + needs: [ prepare-environments, call-build-workflow ] + name: 서비스 배포 + uses: ./.github/workflows/dev-deploy.yml + permissions: + id-token: write + contents: read + secrets: + SSH_HOST: ${{ secrets.DEV_SSH_HOST }} + SSH_USERNAME: ${{ secrets.DEV_SSH_USERNAME }} + SSH_KEY: ${{ secrets.DEV_SSH_KEY }} + SSH_PORT: ${{ secrets.DEV_SSH_PORT }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + with: + image-tag: ${{ needs.prepare-environments.outputs.image-tag }} + spring-profile-active: ${{ needs.prepare-environments.outputs.spring-profile-active }} + environment: ${{ needs.prepare-environments.outputs.environment }} + image-name: ${{ needs.prepare-environments.outputs.image-name }} + service-name: ${{ needs.prepare-environments.outputs.service-name }} + diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 23f5ad78..57d3c55a 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -2,7 +2,6 @@ name: 배포 워크플로우 on: push: branches: - - release - backend env: SPRING_PROFILES_ACTIVE: local diff --git a/.gitignore b/.gitignore index 883e4461..bb82e24e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ Recruit-Domain/HELP.md .gradle/** .server/.gradle/** .server/.gradle +server/.gradle +server/.gradle/** build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ diff --git a/server/Recruit-Domain/src/main/resources/application-domain.yml b/server/Recruit-Domain/src/main/resources/application-domain.yml index 27ef1891..59406cf1 100644 --- a/server/Recruit-Domain/src/main/resources/application-domain.yml +++ b/server/Recruit-Domain/src/main/resources/application-domain.yml @@ -18,7 +18,7 @@ spring: auto-index-creation: true jpa: hibernate: - ddl-auto: update + ddl-auto: ${DDL_AUTO:update} generate-ddl: true show-sql: ${SHOW_SQL:false} properties: @@ -39,13 +39,13 @@ spring: logging: level: - com.zaxxer.hikari.HikariConfig: ERROR - com.zaxxer.hikari: ERROR - org.springframework.orm.jpa: ERROR - org.springframework.transaction: ERROR - org.springframework.aop: INFO + com.zaxxer.hikari.HikariConfig: ${LOG_LEVEL:INFO} + com.zaxxer.hikari: ${LOG_LEVEL:INFO} + org.springframework.orm.jpa: ${LOG_LEVEL:INFO} + org.springframework.transaction: ${LOG_LEVEL:INFO} + org.springframework.aop: ${LOG_LEVEL:INFO} org: - hibernate: ERROR + hibernate: ${LOG_LEVEL:INFO} --- spring: @@ -77,8 +77,8 @@ spring: database-platform: org.hibernate.dialect.MySQL5InnoDBDialect logging: level: - org.springframework.orm.jpa: ERROR - org.springframework.transaction: ERROR + org.springframework.orm.jpa: ${LOG_LEVEL:INFO} + org.springframework.transaction: ${LOG_LEVEL:INFO} --- spring: config: @@ -98,30 +98,4 @@ spring: default_batch_fetch_size: ${JPA_BATCH_FETCH_SIZE:100} hibernate: ddl-auto: none - database-platform: org.hibernate.dialect.MySQL5InnoDBDialect - - - - -##MySQL8 DB -#spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect -#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect -#spring.jpa.generate-ddl=true -#spring.datasource.url=${DB_URL:jdbc:mysql://localhost:3306/econovation?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul} -#spring.jpa.hibernate.ddl-auto=update -#spring.datasource.driver-class-name=com.mysql.jdbc.Driver -#spring.datasource.username=root -#spring.datasource.password=dltjgus119@@ -# -##hibernate ?? -#spring.jpa.properties.hibernate.format_sql=true -#spring.jpa.properties.hibernate.show_sql=true -#spring.jpa.show-sql=true -# -##Bulk Insert -#spring.jpa.properties.hibernate.jdbc.batch_size = ${batchSize} -#spring.jpa.properties.hibernate.jdbc.order_inserts = true -#spring.jpa.properties.hibernate.jdbc.order_updates = true -#spring.jpa.properties.hibernate.hbm2ddl.auto=create -#spring.jpa.open-in-view = false -# + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect \ No newline at end of file