|
| 1 | +name: Build and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v3.*.*" |
| 7 | + |
| 8 | +env: |
| 9 | + DEPLOYMENT: "web-v3" |
| 10 | + CLUSTER: "pickup-cluster" |
| 11 | + |
| 12 | +jobs: |
| 13 | + push_to_registry: |
| 14 | + name: Push Docker image to Docker Hub |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Check out the repo |
| 18 | + uses: actions/checkout@v3 |
| 19 | + with: |
| 20 | + ref: v3 |
| 21 | + |
| 22 | + - name: Log in to Docker Hub |
| 23 | + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 |
| 24 | + with: |
| 25 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 26 | + password: ${{ secrets.DOCKER_TOKEN }} |
| 27 | + |
| 28 | + - name: Extract metadata (tags, labels) for Docker |
| 29 | + id: meta |
| 30 | + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 |
| 31 | + with: |
| 32 | + images: joinpickup/web-v3 |
| 33 | + tags: latest, ${{ github.ref_name }} |
| 34 | + |
| 35 | + - name: Build and push Docker image |
| 36 | + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc |
| 37 | + with: |
| 38 | + context: ./code |
| 39 | + push: true |
| 40 | + tags: ${{ steps.meta.outputs.tags }} |
| 41 | + labels: ${{ steps.meta.outputs.labels }} |
| 42 | + deploy: |
| 43 | + needs: push_to_registry |
| 44 | + runs-on: ubuntu-latest |
| 45 | + steps: |
| 46 | + - name: Check out the repo |
| 47 | + uses: actions/checkout@v3 |
| 48 | + with: |
| 49 | + ref: v3 |
| 50 | + |
| 51 | + - name: Install Doctl |
| 52 | + uses: digitalocean/action-doctl@v2 |
| 53 | + with: |
| 54 | + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} |
| 55 | + |
| 56 | + - name: Save DigitalOcean kubeconfig with short-lived credentials |
| 57 | + run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 $(echo $CLUSTER) |
| 58 | + |
| 59 | + - name: Deploy to DigitalOcean Kubernetes |
| 60 | + run: sed -e 's|$TAG|${{ github.ref_name }}|g' -e 's|$VERSION|${{ github.ref_name }}|g' $GITHUB_WORKSPACE/iac/deployment-v3.yaml | kubectl apply -f - |
| 61 | + |
| 62 | + - name: Verify deployment |
| 63 | + run: kubectl -n prod rollout status deployment/$(echo $DEPLOYMENT) |
0 commit comments