|
| 1 | +name: Test and Deploy Pipeline |
| 2 | + |
| 3 | +env: |
| 4 | + build_number: ${{ github.run_id }} |
| 5 | + |
| 6 | +concurrency: |
| 7 | + group: production |
| 8 | + cancel-in-progress: true |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - master |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-web: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + environment: production |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Login to Docker Hub |
| 24 | + uses: docker/login-action@v3 |
| 25 | + with: |
| 26 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 27 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Set up Docker Buildx |
| 30 | + uses: docker/setup-buildx-action@v3 |
| 31 | + |
| 32 | + - name: Build and push |
| 33 | + uses: docker/build-push-action@v6 |
| 34 | + with: |
| 35 | + file: ./Dockerfile |
| 36 | + context: . |
| 37 | + push: true |
| 38 | + tags: mltshp/mltshp-web:build-${{ env.build_number }} |
| 39 | + |
| 40 | + build-worker: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + environment: production |
| 43 | + steps: |
| 44 | + - name: Checkout code |
| 45 | + uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Login to Docker Hub |
| 48 | + uses: docker/login-action@v3 |
| 49 | + with: |
| 50 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 51 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Set up Docker Buildx |
| 54 | + uses: docker/setup-buildx-action@v3 |
| 55 | + |
| 56 | + - name: Build and push |
| 57 | + uses: docker/build-push-action@v6 |
| 58 | + with: |
| 59 | + file: ./Dockerfile.worker |
| 60 | + context: . |
| 61 | + push: true |
| 62 | + tags: mltshp/mltshp-worker:build-${{ env.build_number }} |
| 63 | + |
| 64 | + test: |
| 65 | + needs: [build-web] |
| 66 | + runs-on: ubuntu-latest |
| 67 | + steps: |
| 68 | + - name: Checkout code |
| 69 | + uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Pull and tag web image |
| 72 | + run: | |
| 73 | + docker pull mltshp/mltshp-web:build-${{ env.build_number }} |
| 74 | + docker tag mltshp/mltshp-web:build-${{ env.build_number }} mltshp/mltshp-web:latest |
| 75 | +
|
| 76 | + - name: Start services with Docker Compose |
| 77 | + run: docker compose -f release/docker-compose.yml up -d |
| 78 | + |
| 79 | + - name: Wait for services to be ready |
| 80 | + run: sleep 10 |
| 81 | + |
| 82 | + - name: Run tests |
| 83 | + run: docker exec -t release-mltshp-1 ./run-tests.sh |
| 84 | + |
| 85 | + - name: Run Coveralls report |
| 86 | + env: |
| 87 | + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} |
| 88 | + run: docker exec -t -e COVERALLS_REPO_TOKEN release-mltshp-1 ./coveralls-report.sh |
| 89 | + |
| 90 | + - name: Stop services and clean up |
| 91 | + run: | |
| 92 | + docker compose -f release/docker-compose.yml down |
| 93 | + docker container prune -f |
| 94 | +
|
| 95 | + deploy: |
| 96 | + needs: [test, build-worker] |
| 97 | + runs-on: ubuntu-latest |
| 98 | + environment: production |
| 99 | + if: success() |
| 100 | + steps: |
| 101 | + - name: Login to Docker Hub |
| 102 | + uses: docker/login-action@v3 |
| 103 | + with: |
| 104 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 105 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 106 | + |
| 107 | + - name: Pull and tag web image |
| 108 | + run: | |
| 109 | + docker pull mltshp/mltshp-web:build-${{ env.build_number }} |
| 110 | + docker tag mltshp/mltshp-web:build-${{ env.build_number }} mltshp/mltshp-web:latest |
| 111 | + docker push mltshp/mltshp-web:latest |
| 112 | +
|
| 113 | + - name: Pull and tag worker image |
| 114 | + run: | |
| 115 | + docker pull mltshp/mltshp-worker:build-${{ env.build_number }} |
| 116 | + docker tag mltshp/mltshp-worker:build-${{ env.build_number }} mltshp/mltshp-worker:latest |
| 117 | + docker push mltshp/mltshp-worker:latest |
| 118 | +
|
| 119 | + - name: Notify Slack |
| 120 | + uses: 8398a7/action-slack@v3 |
| 121 | + with: |
| 122 | + status: success |
| 123 | + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took |
| 124 | + env: |
| 125 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments