[config] 배포 스크립트 수정 3 #19
This file contains 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: 개발 서버 배포 | |
on: | |
push: | |
branches: | |
- dev | |
- config/122-deploy-script | |
jobs: | |
changes: | |
runs-on: ubuntu-latest | |
outputs: | |
restaurant-exposure: ${{ steps.filter.outputs.restaurant-exposure }} | |
search: ${{ steps.filter.outputs.search }} | |
cache: ${{ steps.filter.outputs.cache }} | |
advertisement: ${{ steps.filter.outputs.advertisement }} | |
coupon: ${{ steps.filter.outputs.coupon }} | |
delivery-time: ${{ steps.filter.outputs.delivery-time }} | |
restaurant: ${{ steps.filter.outputs.restaurant }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
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/**' | |
build: | |
needs: changes | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: JDK 21 설정 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'zulu' | |
- name: gradlew 실행 권한 부여 | |
run: chmod +x gradlew | |
- name: JAR 빌드 | |
run: ./gradlew clean build | |
deploy-restaurant-exposure: | |
needs: [ changes, build ] | |
if: ${{ needs.changes.outputs.restaurant-exposure == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: 가게노출 서비스 서버로 JAR 전송 | |
env: | |
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }} | |
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 service/restaurant-exposure-service/build/libs/*.jar ${USER}@${HOST}:~/restaurant-exposure-service.jar | |
- name: 가게노출 서비스 실행 | |
env: | |
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }} | |
HOST: ${{ secrets.DEV_EC2_HOST1 }} | |
USER: ${{ secrets.DEV_EC2_USER }} | |
run: | | |
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF | |
pkill -f 'java -jar restaurant-exposure-service.jar' || true | |
nohup java -jar restaurant-exposure-service.jar --spring.profiles.active=dev > restaurant-exposure-service.log 2>&1 & | |
EOF | |
deploy-search: | |
needs: [ changes, build ] | |
if: ${{ needs.changes.outputs.search == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: 검색 서비스 서버로 JAR 전송 | |
env: | |
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }} | |
HOST: ${{ secrets.DEV_EC2_HOST2 }} | |
USER: ${{ secrets.DEV_EC2_USER }} | |
run: | | |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key | |
scp -o StrictHostKeyChecking=no -i private_key service/search-service/build/libs/*.jar ${USER}@${HOST}:~/search-service.jar | |
- name: 검색 서비스 실행 | |
env: | |
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }} | |
HOST: ${{ secrets.DEV_EC2_HOST2 }} | |
USER: ${{ secrets.DEV_EC2_USER }} | |
run: | | |
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF | |
pkill -f 'java -jar search-service.jar' || true | |
nohup java -jar search-service.jar --spring.profiles.active=dev > search-service.log 2>&1 & | |
EOF | |
deploy-other-services: | |
needs: [ changes, build ] | |
if: ${{ needs.changes.outputs.cache == 'true' || needs.changes.outputs.advertisement == 'true' || needs.changes.outputs.coupon == 'true' || needs.changes.outputs.delivery-time == 'true' || needs.changes.outputs.restaurant == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: 기타 서비스 서버로 JAR 전송 | |
env: | |
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }} | |
HOST: ${{ secrets.DEV_EC2_HOST3 }} | |
USER: ${{ secrets.DEV_EC2_USER }} | |
run: | | |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key | |
if [[ "${{ needs.changes.outputs.cache }}" == 'true' ]]; then | |
scp -o StrictHostKeyChecking=no -i private_key service/cache-service/build/libs/*.jar ${USER}@${HOST}:~/cache-service.jar | |
fi | |
if [[ "${{ needs.changes.outputs.advertisement }}" == 'true' ]]; then | |
scp -o StrictHostKeyChecking=no -i private_key service/advertisement-service/build/libs/*.jar ${USER}@${HOST}:~/advertisement-service.jar | |
fi | |
if [[ "${{ needs.changes.outputs.coupon }}" == 'true' ]]; then | |
scp -o StrictHostKeyChecking=no -i private_key service/coupon-service/build/libs/*.jar ${USER}@${HOST}:~/coupon-service.jar | |
fi | |
if [[ "${{ needs.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 | |
fi | |
if [[ "${{ needs.changes.outputs.restaurant }}" == 'true' ]]; then | |
scp -o StrictHostKeyChecking=no -i private_key service/restaurant-service/build/libs/*.jar ${USER}@${HOST}:~/restaurant-service.jar | |
fi | |
- name: 기타 서비스들 실행 | |
env: | |
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }} | |
HOST: ${{ secrets.DEV_EC2_HOST3 }} | |
USER: ${{ secrets.DEV_EC2_USER }} | |
run: | | |
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF | |
if [[ "${{ needs.changes.outputs.cache }}" == 'true' ]]; then | |
pkill -f 'java -jar cache-service.jar' || true | |
nohup java -jar cache-service.jar --spring.profiles.active=dev > cache-service.log 2>&1 & | |
fi | |
if [[ "${{ needs.changes.outputs.advertisement }}" == 'true' ]]; then | |
pkill -f 'java -jar advertisement-service.jar' || true | |
nohup java -jar advertisement-service.jar --spring.profiles.active=dev > advertisement-service.log 2>&1 & | |
fi | |
if [[ "${{ needs.changes.outputs.coupon }}" == 'true' ]]; then | |
pkill -f 'java -jar coupon-service.jar' || true | |
nohup java -jar coupon-service.jar --spring.profiles.active=dev > coupon-service.log 2>&1 & | |
fi | |
if [[ "${{ needs.changes.outputs.delivery-time }}" == 'true' ]]; then | |
pkill -f 'java -jar delivery-time-service.jar' || true | |
nohup java -jar delivery-time-service.jar --spring.profiles.active=dev > delivery-time-service.log 2>&1 & | |
fi | |
if [[ "${{ needs.changes.outputs.restaurant }}" == 'true' ]]; then | |
pkill -f 'java -jar restaurant-service.jar' || true | |
nohup java -jar restaurant-service.jar --spring.profiles.active=dev > restaurant-service.log 2>&1 & | |
fi | |
EOF |