Repository navigation
feat: implement MVP2 companion sharing feature #20
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: Spring CI | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| - develop | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "17" | |
| cache: gradle | |
| - name: Grant execute permission for Gradle | |
| run: chmod +x ./gradlew | |
| - name: Run tests | |
| run: ./gradlew test --no-daemon | |
| build-and-push: | |
| needs: test | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set Docker image name | |
| id: image | |
| run: echo "name=${{ secrets.DOCKERHUB_USERNAME }}/server-team5" >> "$GITHUB_OUTPUT" | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ${{ steps.image.outputs.name }}:latest | |
| ${{ steps.image.outputs.name }}:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy: | |
| needs: build-and-push | |
| if: github.event_name != 'pull_request' && github.ref == 'refs/heads/develop' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Configure SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/ec2.pem | |
| chmod 600 ~/.ssh/ec2.pem | |
| ssh-keyscan -H "${{ secrets.EC2_HOST }}" >> ~/.ssh/known_hosts | |
| - name: Upload compose file | |
| run: | | |
| ssh -o BatchMode=yes -i ~/.ssh/ec2.pem "${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}" "mkdir -p ~/server-team5" | |
| scp -o BatchMode=yes -i ~/.ssh/ec2.pem compose.prod.yml "${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:~/server-team5/compose.prod.yml" | |
| - name: Deploy to EC2 | |
| run: | | |
| ssh -o BatchMode=yes -i ~/.ssh/ec2.pem "${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}" << 'EOF' | |
| set -e | |
| cd ~/server-team5 | |
| docker compose -f compose.prod.yml pull app | |
| docker compose -f compose.prod.yml up -d | |
| healthy=false | |
| for attempt in $(seq 1 30); do | |
| if curl --fail --silent http://127.0.0.1:8080/actuator/health > /dev/null; then | |
| echo "Application is healthy" | |
| healthy=true | |
| break | |
| fi | |
| sleep 2 | |
| done | |
| if [ "$healthy" != "true" ]; then | |
| docker compose -f compose.prod.yml logs app | |
| exit 1 | |
| fi | |
| EOF |