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@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: cargo xtask 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@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@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 elif [[ $GITHUB_REF_NAME = "collab-staging" ]]; then
107 export ZED_KUBE_NAMESPACE=staging
108 export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=1
109 export ZED_API_LOAD_BALANCER_SIZE_UNIT=1
110 else
111 echo "cowardly refusing to deploy from an unknown branch"
112 exit 1
113 fi
114
115 echo "Deploying collab:$GITHUB_SHA to $ZED_KUBE_NAMESPACE"
116
117 source script/lib/deploy-helpers.sh
118 export_vars_for_environment $ZED_KUBE_NAMESPACE
119
120 export ZED_DO_CERTIFICATE_ID=$(doctl compute certificate list --format ID --no-header)
121 export ZED_IMAGE_ID="registry.digitalocean.com/zed/collab:${GITHUB_SHA}"
122
123 export ZED_SERVICE_NAME=collab
124 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT
125 envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
126 kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/$ZED_SERVICE_NAME --watch
127 echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"
128
129 export ZED_SERVICE_NAME=api
130 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_API_LOAD_BALANCER_SIZE_UNIT
131 envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
132 kubectl -n "$ZED_KUBE_NAMESPACE" rollout status deployment/$ZED_SERVICE_NAME --watch
133 echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"