Skip to content

Commit

Permalink
[BE-81] CD 개발 서버 추가 배포 및 포트 포워딩 변수 추가 #217
Browse files Browse the repository at this point in the history
[BE-81] CD 개발 서버 추가 배포 및 포트 포워딩 변수 추가 #217
  • Loading branch information
BlackBean99 authored Mar 11, 2024
2 parents b1e447b + 7c06c44 commit 42d6fdd
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 38 deletions.
Binary file removed .github/workflows/.deploy.yml.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
104 changes: 104 additions & 0 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
100 changes: 100 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -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 }}

1 change: 0 additions & 1 deletion .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: 배포 워크플로우
on:
push:
branches:
- release
- backend
env:
SPRING_PROFILES_ACTIVE: local
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
46 changes: 10 additions & 36 deletions server/Recruit-Domain/src/main/resources/application-domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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

0 comments on commit 42d6fdd

Please sign in to comment.