Skip to content

Merge pull request #300 from team9502/dev #102

Merge pull request #300 from team9502/dev

Merge pull request #300 from team9502/dev #102

Workflow file for this run

name: sinChul
on:
workflow_dispatch:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: gradlew bootJar
run: ./gradlew bootJar
- name: copy jar to Green server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
source: "./build/libs/*.jar"
target: "/home/ec2-user"
strip_components: 2
- name: Stop existing Green Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
PID=$(lsof -t -i:8081)
if [ -n "$PID" ]; then
sudo kill -9 $PID
fi
- name: Deploy to Green Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
export API_KEY="${{ secrets.API_KEY }}"
export JDBC_URL="${{ secrets.JDBC_URL }}"
export JDBC_USERNAME="${{ secrets.JDBC_USERNAME }}"
export JDBC_PASSWORD="${{ secrets.JDBC_PASSWORD }}"
export ENCRYPTION_SECRET_KEY="${{ secrets.ENCRYPTION_SECRET_KEY }}"
export JWT_SECRETKEY="${{ secrets.JWT_SECRETKEY }}"
export API_SERVICE_KEY="${{ secrets.API_SERVICE_KEY }}"
export S3_ACCESS_KEY="${{ secrets.S3_ACCESS_KEY }}"
export S3_NAME="${{ secrets.S3_NAME }}"
export S3_REGION="${{ secrets.S3_REGION }}"
export SECRET_ACCESS_KEY="${{ secrets.SECRET_ACCESS_KEY }}"
export GOOGLE_ACCOUNT="${{ secrets.GOOGLE_ACCOUNT }}"
export GOOGLE_PASSWORD="${{ secrets.GOOGLE_PASSWORD }}"
export GOOGLE_CLIENT_ID="${{ secrets.GOOGLE_CLIENT_ID }}"
export GOOGLE_CLIENT_SECRET="${{ secrets.GOOGLE_CLIENT_SECRET }}"
export GOOGLE_REDIRECT_URI="${{ secrets.GOOGLE_REDIRECT_URI }}"
# Green ์„œ๋ฒ„์— ์ƒˆ ๋ฒ„์ „ ๋ฐฐํฌ
nohup java -jar /home/ec2-user/*.jar --server.port=8081 > nohup_green.out 2>&1 &
- name: Wait for Green Server to start
run: sleep 30 # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹œ์ž‘ ๋Œ€๊ธฐ ์‹œ๊ฐ„ (์ดˆ ๋‹จ์œ„๋กœ ์กฐ์ • ๊ฐ€๋Šฅ)
- name: Verify Green Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
curl -f http://localhost:8081/aws || exit 1
- name: Update Nginx to point to Green Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.NGINX_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
sudo sed -i 's/proxy_pass http:\/\/app_blue;/proxy_pass http:\/\/app_green;/' /etc/nginx/nginx.conf
if ! sudo systemctl is-active --quiet nginx; then
sudo systemctl start nginx
fi
sudo nginx -t && sudo nginx -s reload
- name: Clean up Blue Server and deploy new version
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
PID=$(lsof -t -i:8080)
if [ -n "$PID" ]; then
sudo kill -9 $PID
fi
export API_KEY="${{ secrets.API_KEY }}"
export JDBC_URL="${{ secrets.JDBC_URL }}"
export JDBC_USERNAME="${{ secrets.JDBC_USERNAME }}"
export JDBC_PASSWORD="${{ secrets.JDBC_PASSWORD }}"
export ENCRYPTION_SECRET_KEY="${{ secrets.ENCRYPTION_SECRET_KEY }}"
export JWT_SECRETKEY="${{ secrets.JWT_SECRETKEY }}"
export API_SERVICE_KEY="${{ secrets.API_SERVICE_KEY }}"
export S3_ACCESS_KEY="${{ secrets.S3_ACCESS_KEY }}"
export S3_NAME="${{ secrets.S3_NAME }}"
export S3_REGION="${{ secrets.S3_REGION }}"
export SECRET_ACCESS_KEY="${{ secrets.SECRET_ACCESS_KEY }}"
export GOOGLE_ACCOUNT="${{ secrets.GOOGLE_ACCOUNT }}"
export GOOGLE_PASSWORD="${{ secrets.GOOGLE_PASSWORD }}"
export GOOGLE_CLIENT_ID="${{ secrets.GOOGLE_CLIENT_ID }}"
export GOOGLE_CLIENT_SECRET="${{ secrets.GOOGLE_CLIENT_SECRET }}"
export GOOGLE_REDIRECT_URI="${{ secrets.GOOGLE_REDIRECT_URI }}"
nohup java -jar /home/ec2-user/*.jar --server.port=8080 > nohup_blue.out 2>&1 &
- name: Update Nginx to point to Blue Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.NGINX_HOST }}
username: ec2-user
key: ${{ secrets.SSH_KEY }}
port: 22
script_stop: true
script: |
sudo sed -i 's/proxy_pass http:\/\/app_green;/proxy_pass http:\/\/app_blue;/' /etc/nginx/nginx.conf
if ! sudo systemctl is-active --quiet nginx; then
sudo systemctl start nginx
fi
sudo nginx -t && sudo nginx -s reload
env:
API_KEY: ${{ secrets.API_KEY }}
JDBC_URL: ${{ secrets.JDBC_URL }}
JDBC_USERNAME: ${{ secrets.JDBC_USERNAME }}
JDBC_PASSWORD: ${{ secrets.JDBC_PASSWORD }}
ENCRYPTION_SECRET_KEY: ${{ secrets.ENCRYPTION_SECRET_KEY }}
JWT_SECRETKEY: ${{ secrets.JWT_SECRETKEY }}
API_SERVICE_KEY: ${{ secrets.API_SERVICE_KEY }}
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
S3_NAME: ${{ secrets.S3_NAME }}
S3_REGION: ${{ secrets.S3_REGION }}
SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
GOOGLE_ACCOUNT: ${{ secrets.GOOGLE_ACCOUNT }}
GOOGLE_PASSWORD: ${{ secrets.GOOGLE_PASSWORD }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_REDIRECT_URI: ${{ secrets.GOOGLE_REDIRECT_URI }}