#64 [ENV] : 스크립트 수정 #29
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-Dev CI/CD | |
on: | |
push: | |
branches: [ "main", "env/cd" ] | |
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-dev.yml | |
run: | | |
#mkdir -p ./src/main/resources | |
cd ./src/main/resources | |
touch ./application-dev.yaml | |
echo "${{ secrets.TOGETUP_PROD_APPLICATION }}" >> ./application-dev.yaml | |
shell: bash | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew 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 | |
rm: false | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
port: 22 | |
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 "#### RUN $SOURCE_DIR/$FILE_NAME ####" | |
cd app | |
sudo nohup java -jar $FILE_NAME 2>&1 & | |
echo "PID : $PID" | |