Deploy and Start services by caniro #35
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: CI/CD Deploy and Start services | |
| run-name: Deploy and Start services by ${{github.actor}} | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'src/**' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Build with Gradle Wrapper | |
| run: ./gradlew build -x test | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{secrets.DOCKER_USERNAME}} | |
| password: ${{secrets.DOCKER_TOKEN}} | |
| - name: Build and Push Docker Image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{secrets.DOCKER_USERNAME}}/if-be:latest | |
| start-services: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Connect to cloud server and run Docker commands | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{secrets.CLOUD_HOST}} | |
| username: ${{secrets.CLOUD_USERNAME}} | |
| key: ${{secrets.CLOUD_SECRET_KEY}} | |
| port: ${{secrets.CLOUD_PORT}} | |
| script: | | |
| cd ~ | |
| /bin/bash deploy_spring.sh |