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