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