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@692973e3d937129bcbf40652eb9f2f61becf3332 # 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 - test
37 needs: style
38 steps:
39 - name: Checkout repo
40 uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 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
49
50 - name: Limit target directory size
51 shell: bash -euxo pipefail {0}
52 run: script/clear-target-dir-if-larger-than 100
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 - self-hosted
65 - deploy
66 steps:
67 - name: Add Rust to the PATH
68 run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
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 - self-hosted
93 - deploy
94
95 steps:
96 - name: Sign into Kubernetes
97 run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.CLUSTER_NAME }}
98
99 - name: Start rollout
100 run: |
101 set -eu
102 if [[ $GITHUB_REF_NAME = "collab-production" ]]; then
103 export ZED_KUBE_NAMESPACE=production
104 export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=10
105 export ZED_API_LOAD_BALANCER_SIZE_UNIT=2
106 export ZED_LLM_LOAD_BALANCER_SIZE_UNIT=2
107 elif [[ $GITHUB_REF_NAME = "collab-staging" ]]; then
108 export ZED_KUBE_NAMESPACE=staging
109 export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=1
110 export ZED_API_LOAD_BALANCER_SIZE_UNIT=1
111 export ZED_LLM_LOAD_BALANCER_SIZE_UNIT=1
112 else
113 echo "cowardly refusing to deploy from an unknown branch"
114 exit 1
115 fi
116
117 echo "Deploying collab:$GITHUB_SHA to $ZED_KUBE_NAMESPACE"
118
119 source script/lib/deploy-helpers.sh
120 export_vars_for_environment $ZED_KUBE_NAMESPACE
121
122 export ZED_DO_CERTIFICATE_ID=$(doctl compute certificate list --format ID --no-header)
123 export ZED_IMAGE_ID="registry.digitalocean.com/zed/collab:${GITHUB_SHA}"
124
125 export ZED_SERVICE_NAME=collab
126 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT
127 envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
128 kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/$ZED_SERVICE_NAME --watch
129 echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"
130
131 export ZED_SERVICE_NAME=api
132 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_API_LOAD_BALANCER_SIZE_UNIT
133 envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
134 kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/$ZED_SERVICE_NAME --watch
135 echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"
136
137 export ZED_SERVICE_NAME=llm
138 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_LLM_LOAD_BALANCER_SIZE_UNIT
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}"