Update Readme #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: Tradin_CD | |
| on: | |
| push: | |
| branches: [ dev ] | |
| workflow_dispatch: | |
| env: | |
| DOCKER_IMAGE: zaaan/tradin | |
| DOCKER_TAG: latest | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| 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: Build with Gradle | |
| run: ./gradlew :Tradin-Api:build -x test | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Deploy to Home Server | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.HOME_SERVER_HOST }} | |
| username: ${{ secrets.HOME_SERVER_USERNAME }} | |
| password: ${{ secrets.HOME_SERVER_PASSWORD }} | |
| port: ${{ secrets.HOME_SERVER_PORT }} | |
| script: | | |
| # Pull latest image | |
| docker pull ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} | |
| # Update the stack with rolling update (Docker Swarm handles rolling updates automatically) | |
| docker stack deploy -c docker-stack.yml tradin | |
| # Wait for services to be ready | |
| sleep 10 | |
| # Check service status | |
| docker service ls --filter name=tradin_api | |
| # Show recent logs | |
| docker service logs --tail 50 tradin_api |