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