Skip to content

Commit

Permalink
⚡️: fix CI/CD 관련 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
orijoon98 committed Mar 2, 2024
1 parent 122b4eb commit cbe2014
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/workflows/api-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches: [ develop ]
paths:
- .github/workflows/**
- plu-api/**
- plu-common/**
- plu-domain/**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/api-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches: [ main ]
paths:
- .github/workflows/**
- plu-api/**
- plu-common/**
- plu-domain/**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/api-pr-check-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches: [ develop ]
paths:
- .github/workflows/**
- plu-api/**
- plu-common/**
- plu-domain/**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/api-pr-check-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches: [ main ]
paths:
- .github/workflows/**
- plu-api/**
- plu-common/**
- plu-domain/**
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/notification-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches: [ develop ]
paths:
- .github/workflows/**
- plu-notification/**
- plu-common/**
- plu-domain/**
Expand Down Expand Up @@ -64,16 +65,16 @@ jobs:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_KEY_DEV }}
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }}
aws-region: ap-northeast-2

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./notification-code-deploy.zip s3://$AWS_S3_BUCKET/notification-code-deploy.zip

- name: Code Deploy
run: aws deploy create-deployment
--application-name plu-codedeploy
--application-name plu-application
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name NOTIFICATION
--s3-location bucket=$AWS_S3_BUCKET_NAME,bundleType=zip,key=notification-code-deploy.zip
--s3-location bucket=$AWS_S3_BUCKET,bundleType=zip,key=notification-code-deploy.zip
10 changes: 5 additions & 5 deletions .github/workflows/notification-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: notification-deploy-prod
# Controls when the workflow will run
on:
push:
branches: [ develop ]
branches: [ main ]
paths:
- plu-notification/**
- plu-common/**
Expand Down Expand Up @@ -60,16 +60,16 @@ jobs:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_KEY_DEV }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }}
aws-region: ap-northeast-2

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./notification-code-deploy.zip s3://$AWS_S3_BUCKET/notification-code-deploy.zip

- name: Code Deploy
run: aws deploy create-deployment
--application-name plu-codedeploy
--application-name plu-application
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name NOTIFICATION
--s3-location bucket=$AWS_S3_BUCKET_NAME,bundleType=zip,key=notification-code-deploy.zip
--s3-location bucket=$AWS_S3_BUCKET,bundleType=zip,key=notification-code-deploy.zip
1 change: 1 addition & 0 deletions .github/workflows/notification-pr-check-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
pull_request:
branches: [ develop ]
paths:
- .github/workflows/**
- plu-notification/**
- plu-common/**
- plu-domain/**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/notification-pr-check-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches: [ main ]
paths:
- .github/workflows/**
- plu-notification/**
- plu-common/**
- plu-domain/**
Expand Down
12 changes: 6 additions & 6 deletions scripts/plu-api/health_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ if [ ${CURRENT_PORT} -eq 8081 ]; then
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "No WAS is connected to nginx"
echo "No WAS is connected to nginx" >> /home/ubuntu/plu-api/deploy.log
exit 1
fi

echo "Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..."
echo "Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..." >> /home/ubuntu/plu-api/deploy.log

for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10
do
echo "#${RETRY_COUNT} trying..."
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/health)
echo "#${RETRY_COUNT} trying..." >> /home/ubuntu/plu-api/deploy.log
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/actuator/health)

if [ ${RESPONSE_CODE} -eq 200 ]; then
echo "New WAS successfully running"
echo "New WAS successfully running" >> /home/ubuntu/plu-api/deploy.log
exit 0
elif [ ${RETRY_COUNT} -eq 10 ]; then
echo "Health check failed."
echo "Health check failed." >> /home/ubuntu/plu-api/deploy.log
exit 1
fi
sleep 10
Expand Down
12 changes: 6 additions & 6 deletions scripts/plu-api/run_new_was.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ if [ ${CURRENT_PORT} -eq 8081 ]; then
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "[$NOW_TIME] No WAS is connected to nginx"
echo "[$NOW_TIME] No WAS is connected to nginx" >> /home/ubuntu/plu-api/deploy.log
fi

TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')

if [ ! -z ${TARGET_PID} ]; then
echo "Kill WAS running at ${TARGET_PORT}."
echo "Kill WAS running at ${TARGET_PORT}." >> /home/ubuntu/plu-api/deploy.log
sudo kill ${TARGET_PID}
fi

if [ ${HOST_NAME} == "plu-prod-server" ]; then
nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/plu-api/*.jar
echo "Now new WAS runs at ${TARGET_PORT}."
nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/plu-api/*.jar >> /home/ubuntu/plu-api/deploy.log 2>/home/ubuntu/plu-api/deploy_err.log &
echo "Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/plu-api/deploy.log
exit 0
else
nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev /home/ubuntu/plu-api/*.jar
echo "Now new WAS runs at ${TARGET_PORT}."
nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev /home/ubuntu/plu-api/*.jar >> /home/ubuntu/plu-api/deploy.log 2>/home/ubuntu/plu-api/deploy_err.log &
echo "Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/plu-api/deploy.log
exit 0
fi
10 changes: 5 additions & 5 deletions scripts/plu-api/switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S
CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0

echo "[$NOW_TIME] Nginx currently proxies to ${CURRENT_PORT}."
echo "[$NOW_TIME] Nginx currently proxies to ${CURRENT_PORT}." >> /home/ubuntu/plu-api/deploy.log

if [ ${CURRENT_PORT} -eq 8081 ]; then
TARGET_PORT=8082
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "[$NOW_TIME] No WAS is connected to nginx"
echo "[$NOW_TIME] No WAS is connected to nginx" >> /home/ubuntu/plu-api/deploy.log
exit 1
fi

echo "set \$service_url http://127.0.0.1:${TARGET_PORT};" | sudo tee /etc/nginx/conf.d/service-url.inc
echo "set \$service_url http://127.0.0.1:${TARGET_PORT};" >> /home/ubuntu/plu-api/deploy.log | sudo tee /etc/nginx/conf.d/service-url.inc

echo "[$NOW_TIME] Now Nginx proxies to ${TARGET_PORT}."
echo "[$NOW_TIME] Now Nginx proxies to ${TARGET_PORT}." >> /home/ubuntu/plu-api/deploy.log
sudo service nginx reload

echo "[$NOW_TIME] Nginx reloaded."
echo "[$NOW_TIME] Nginx reloaded." >> /home/ubuntu/plu-api/deploy.log
10 changes: 5 additions & 5 deletions scripts/plu-notification/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ TARGET_PORT=8083
TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')

if [ ! -z ${TARGET_PID} ]; then
echo "[$NOW_TIME] Kill WAS running at ${TARGET_PORT}."
echo "[$NOW_TIME] Kill WAS running at ${TARGET_PORT}." >> /home/ubuntu/plu-notification/deploy.log
sudo kill ${TARGET_PID}
fi

if [ ${HOST_NAME} == "plu-prod-server" ]; then
nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/plu-notification/*.jar
echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}."
nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/plu-notification/*.jar >> /home/ubuntu/plu-notification/deploy.log 2>/home/ubuntu/plu-notification/deploy_err.log &
echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/plu-notification/deploy.log
exit 0
else
nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev /home/ubuntu/plu-notification/*.jar
echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}."
nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev /home/ubuntu/plu-notification/*.jar >> /home/ubuntu/plu-notification/deploy.log 2>/home/ubuntu/plu-notification/deploy_err.log &
echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/plu-notification/deploy.log
exit 0
fi

0 comments on commit cbe2014

Please sign in to comment.