fix : 스크립트 수정 #3
Workflow file for this run
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: TogetUp-Server-Prod CI/CD | |
on: | |
push: | |
branches: [ "product","env/prod" ] | |
env: | |
S3_BUCKET_NAME: togetup-storage | |
FILE_PATH: /home/ubuntu/app/ | |
FILE_NAME: TogetUp-0.0.1-SNAPSHOT.jar | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Get CurrentTime | |
uses: 1466587594/get-current-time@v2 | |
id: current-time | |
with: | |
format: YYYY-MM-DDTHH-mm-ss | |
utcOffset: "+09:00" | |
- name: Show Current Time | |
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}" | |
shell: bash | |
- name: make application.yml | |
run: | | |
## create application.yml | |
mkdir -p ./src/main/resources | |
cd ./src/main/resources | |
touch ./application.yml | |
echo '${{ secrets.TOGETUP_PROD_APPLICATION }}' >> ./application.yml | |
cat ./application.yml | |
shell: bash | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build | |
- name: Deliver File | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
port: 22 | |
source: "build/libs/TogetUp-0.0.1-SNAPSHOT.jar" | |
target: "/home/ubuntu/app" | |
strip_components: 2 | |
overwrite: true | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
port: 22 | |
wait_for_deployment: false | |
script: | | |
SOURCE_DIR=/home/ubuntu/app/ | |
FILE_NAME=TogetUp-0.0.1-SNAPSHOT.jar | |
PID=$(ps aux | grep $FILE_NAME | grep -v grep | awk '{print $2}') | |
echo "PID : $PID" | |
if [ -z "$PID" ]; then | |
echo "#### THERE IS NO PROCESS ####" | |
else | |
echo "#### KILL $PID ####" | |
sudo kill $PID | |
fi | |
echo "#### RUNNING $SOURCE_DIR/$FILE_NAME ####" | |
cd $SOURCE_DIR | |
sudo nohup java -jar $FILE_NAME > nohup.out 2> nohup.err < /dev/null & | |
sleep 2 | |
echo "New PID after restart: $(ps aux | grep $FILE_NAME | grep -v grep | awk '{print $2}')" | |