1# Generated from xtask::workflows::deploy_collab
2# Rebuild with `cargo xtask workflows`.
3name: deploy_collab
4env:
5 DOCKER_BUILDKIT: '1'
6on:
7 push:
8 tags:
9 - collab-production
10jobs:
11 style:
12 if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
13 name: Check formatting and Clippy lints
14 runs-on: namespace-profile-16x32-ubuntu-2204
15 steps:
16 - name: steps::checkout_repo
17 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
18 with:
19 clean: false
20 fetch-depth: 0
21 - name: steps::setup_cargo_config
22 run: |
23 mkdir -p ./../.cargo
24 cp ./.cargo/ci-config.toml ./../.cargo/config.toml
25 - name: steps::cache_rust_dependencies_namespace
26 uses: namespacelabs/nscloud-cache-action@v1
27 with:
28 cache: rust
29 path: ~/.rustup
30 - name: steps::setup_linux
31 run: ./script/linux
32 - name: steps::install_mold
33 run: ./script/install-mold
34 - name: steps::download_wasi_sdk
35 run: ./script/download-wasi-sdk
36 - name: steps::cargo_fmt
37 run: cargo fmt --all -- --check
38 - name: steps::clippy
39 run: ./script/clippy
40 tests:
41 needs:
42 - style
43 name: Run tests
44 runs-on: namespace-profile-16x32-ubuntu-2204
45 steps:
46 - name: steps::checkout_repo
47 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
48 with:
49 clean: false
50 fetch-depth: 0
51 - name: steps::setup_cargo_config
52 run: |
53 mkdir -p ./../.cargo
54 cp ./.cargo/ci-config.toml ./../.cargo/config.toml
55 - name: steps::cache_rust_dependencies_namespace
56 uses: namespacelabs/nscloud-cache-action@v1
57 with:
58 cache: rust
59 path: ~/.rustup
60 - name: steps::setup_linux
61 run: ./script/linux
62 - name: steps::install_mold
63 run: ./script/install-mold
64 - name: steps::download_wasi_sdk
65 run: ./script/download-wasi-sdk
66 - name: steps::cargo_install_nextest
67 uses: taiki-e/install-action@nextest
68 - name: steps::clear_target_dir_if_large
69 run: ./script/clear-target-dir-if-larger-than 250
70 - name: deploy_collab::tests::run_collab_tests
71 run: cargo nextest run --package collab --no-fail-fast
72 services:
73 postgres:
74 image: postgres:15
75 env:
76 POSTGRES_HOST_AUTH_METHOD: trust
77 ports:
78 - 5432:5432
79 options: --health-cmd pg_isready --health-interval 500ms --health-timeout 5s --health-retries 10
80 publish:
81 needs:
82 - style
83 - tests
84 name: Publish collab server image
85 runs-on: namespace-profile-16x32-ubuntu-2204
86 steps:
87 - name: deploy_collab::publish::install_doctl
88 uses: digitalocean/action-doctl@v2
89 with:
90 token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
91 - name: deploy_collab::publish::sign_into_registry
92 run: doctl registry login
93 - name: steps::checkout_repo
94 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
95 with:
96 clean: false
97 - name: deploy_collab::publish::build_docker_image
98 run: |
99 docker build -f Dockerfile-collab \
100 --build-arg "GITHUB_SHA=$GITHUB_SHA" \
101 --tag "registry.digitalocean.com/zed/collab:$GITHUB_SHA" \
102 .
103 - name: deploy_collab::publish::publish_docker_image
104 run: docker push "registry.digitalocean.com/zed/collab:${GITHUB_SHA}"
105 - name: deploy_collab::publish::prune_docker_system
106 run: docker system prune --filter 'until=72h' -f
107 deploy:
108 needs:
109 - publish
110 name: Deploy new server image
111 runs-on: namespace-profile-16x32-ubuntu-2204
112 steps:
113 - name: steps::checkout_repo
114 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
115 with:
116 clean: false
117 - name: deploy_collab::deploy::install_doctl
118 uses: digitalocean/action-doctl@v2
119 with:
120 token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
121 - name: deploy_collab::deploy::sign_into_kubernetes
122 run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 "$CLUSTER_NAME"
123 env:
124 CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }}
125 - name: deploy_collab::deploy::start_rollout
126 run: |
127 set -eu
128 if [[ $GITHUB_REF_NAME = "collab-production" ]]; then
129 export ZED_KUBE_NAMESPACE=production
130 export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=10
131 export ZED_API_LOAD_BALANCER_SIZE_UNIT=2
132 elif [[ $GITHUB_REF_NAME = "collab-staging" ]]; then
133 export ZED_KUBE_NAMESPACE=staging
134 export ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT=1
135 export ZED_API_LOAD_BALANCER_SIZE_UNIT=1
136 else
137 echo "cowardly refusing to deploy from an unknown branch"
138 exit 1
139 fi
140
141 echo "Deploying collab:$GITHUB_SHA to $ZED_KUBE_NAMESPACE"
142
143 source script/lib/deploy-helpers.sh
144 export_vars_for_environment "$ZED_KUBE_NAMESPACE"
145
146 ZED_DO_CERTIFICATE_ID="$(doctl compute certificate list --format ID --no-header)"
147 export ZED_DO_CERTIFICATE_ID
148 export ZED_IMAGE_ID="registry.digitalocean.com/zed/collab:${GITHUB_SHA}"
149
150 export ZED_SERVICE_NAME=collab
151 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_COLLAB_LOAD_BALANCER_SIZE_UNIT
152 export DATABASE_MAX_CONNECTIONS=850
153 envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
154 kubectl -n "$ZED_KUBE_NAMESPACE" rollout status "deployment/$ZED_SERVICE_NAME" --watch
155 echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"
156
157 export ZED_SERVICE_NAME=api
158 export ZED_LOAD_BALANCER_SIZE_UNIT=$ZED_API_LOAD_BALANCER_SIZE_UNIT
159 export DATABASE_MAX_CONNECTIONS=60
160 envsubst < crates/collab/k8s/collab.template.yml | kubectl apply -f -
161 kubectl -n "$ZED_KUBE_NAMESPACE" rollout status "deployment/$ZED_SERVICE_NAME" --watch
162 echo "deployed ${ZED_SERVICE_NAME} to ${ZED_KUBE_NAMESPACE}"
163defaults:
164 run:
165 shell: bash -euxo pipefail {0}