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: CD with Gradle | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Build with Gradle Wrapper | |
| run: | | |
| chmod +x ./gradlew | |
| ./gradlew build -x test | |
| - name: Rename JAR | |
| run: | | |
| JAR_NAME=$(ls build/libs/*.jar | grep -v 'plain' | head -n 1) | |
| echo "JAR_NAME=$JAR_NAME" >> $GITHUB_ENV | |
| - name: Transfer JAR to EC2 | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ec2-user | |
| key: ${{ secrets.SSH_KEY }} | |
| source: "build/libs/app.jar" | |
| target: "/home/ec2-user/friendpass/backend/" | |
| - name: Deploy with Docker Compose | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ec2-user | |
| key: ${{ secrets.SSH_KEY }} | |
| script: | | |
| cd ~/friendpass | |
| docker compose up -d --build spring | |
| docker image prune -f |