-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEarthfile
More file actions
359 lines (325 loc) · 15.3 KB
/
Earthfile
File metadata and controls
359 lines (325 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
VERSION --cache-persist-option --global-cache 0.7
PROJECT applied-knowledge-systems/terraphim-project
IMPORT github.com/earthly/lib/rust AS rust
FROM ubuntu:20.04
ARG TARGETARCH
ARG TARGETOS
ARG TARGETPLATFORM
ARG --global tag=$TARGETOS-$TARGETARCH
ARG --global TARGETARCH
IF [ "$TARGETARCH" = amd64 ]
ARG --global ARCH=x86_64
ELSE
ARG --global ARCH=$TARGETARCH
END
WORKDIR /code
pipeline:
BUILD +build-debug-native
BUILD +fmt
BUILD +lint
BUILD +test
BUILD +build-native
BUILD +docs-pages
rustlib:
BUILD +install
BUILD +build
native:
BUILD +install-native
BUILD +build-native
# Creates a `./artifact/bin` folder with all binaries
build-all:
BUILD +build # x86_64-unknown-linux-gnu (main build working ✅)
# TODO: Fix OpenSSL cross-compilation issues for musl targets
# BUILD +cross-build --TARGET=x86_64-unknown-linux-musl
# BUILD +cross-build --TARGET=armv7-unknown-linux-musleabihf
# BUILD +cross-build --TARGET=aarch64-apple-darwin
# BUILD +cross-build --TARGET=x86_64-pc-windows-msvc
# BUILD +cross-build --TARGET=aarch64-apple-darwin
docker-all:
BUILD --platform=linux/amd64 +docker-musl --TARGET=x86_64-unknown-linux-musl
BUILD --platform=linux/arm/v7 +docker-musl --TARGET=armv7-unknown-linux-musleabihf
BUILD --platform=linux/arm64/v8 +docker-musl --TARGET=aarch64-unknown-linux-musl
# this install builds from base OS without registry dependencies
install:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN=true
RUN apt-get update -qq
RUN apt-get install -yqq --no-install-recommends build-essential bison flex ca-certificates openssl libssl-dev bc wget git curl cmake pkg-config musl-tools musl-dev libclang-dev clang llvm-dev
RUN update-ca-certificates
# Install Rust from official installer
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.88.0
ENV PATH="/root/.cargo/bin:$PATH"
ENV CARGO_HOME="/root/.cargo"
RUN rustup component add clippy
RUN rustup component add rustfmt
DO rust+INIT --keep_fingerprints=true
RUN cargo install cross --locked
RUN cargo install ripgrep
# Install Docker client for cross tool
RUN apt-get update && apt-get install -y gnupg lsb-release software-properties-common
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
RUN apt-get update && apt-get install -y docker-ce-cli
# Install common cross-compilation targets
RUN rustup target add x86_64-unknown-linux-musl
RUN rustup target add aarch64-unknown-linux-gnu
RUN rustup target add armv7-unknown-linux-musleabihf
RUN rustup target add aarch64-unknown-linux-musl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
RUN bash -c "source $HOME/.nvm/nvm.sh && nvm install 16.15.1"
RUN bash -c "source $HOME/.nvm/nvm.sh && npm install -g yarn"
# Save locally instead of pushing to registry
SAVE IMAGE terraphim_builder:local
# this install doesn't use rust lib and Earthly cache
install-native:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN=true
RUN apt-get update -qq
RUN apt-get install -yqq --no-install-recommends build-essential bison flex ca-certificates openssl libssl-dev bc wget git curl cmake pkg-config musl-tools musl-dev libclang-dev clang llvm-dev libglib2.0-dev libgtk-3-dev libsoup2.4-dev libwebkit2gtk-4.0-dev libappindicator3-dev
RUN update-ca-certificates
# Install Rust from official installer
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.88.0
ENV PATH="/root/.cargo/bin:$PATH"
ENV CARGO_HOME="/root/.cargo"
RUN rustup component add clippy
RUN rustup component add rustfmt
RUN cargo install ripgrep
RUN cargo install cross --locked
# Install Docker client for cross tool
RUN apt-get update && apt-get install -y docker.io
# Install common cross-compilation targets
RUN rustup target add x86_64-unknown-linux-musl
RUN rustup target add aarch64-unknown-linux-gnu
RUN rustup target add armv7-unknown-linux-musleabihf
RUN rustup target add aarch64-unknown-linux-musl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
RUN bash -c "source $HOME/.nvm/nvm.sh && nvm install 16.15.1"
RUN bash -c "source $HOME/.nvm/nvm.sh && npm install -g yarn"
# Save locally instead of pushing to registry
SAVE IMAGE terraphim_builder_native:local
source-native:
FROM +install-native
WORKDIR /code
CACHE --sharing shared --persist /code/vendor
COPY --keep-ts Cargo.toml Cargo.lock ./
COPY --keep-ts --dir terraphim_server terraphim_firecracker terraphim_ai_nodejs default crates ./
RUN mkdir -p .cargo
# Optimize cargo vendor for faster dependency resolution
RUN CARGO_NET_RETRY=10 CARGO_NET_TIMEOUT=60 cargo vendor > .cargo/config.toml
SAVE ARTIFACT .cargo/config.toml AS LOCAL .cargo/config.toml
SAVE ARTIFACT /code
build-native:
FROM +source-native
WORKDIR /code
# Optimize release build with parallel jobs
RUN CARGO_BUILD_JOBS=$(nproc) CARGO_NET_RETRY=10 CARGO_NET_TIMEOUT=60 cargo build --release
SAVE ARTIFACT /code/target/release/terraphim_server AS LOCAL artifact/bin/terraphim_server
build-debug-native:
FROM +source-native
WORKDIR /code
# Optimize build with parallel jobs and optimized settings
RUN CARGO_BUILD_JOBS=$(nproc) CARGO_NET_RETRY=10 CARGO_NET_TIMEOUT=60 cargo build
SAVE ARTIFACT /code/target/debug/terraphim_server AS LOCAL artifact/bin/terraphim_server_debug
# Save entire target directory for reuse by fmt, lint, test
SAVE ARTIFACT /code/target /target
workspace-debug:
FROM +source-native
WORKDIR /code
# Copy the pre-built target directory from build-debug-native
COPY +build-debug-native/target /code/target
# The workspace now has all compiled artifacts ready
source:
FROM +install
WORKDIR /code
CACHE --sharing shared --persist /code/vendor
COPY --keep-ts Cargo.toml Cargo.lock ./
COPY --keep-ts --dir terraphim_server terraphim_firecracker terraphim_ai_nodejs default crates ./
RUN mkdir -p .cargo
RUN cargo vendor > .cargo/config.toml
DO rust+CARGO --args=fetch
cross-build:
FROM +source
ARG --required TARGET
DO rust+SET_CACHE_MOUNTS_ENV
# Use cargo directly for musl targets, cross for others
IF [ "$TARGET" = "x86_64-unknown-linux-musl" ]
RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE \
CC_x86_64_unknown_linux_musl=musl-gcc \
cargo build --target $TARGET --release \
--package terraphim_server \
--package terraphim_mcp_server \
--package terraphim_agent
ELSE
# For non-musl targets, we would use cross here but it requires Docker daemon
# For now, skip complex targets that need cross
RUN echo "Cross-compilation for $TARGET requires Docker daemon access"
RUN exit 1
END
DO rust+COPY_OUTPUT --output=".*" # Copies all files to ./target
# Test the binaries (note: TUI binary uses hyphen, not underscore)
RUN ./target/$TARGET/release/terraphim_server --version
RUN ./target/$TARGET/release/terraphim_mcp_server --version
RUN ./target/$TARGET/release/terraphim-agent --version
# Save all three binaries
SAVE ARTIFACT ./target/$TARGET/release/terraphim_server AS LOCAL artifact/bin/terraphim_server-$TARGET
SAVE ARTIFACT ./target/$TARGET/release/terraphim_mcp_server AS LOCAL artifact/bin/terraphim_mcp_server-$TARGET
SAVE ARTIFACT ./target/$TARGET/release/terraphim-agent AS LOCAL artifact/bin/terraphim_agent-$TARGET
build:
FROM +source
DO rust+SET_CACHE_MOUNTS_ENV
# Build each package separately to ensure all binaries are created
DO rust+CARGO --args="build --offline --release --package terraphim_server" --output="release/[^/\.]+"
DO rust+CARGO --args="build --offline --release --package terraphim_mcp_server" --output="release/[^/\.]+"
DO rust+CARGO --args="build --offline --release --package terraphim_agent" --output="release/[^/\.]+"
# Debug: Check what binaries were actually created
RUN find /code/target/release -name "*terraphim*" -type f -exec ls -la {} \;
# Test all binaries (note: TUI binary uses hyphen, not underscore)
RUN /code/target/release/terraphim_server --version
RUN /code/target/release/terraphim_mcp_server --version
RUN /code/target/release/terraphim-agent --version
# Save all three binaries
SAVE ARTIFACT /code/target/release/terraphim_server AS LOCAL artifact/bin/terraphim_server-
SAVE ARTIFACT /code/target/release/terraphim_mcp_server AS LOCAL artifact/bin/terraphim_mcp_server-
SAVE ARTIFACT /code/target/release/terraphim-agent AS LOCAL artifact/bin/terraphim_agent-
build-debug:
FROM +source
DO rust+SET_CACHE_MOUNTS_ENV
DO rust+CARGO --args="build" --output="debug/[^/\.]+"
RUN ./target/debug/terraphim_server --version
SAVE ARTIFACT ./target/debug/terraphim_server AS LOCAL artifact/bin/terraphim_server_debug
test:
FROM +workspace-debug
# DO rust+SET_CACHE_MOUNTS_ENV
# COPY --chmod=0755 +build-debug/terraphim_server /code/terraphim_server_debug
GIT CLONE https://github.com/terraphim/INCOSE-Systems-Engineering-Handbook.git /tmp/system_operator/
# RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE nohup /code/terraphim_server_debug & sleep 5 && cargo test;
# rocksdb feature disabled in CI
RUN cargo test --workspace
#DO rust+CARGO --args="test --offline"
fmt:
FROM +workspace-debug
RUN cargo fmt --check
lint:
FROM +workspace-debug
RUN cargo clippy --workspace --all-targets
build-focal:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
RUN apt-get update -qq
RUN DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true TZ=Etc/UTC apt-get install -yqq --no-install-recommends build-essential bison flex ca-certificates openssl libssl-dev bc wget git curl cmake pkg-config
WORKDIR /code
COPY --keep-ts Cargo.toml Cargo.lock ./
COPY --keep-ts --dir terraphim_server terraphim_firecracker terraphim_ai_nodejs default crates ./
RUN curl https://pkgx.sh | sh
RUN pkgx +openssl cargo build --release
SAVE ARTIFACT /code/target/release/terraphim_server AS LOCAL artifact/bin/terraphim_server_focal
build-jammy:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
RUN apt-get update -qq
RUN DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true TZ=Etc/UTC apt-get install -yqq --no-install-recommends build-essential bison flex ca-certificates openssl libssl-dev bc wget git curl cmake pkg-config
RUN update-ca-certificates
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.88.0
# RUN rustup toolchain install stable
WORKDIR /code
COPY --keep-ts Cargo.toml Cargo.lock ./
COPY --keep-ts --dir terraphim_server terraphim_firecracker terraphim_ai_nodejs default crates ./
IF [ "$CARGO_HOME" = "" ]
ENV CARGO_HOME="$HOME/.cargo"
END
IF ! echo $PATH | grep -E -q "(^|:)$CARGO_HOME/bin($|:)"
ENV PATH="$PATH:$CARGO_HOME/bin"
END
RUN cargo build --release
SAVE ARTIFACT /code/target/release/terraphim_server AS LOCAL artifact/bin/terraphim_server_jammy
docker-native:
FROM ubuntu:20.04
# Install minimal runtime dependencies
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
ARG tags="ghcr.io/applied-knowledge-systems/terraphim-server:latest"
# Copy all three binaries from main build
COPY --chmod=0755 (+build/terraphim_server) /usr/local/bin/terraphim_server
COPY --chmod=0755 (+build/terraphim_mcp_server) /usr/local/bin/terraphim_mcp_server
COPY --chmod=0755 (+build/terraphim-tui) /usr/local/bin/terraphim-tui
# Test binaries
RUN /usr/local/bin/terraphim_server --version
RUN /usr/local/bin/terraphim_mcp_server --version
RUN /usr/local/bin/terraphim-tui --version
# Default to main server
ENV TERRAPHIM_SERVER_HOSTNAME="127.0.0.1:8000"
ENV TERRAPHIM_SERVER_API_ENDPOINT="http://localhost:8000/api"
EXPOSE 8000
ENTRYPOINT ["/usr/local/bin/terraphim_server"]
SAVE IMAGE --push ${tags}
docker-musl:
FROM alpine:3.18
# You can pass multiple tags, space separated
# TODO: Re-enable once OpenDAL->reqsign OpenSSL issue is resolved
# ARG tags="ghcr.io/applied-knowledge-systems/terraphim-server:latest"
# ARG --required TARGET
# COPY --chmod=0755 --platform=linux/amd64 (+cross-build/terraphim_server --TARGET=${TARGET}) /terraphim_server
# RUN /terraphim_server --version
# ENV TERRAPHIM_SERVER_HOSTNAME="127.0.0.1:8000"
# ENV TERRAPHIM_SERVER_API_ENDPOINT="http://localhost:8000/api"
# EXPOSE 8000
# ENTRYPOINT ["/terraphim_server"]
# SAVE IMAGE --push ${tags}
RUN echo "MUSL cross-compilation temporarily disabled due to OpenDAL->reqsign OpenSSL dependency"
docker-aarch64:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN=true
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -yqq --no-install-recommends build-essential bison flex ca-certificates openssl libssl-dev bc wget git curl cmake pkg-config libssl-dev g++-aarch64-linux-gnu libc6-dev-arm64-cross
# Install Rust from official installer
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.88.0
ENV PATH="/root/.cargo/bin:$PATH"
ENV CARGO_HOME="/root/.cargo"
RUN rustup target add aarch64-unknown-linux-gnu
RUN rustup toolchain install stable-aarch64-unknown-linux-gnu
WORKDIR /code
COPY --keep-ts Cargo.toml Cargo.lock ./
COPY --keep-ts --dir terraphim_server terraphim_firecracker terraphim_ai_nodejs default crates ./
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
ENV PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig
RUN cargo build --release --target aarch64-unknown-linux-gnu
SAVE ARTIFACT /code/target/aarch64-unknown-linux-gnu/release/terraphim_server AS LOCAL artifact/bin/terraphim_server_linux-aarch64
# CMD ["cargo", "build","--release","--target", "aarch64-unknown-linux-gnu"]
docker-slim:
FROM debian:buster-slim
COPY +build/terraphim_server terraphim_server
EXPOSE 8000
ENTRYPOINT ["./terraphim_server"]
SAVE IMAGE aks/terraphim_server:buster
docker-scratch:
FROM scratch
COPY +build/terraphim_server terraphim_server
EXPOSE 8000
ENTRYPOINT ["./terraphim_server"]
SAVE IMAGE aks/terraphim_server:scratch
docs-deps:
FROM +install-native
RUN cargo install mdbook
RUN cargo install mdbook-linkcheck
RUN cargo install mdbook-sitemap-generator
# RUN cargo install --git https://github.com/typst/typst typst-cli
# RUN cargo install --git https://github.com/terraphim/mdbook-typst.git
RUN cargo install mdbook-mermaid
RUN cargo install mdbook-alerts
RUN apt update && apt install libvips-dev -y
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
RUN bash -c "source $HOME/.nvm/nvm.sh && nvm install 20 && npm install -g netlify-cli"
docs-pages:
FROM +docs-deps
COPY --keep-ts docs /docs
WORKDIR /docs
RUN mdbook --version
RUN mdbook build
RUN mdbook-sitemap-generator -d docs.terraphim.ai -o /docs/book/html/sitemap.xml
RUN --secret NETLIFY_AUTH_TOKEN=NETLIFY_TOKEN bash -c "source $HOME/.nvm/nvm.sh && netlify deploy --dir /docs/book/html --prod --auth $NETLIFY_AUTH_TOKEN --site docs-terraphim-ai"