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 uses: taiki-e/install-action@nextest
47
48 - name: Limit target directory size
49 shell: bash -euxo pipefail {0}
50 run: script/clear-target-dir-if-larger-than 300
51
52 - name: Run tests
53 shell: bash -euxo pipefail {0}
54 run: cargo nextest run --package collab --no-fail-fast
55
56 publish:
57 name: Publish collab server image
58 needs:
59 - style
60 - tests
61 runs-on:
62 - namespace-profile-16x32-ubuntu-2204
63 steps:
64 - name: Install doctl
65 uses: digitalocean/action-doctl@v2
66 with:
67 token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
68
69 - name: Sign into DigitalOcean docker registry
70 run: doctl registry login
71
72 - name: Checkout repo
73 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
74 with:
75 clean: false
76
77 - name: Build docker image
78 run: |
79 docker build -f Dockerfile-collab \
80 --build-arg "GITHUB_SHA=$GITHUB_SHA" \
81 --tag "registry.digitalocean.com/zed/collab:$GITHUB_SHA" \
82 .
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 - namespace-profile-16x32-ubuntu-2204
96
97 steps:
98 - name: Checkout repo
99 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
100 with:
101 clean: false
102
103 - name: Install doctl
104 uses: digitalocean/action-doctl@v2
105 with:
106 token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
107
108 - name: Sign into Kubernetes
109 run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.CLUSTER_NAME }}
110
111 - name: Start rollout
112 run: |
113 set -eu
114 if [[ $GITHUB_REF_NAME = "collab-production" ]]; then
115 export ZED_KUBE_NAMESPACE=production
116 export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=10
117 export ZED_API_LOAD_BALANCER_SIZE_UNIT=2
118 elif [[ $GITHUB_REF_NAME = "collab-staging" ]]; then
119 export ZED_KUBE_NAMESPACE=staging
120 export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=1
121 export ZED_API_LOAD_BALANCER_SIZE_UNIT=1
122 else
123 echo "cowardly refusing to deploy from an unknown branch"
124 exit 1
125 fi
126
127 echo "Deploying collab:$GITHUB_SHA to $ZED_KUBE_NAMESPACE"
128
129 source script/lib/deploy-helpers.sh
130 export_vars_for_environment $ZED_KUBE_NAMESPACE
131
132 ZED_DO_CERTIFICATE_ID="$(doctl compute certificate list --format ID --no-header)"
133 export ZED_DO_CERTIFICATE_ID
134 export ZED_IMAGE_ID="registry.digitalocean.com/zed/collab:${GITHUB_SHA}"
135
136 export ZED_SERVICE_NAME=collab
137 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT
138 export DATABASE_MAX_CONNECTIONS=850
139 envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
140 kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/$ZED_SERVICE_NAME --watch
141 echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"
142
143 export ZED_SERVICE_NAME=api
144 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_API_LOAD_BALANCER_SIZE_UNIT
145 export DATABASE_MAX_CONNECTIONS=60
146 envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
147 kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/$ZED_SERVICE_NAME --watch
148 echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"