datahaven/.github/workflows/task-build-operator.yml
Tim B 1997c298a1
refactor: 🐳 Improve docker caching (again) (#86)
## Changes

- New CI file for making Docker Prod images
- Changed E2E tests use an image built from a local dockerfile
- Some cargo build options to make it quicker
- Fix the cache hit rate
- added `tsgo` preview to the project 😎
  - Can be invoked with `bun tsgo` to typecheck
- Install in IDE
[VSCode](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace)
& [Zed](https://github.com/zed-extensions/tsgo) for super-fast inline
typechecking (as you type basically)

## Context

This PR attempts to make the frankly unacceptable CI times better. This
achieves that aim by making a crappy image for day-to-day usage and let
the prod issue take ages since that will be infrequently used. The
reason why the original design didn't work for us is because: 1) we are
using the free GH runners 2) when we goto baremetal runners we'll lose
our rapid caching abilities which make using docker cheap.

Also, we add `tsgo` support to improve devex. The improvement is
astounding.

```sh
hyperfine -n tsc "bun tsc --incremental false --extendedDiagnostics" -n tsgo "bun tsgo --incremental false --extendedDiagnostics"
Benchmark 1: tsc
  Time (mean ± σ):      5.500 s ±  0.221 s    [User: 8.939 s, System: 0.400 s]
  Range (min … max):    5.196 s …  5.845 s    10 runs
 
Benchmark 2: tsgo
  Time (mean ± σ):      99.1 ms ±   8.4 ms    [User: 392.8 ms, System: 54.1 ms]
  Range (min … max):    88.3 ms … 116.0 ms    29 runs
 
Summary
  tsgo ran
   55.48 ± 5.22 times faster than tsc
```
2025-05-27 16:14:15 +00:00

72 lines
No EOL
2.3 KiB
YAML

# Build Operator: CI for building the operator binary
name: DataHave Operator Rust Tests
on:
workflow_dispatch:
workflow_call:
outputs:
binary-hash:
description: "The hash of the operator binary"
value: ${{ jobs.build-node.outputs.binary-hash }}
jobs:
build-node:
outputs:
binary-hash: ${{ steps.hash-binary.outputs.datahaven-node-hash }}
name: Build operator binary
runs-on: ubuntu-latest
env:
RUSTC_WRAPPER: "sccache"
CARGO_INCREMENTAL: "0"
CARGO_TERM_COLOR: always
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=mold"
SCCACHE_GHA_ENABLED: "true"
defaults:
run:
working-directory: ./operator
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 1
# Re-enable if you get GH issues with the runner being full
# - uses: ./.github/workflows/actions/cleanup-runner
- uses: ./.github/workflows/actions/setup-env
with:
cache-key: BUILD-RELEASE
install-deps: true
- name: Build node binary
run: |
cargo build --release --locked --features fast-runtime
- name: Prepare binary
run: |
mkdir -p ./target/ci
mkdir -p ./target/x86_64-unknown-linux-gnu/release
cp ./target/release/datahaven-node ./target/ci/datahaven-node
cp ./target/release/datahaven-node ./target/x86_64-unknown-linux-gnu/release/datahaven-node
- name: Hash binary
id: hash-binary
run: |
TIMESTAMP=$(date +%s)
BINARY_PATH=./target/ci/datahaven-node
HASH=$(echo "$TIMESTAMP" | cat - $BINARY_PATH | sha256sum | awk '{ print $1 }')
echo "datahaven-node-hash=$HASH" >> $GITHUB_OUTPUT
echo "Hash of the datahaven-node is: $HASH (with timestamp: $TIMESTAMP)"
- name: Upload binary to workflow
uses: actions/upload-artifact@v4
with:
name: datahaven-node-${{ steps.hash-binary.outputs.datahaven-node-hash }}
path: operator/target/x86_64-unknown-linux-gnu/release/datahaven-node
retention-days: 1
- name: Build Stats
run: |
sccache --show-stats
echo "Binary size: $(du -h ./target/ci/datahaven-node | cut -f1)"