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
 12jobs:
 13  style:
 14    name: Check formatting and Clippy lints
 15    if: github.repository_owner == 'zed-industries'
 16    runs-on:
 17      - namespace-profile-16x32-ubuntu-2204
 18    steps:
 19      - name: Checkout repo
 20        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
 21        with:
 22          clean: false
 23          fetch-depth: 0
 24
 25      - name: Run style checks
 26        uses: ./.github/actions/check_style
 27
 28      - name: Run clippy
 29        run: ./script/clippy
 30
 31  tests:
 32    name: Run tests
 33    runs-on:
 34      - namespace-profile-16x32-ubuntu-2204
 35    needs: style
 36    steps:
 37      - name: Checkout repo
 38        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
 39        with:
 40          clean: false
 41          fetch-depth: 0
 42
 43      - name: Install cargo nextest
 44        uses: taiki-e/install-action@nextest
 45
 46      - name: Limit target directory size
 47        shell: bash -euxo pipefail {0}
 48        run: script/clear-target-dir-if-larger-than 300
 49
 50      - name: Run tests
 51        shell: bash -euxo pipefail {0}
 52        run: cargo nextest run --package collab --no-fail-fast
 53
 54  publish:
 55    name: Publish collab server image
 56    needs:
 57      - style
 58      - tests
 59    runs-on:
 60      - namespace-profile-16x32-ubuntu-2204
 61    steps:
 62      - name: Install doctl
 63        uses: digitalocean/action-doctl@v2
 64        with:
 65          token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
 66
 67      - name: Sign into DigitalOcean docker registry
 68        run: doctl registry login
 69
 70      - name: Checkout repo
 71        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
 72        with:
 73          clean: false
 74
 75      - name: Build docker image
 76        run: |
 77          docker build -f Dockerfile-collab \
 78            --build-arg "GITHUB_SHA=$GITHUB_SHA" \
 79            --tag "registry.digitalocean.com/zed/collab:$GITHUB_SHA" \
 80            .
 81
 82      - name: Publish docker image
 83        run: docker push "registry.digitalocean.com/zed/collab:${GITHUB_SHA}"
 84
 85      - name: Prune Docker system
 86        run: docker system prune  --filter 'until=72h' -f
 87
 88  deploy:
 89    name: Deploy new server image
 90    needs:
 91      - publish
 92    runs-on:
 93      - namespace-profile-16x32-ubuntu-2204
 94
 95    steps:
 96      - name: Checkout repo
 97        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
 98        with:
 99          clean: false
100
101      - name: Install doctl
102        uses: digitalocean/action-doctl@v2
103        with:
104          token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
105
106      - name: Sign into Kubernetes
107        run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.CLUSTER_NAME }}
108
109      - name: Start rollout
110        run: |
111          set -eu
112          if [[ $GITHUB_REF_NAME = "collab-production" ]]; then
113            export ZED_KUBE_NAMESPACE=production
114            export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=10
115            export ZED_API_LOAD_BALANCER_SIZE_UNIT=2
116          elif [[ $GITHUB_REF_NAME = "collab-staging" ]]; then
117            export ZED_KUBE_NAMESPACE=staging
118            export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=1
119            export ZED_API_LOAD_BALANCER_SIZE_UNIT=1
120          else
121            echo "cowardly refusing to deploy from an unknown branch"
122            exit 1
123          fi
124
125          echo "Deploying collab:$GITHUB_SHA to $ZED_KUBE_NAMESPACE"
126
127          source script/lib/deploy-helpers.sh
128          export_vars_for_environment $ZED_KUBE_NAMESPACE
129
130          ZED_DO_CERTIFICATE_ID="$(doctl compute certificate list --format ID --no-header)"
131          export ZED_DO_CERTIFICATE_ID
132          export ZED_IMAGE_ID="registry.digitalocean.com/zed/collab:${GITHUB_SHA}"
133
134          export ZED_SERVICE_NAME=collab
135          export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT
136          export DATABASE_MAX_CONNECTIONS=850
137          envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
138          kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/$ZED_SERVICE_NAME --watch
139          echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"
140
141          export ZED_SERVICE_NAME=api
142          export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_API_LOAD_BALANCER_SIZE_UNIT
143          export DATABASE_MAX_CONNECTIONS=60
144          envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
145          kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/$ZED_SERVICE_NAME --watch
146          echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"