deploy_collab.yml

  1name: Publish Collab Server Image
  2
  3on:
  4  push:
  5    tags:
  6      - collab-production
  7      - collab-staging
  8
  9env:
 10  DOCKER_BUILDKIT: 1
 11  DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
 12
 13jobs:
 14  style:
 15    name: Check formatting and Clippy lints
 16    runs-on:
 17      - self-hosted
 18      - test
 19    steps:
 20      - name: Checkout repo
 21        uses: actions/checkout@v4
 22        with:
 23          clean: false
 24          submodules: "recursive"
 25          fetch-depth: 0
 26
 27      - name: Run style checks
 28        uses: ./.github/actions/check_style
 29
 30      - name: Run clippy
 31        shell: bash -euxo pipefail {0}
 32        run: script/clippy
 33
 34  tests:
 35    name: Run tests
 36    runs-on:
 37      - self-hosted
 38      - test
 39    needs: style
 40    steps:
 41      - name: Checkout repo
 42        uses: actions/checkout@v4
 43        with:
 44          clean: false
 45          submodules: "recursive"
 46          fetch-depth: 0
 47
 48      - name: Install cargo nextest
 49        shell: bash -euxo pipefail {0}
 50        run: |
 51          cargo install cargo-nextest
 52
 53      - name: Limit target directory size
 54        shell: bash -euxo pipefail {0}
 55        run: script/clear-target-dir-if-larger-than 100
 56
 57      - name: Run tests
 58        shell: bash -euxo pipefail {0}
 59        run: cargo nextest run --package collab --no-fail-fast
 60
 61  publish:
 62    name: Publish collab server image
 63    needs:
 64      - style
 65      - tests
 66    runs-on:
 67      - self-hosted
 68      - deploy
 69    steps:
 70      - name: Add Rust to the PATH
 71        run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
 72
 73      - name: Sign into DigitalOcean docker registry
 74        run: doctl registry login
 75
 76      - name: Checkout repo
 77        uses: actions/checkout@v4
 78        with:
 79          clean: false
 80          submodules: "recursive"
 81
 82      - name: Build docker image
 83        run: docker build . --build-arg GITHUB_SHA=$GITHUB_SHA --tag registry.digitalocean.com/zed/collab:$GITHUB_SHA
 84
 85      - name: Publish docker image
 86        run: docker push registry.digitalocean.com/zed/collab:${GITHUB_SHA}
 87
 88      - name: Prune Docker system
 89        run: docker system prune  --filter 'until=72h' -f
 90
 91  deploy:
 92    name: Deploy new server image
 93    needs:
 94      - publish
 95    runs-on:
 96      - self-hosted
 97      - deploy
 98
 99    steps:
100      - name: Sign into Kubernetes
101        run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.CLUSTER_NAME }}
102
103      - name: Start rollout
104        run: |
105          set -eu
106          if [[ $GITHUB_REF_NAME = "collab-production" ]]; then
107            export ZED_KUBE_NAMESPACE=production
108          elif [[ $GITHUB_REF_NAME = "collab-staging" ]]; then
109            export ZED_KUBE_NAMESPACE=staging
110          else
111            echo "cowardly refusing to deploy from an unknown branch"
112            exit 1
113          fi
114
115          echo "Deploying collab:$GITHUB_SHA to $ZED_KUBE_NAMESPACE"
116
117          source script/lib/deploy-helpers.sh
118          export_vars_for_environment $ZED_KUBE_NAMESPACE
119
120          export ZED_DO_CERTIFICATE_ID=$(doctl compute certificate list --format ID --no-header)
121          export ZED_IMAGE_ID="registry.digitalocean.com/zed/collab:${GITHUB_SHA}"
122
123          envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
124          kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/collab --watch
125          echo "deployed collab.template.yml to ${ZED_KUBE_NAMESPACE}"