Skip to content

[FEAT] CI/CD 파일 수정 #3

[FEAT] CI/CD 파일 수정

[FEAT] CI/CD 파일 수정 #3

Workflow file for this run

name: Deploy Backend to EC2
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Create SSH key file
run: |
echo "${{ secrets.EC2_SSH_KEY }}" > private_key.pem
chmod 600 private_key.pem
- name: Deploy to EC2
run: |
scp -i private_key.pem -o StrictHostKeyChecking=no \
build/libs/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/app.jar
ssh -i private_key.pem -o StrictHostKeyChecking=no \
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
sudo systemctl restart studylink
sudo systemctl status studylink
EOF
- name: Clean up
if: always()
run: rm -f private_key.pem
- name: Send deployment notification
if: success()
run: echo "Deployment successful!"