Dockerfile 수정 #19
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 main merge | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Build JAR | |
| run: ./gradlew clean build -x test | |
| - name: Upload JAR to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: build/libs/*.jar | |
| target: /home/ubuntu/app/app.jar | |
| - name: SSH and deploy Docker container | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| docker pull your-docker-image:latest || true | |
| docker stop myapp || true | |
| docker rm myapp || true | |
| docker run -d --name myapp --env-file /home/ubuntu/app/.env -p 8080:8080 openjdk:17-jdk java -jar /home/ubuntu/app/app.jar |