공지수정 #50
This file contains hidden or 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: Deploy to EC2 | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source 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 to gradlew | |
| run: chmod +x ./gradlew | |
| - name: Build .jar (excluding tests) | |
| run: ./gradlew clean build -x test | |
| - name: Install rsync | |
| run: sudo apt-get update && sudo apt-get install -y rsync | |
| - name: Create SSH Key file | |
| run: | | |
| echo "${{ secrets.EC2_SSH_KEY }}" > outline-key.pem | |
| chmod 600 outline-key.pem | |
| - name: Upload .jar to EC2 with rsync | |
| run: | | |
| rsync -avz -e "ssh -i outline-key.pem -o StrictHostKeyChecking=no" ./build/libs/outline-0.0.1-SNAPSHOT.jar ubuntu@${{ secrets.EC2_HOST }}:~/outline/build/libs/ | |
| - name: Restart docker-compose on EC2 | |
| run: | | |
| ssh -i outline-key.pem -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_HOST }} << 'EOF' | |
| cd ~/outline | |
| sudo docker-compose down | |
| sudo docker-compose up -d --build | |
| EOF | |
| - name: Delete SSH Key | |
| run: rm -f outline-key.pem |