deploy_collab.yml

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