Skip to content

Commit

Permalink
Merge pull request #126 from woowa-techcamp-2024/config/122-deploy-sc…
Browse files Browse the repository at this point in the history
…ript

[config] 서버 배포 스크립트 및 환경 구성
  • Loading branch information
huiseung authored Aug 26, 2024
2 parents e139b51 + 093604a commit 5df3f11
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 71 deletions.
124 changes: 110 additions & 14 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ on:
- dev

jobs:
deploy:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: JDK 17 설정
- name: JDK 21 설정
uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'zulu'

- name: gradlew 실행 권한 부여
Expand All @@ -24,22 +23,119 @@ jobs:
- name: JAR 빌드
run: ./gradlew clean build

- name: JAR를 EC2로 전송
- name: 빌드된 JAR 파일 확인
run: |
echo "빌드된 JAR 파일 목록:"
find service/*/build/libs -name "*.jar"
- name: 변경된 서비스 확인
id: check_changes
uses: dorny/paths-filter@v2
with:
filters: |
restaurant-exposure:
- 'service/restaurant-exposure-service/**'
search:
- 'service/search-service/**'
cache:
- 'service/cache-service/**'
advertisement:
- 'service/advertisement-service/**'
coupon:
- 'service/coupon-service/**'
delivery-time:
- 'service/delivery-time-service/**'
restaurant:
- 'service/restaurant-service/**'
- name: SSH 키 설정
env:
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }}
HOST: ${{ secrets.DEV_EC2_HOST }}
run: |
echo "$PRIVATE_KEY" > private_key
chmod 600 private_key
- name: 가게노출 서비스 배포
if: steps.check_changes.outputs.restaurant-exposure == 'true'
env:
HOST: ${{ secrets.DEV_EC2_HOST1 }}
USER: ${{ secrets.DEV_EC2_USER }}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
scp -o StrictHostKeyChecking=no -i private_key mono/build/libs/*.jar ${USER}@${HOST}:~/app.jar
scp -o StrictHostKeyChecking=no -i private_key service/restaurant-exposure-service/build/libs/*.jar ${USER}@${HOST}:~/restaurant-exposure-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar restaurant-exposure-service.jar' || true
rm -rf estaurant-exposure-service.log
source ~/.bash_profile
nohup java -jar restaurant-exposure-service.jar --spring.profiles.active=dev > restaurant-exposure-service.log 2>&1 &
EOF
- name: EC2에서 JAR 실행
- name: 검색 서비스 배포
if: steps.check_changes.outputs.search == 'true'
env:
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }}
HOST: ${{ secrets.DEV_EC2_HOST }}
HOST: ${{ secrets.DEV_EC2_HOST2 }}
USER: ${{ secrets.DEV_EC2_USER }}
run: |
scp -o StrictHostKeyChecking=no -i private_key service/search-service/build/libs/*.jar ${USER}@${HOST}:~/search-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar app.jar --spring.profiles.active=dev' || true
nohup java -jar app.jar --spring.profiles.active=dev > app.log 2>&1 &
EOF
pkill -f 'java -jar search-service.jar' || true
rm -rf search-service.log
source ~/.bash_profile
nohup java -jar search-service.jar --spring.profiles.active=dev > search-service.log 2>&1 &
EOF
- name: 기타 서비스 배포
if: |
steps.check_changes.outputs.cache == 'true' ||
steps.check_changes.outputs.advertisement == 'true' ||
steps.check_changes.outputs.coupon == 'true' ||
steps.check_changes.outputs.delivery-time == 'true' ||
steps.check_changes.outputs.restaurant == 'true'
env:
HOST: ${{ secrets.DEV_EC2_HOST3 }}
USER: ${{ secrets.DEV_EC2_USER }}
run: |
if [[ "${{ steps.check_changes.outputs.cache }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/cache-service/build/libs/*.jar ${USER}@${HOST}:~/cache-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar cache-service.jar' || true
rm -rf cache-service.log
source ~/.bash_profile
nohup java -jar cache-service.jar --spring.profiles.active=dev > cache-service.log 2>&1 &
EOF
fi
if [[ "${{ steps.check_changes.outputs.advertisement }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/advertisement-service/build/libs/*.jar ${USER}@${HOST}:~/advertisement-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar advertisement-service.jar' || true
rm -rf advertisement-service.log
source ~/.bash_profile
nohup java -jar advertisement-service.jar --spring.profiles.active=dev > advertisement-service.log 2>&1 &
EOF
fi
if [[ "${{ steps.check_changes.outputs.coupon }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/coupon-service/build/libs/*.jar ${USER}@${HOST}:~/coupon-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar coupon-service.jar' || true
rm -rf coupon-service.log
source ~/.bash_profile
nohup java -jar coupon-service.jar --spring.profiles.active=dev > coupon-service.log 2>&1 &
EOF
fi
if [[ "${{ steps.check_changes.outputs.delivery-time }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/delivery-time-service/build/libs/*.jar ${USER}@${HOST}:~/delivery-time-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar delivery-time-service.jar' || true
rm -rf delivery-time-service.log
source ~/.bash_profile
nohup java -jar delivery-time-service.jar --spring.profiles.active=dev > delivery-time-service.log 2>&1 &
EOF
fi
if [[ "${{ steps.check_changes.outputs.restaurant }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/restaurant-service/build/libs/*.jar ${USER}@${HOST}:~/restaurant-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar restaurant-service.jar' || true
rm -rf restaurant-service.log
source ~/.bash_profile
nohup java -jar restaurant-service.jar --spring.profiles.active=dev > restaurant-service.log 2>&1 &
EOF
fi
18 changes: 12 additions & 6 deletions service/cache-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spring:
redis:
host: localhost
port: 6379

external-api:
cache-service:
endpoints: http://localhost:7001/api/v1/cache
Expand All @@ -43,13 +44,18 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database-platform: org.hibernate.dialect.MySQLDialect
show-sql: true
properties:
hibernate:
format_sql: true
hibernate:
ddl-auto: none
data:
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ${REDIS_PASSWORD}

external-api:
cache-service:
endpoints: ${CACHE_SERVICE_ENDPOINT}

---

spring:
config:
activate:
Expand Down
3 changes: 3 additions & 0 deletions service/coupon-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ repositories {
mavenCentral()
}

bootJar.enabled = true
jar.enabled = false

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ spring:
hibernate:
ddl-auto: none

elasticsearch:
uris: http://localhost:9200
username: elastic
password: your_elastic_password
data:
elasticsearch:
repositories:
enabled: true
redis:
host: localhost
port: 6379

logging:
level:
tracer: TRACE
Expand Down Expand Up @@ -66,13 +54,25 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database-platform: org.hibernate.dialect.MySQLDialect
show-sql: true
properties:
hibernate:
format_sql: true
hibernate:
ddl-auto: none

external-api:
advertisement-service:
endpoints: ${ADVERTISEMENT_SERVICE_ENDPOINT}
coupon-service:
endpoints: ${COUPON_SERVICE_ENDPOINT}
delivery-service:
endpoints: ${DELIVERY_SERVICE_ENDPOINT}
cache-service:
endpoints: ${CACHE_SERVICE_ENDPOINT}
restaurant-service:
endpoints: ${RESTAURANT_SERVICE_ENDPOINT}
search-service:
endpoints: ${SEARCH_SERVICE_ENDPOINT}

---

spring:
config:
activate:
Expand Down
21 changes: 1 addition & 20 deletions service/restaurant-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ spring:
hibernate:
ddl-auto: none

elasticsearch:
uris: http://localhost:9200
username: elastic
password: your_elastic_password
data:
elasticsearch:
repositories:
enabled: true
redis:
host: localhost
port: 6379

logging:
level:
tracer: TRACE

---
spring:
config:
Expand All @@ -52,10 +36,6 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database-platform: org.hibernate.dialect.MySQLDialect
show-sql: true
properties:
hibernate:
format_sql: true
hibernate:
ddl-auto: none
elasticsearch:
Expand All @@ -67,6 +47,7 @@ spring:
repositories:
enabled: true
---

spring:
config:
activate:
Expand Down
17 changes: 2 additions & 15 deletions service/search-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,10 @@ spring:
format_sql: true
hibernate:
ddl-auto: none

elasticsearch:
uris: http://localhost:9200
username: elastic
password: your_elastic_password
data:
elasticsearch:
repositories:
enabled: true
redis:
host: localhost
port: 6379

logging:
level:
Expand All @@ -61,7 +53,6 @@ spring:
elasticsearch:
uris: ${ELASTICSEARCH_URL}
username: ${ELASTICSEARCH_USERNAME}
password: ${ELASTICSEARCH_PASSWORD}
data:
elasticsearch:
repositories:
Expand All @@ -70,12 +61,8 @@ spring:
password: ${REDIS_PASSWORD}

external-api:
advertisement-service:
endpoints: http://localhost:8083/api/v1/advertisements
coupon-service:
endpoints: http://localhost:8082/api/v1/coupons
delivery-service:
endpoints: http://localhost:8081/api/v1/deliveries
search-service:
endpoints: ${SEARCH_SERVICE_ENDPOINT}

---

Expand Down

0 comments on commit 5df3f11

Please sign in to comment.