chore: 배포 스크립트 수정 #16
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: Build and Deploy | |
on: | |
push: | |
branches: | |
- '**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: create application-secret.yml | |
run: | | |
# application-secret.yml 파일 생성 | |
touch ./src/main/resources/application-secret.yml | |
# GitHub-Actions 에서 설정한 값을 application-secret.yml 파일에 쓰기 | |
echo "${{ secrets.SECRET }}" > ./src/main/resources/application-secret.yml | |
- name: Grant execute permission for Gradle wrapper | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
- name: Archive WAR file | |
uses: actions/upload-artifact@v2 | |
with: | |
name: application-war | |
path: build/libs/*.war | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: application-war | |
path: ./build/libs | |
- name: Create SSH key file | |
env: | |
SCP_KEY: ${{ secrets.SCP_KEY }} | |
run: | | |
echo "${{ secrets.SCP_KEY }}" > scp_key.pem | |
chmod 600 scp_key.pem | |
- name: Verify SSH key file | |
run: ls -la scp_key.pem | |
- name: Copy WAR to EC2 | |
env: | |
SCP_USER: ${{ secrets.SCP_USER }} | |
SCP_HOST: ${{ secrets.SCP_HOST }} | |
SCP_PATH: ${{ secrets.SCP_PATH }} | |
run: | | |
scp -v -o StrictHostKeyChecking=no -i scp_key.pem ./build/libs/*.war $SCP_USER@$SCP_HOST:/home/kariskan/ROOT.war | |
- name: Deploy to Tomcat on EC2 | |
env: | |
SSH_KEY: ${{ secrets.SCP_KEY }} | |
SSH_USER: ${{ secrets.SCP_USER }} | |
SSH_HOST: ${{ secrets.SCP_HOST }} | |
run: | | |
echo "${{ secrets.SCP_KEY }}" > ssh_key.pem | |
chmod 600 ssh_key.pem | |
ssh -o StrictHostKeyChecking=no -i ssh_key.pem $SSH_USER@$SSH_HOST << EOF | |
sudo su | |
cd /home/kariskan | |
chmod +x deploy.sh | |
./deploy.sh | |
EOF |