Delete gradle directory #8
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: | |
| - ci-cd | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Grant execute permission to gradlew | |
| run: chmod +x ./gradlew | |
| - name: Build with Gradle (skip test) | |
| run: ./gradlew clean build -x test | |
| - name: Set up SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| - name: Add EC2 host to known_hosts | |
| run: ssh-keyscan -p ${{ secrets.EC2_PORT }} ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts | |
| - name: Upload JAR to EC2 | |
| run: | | |
| scp -i ~/.ssh/id_rsa -P ${{ secrets.EC2_PORT }} build/libs/noonsongmaker-0.0.1-SNAPSHOT.jar ${{ secrets.EC2_HOST }}:/home/ec2-user/build/libs/ | |
| - name: Restart docker-compose on EC2 | |
| run: | | |
| ssh -i ~/.ssh/id_rsa -p ${{ secrets.EC2_PORT }} ${{ secrets.EC2_HOST }} << 'EOF' | |
| cd /home/ec2-user | |
| docker-compose down | |
| docker-compose up -d | |
| EOF |