-
Notifications
You must be signed in to change notification settings - Fork 10
/
Earthfile
174 lines (143 loc) · 5.36 KB
/
Earthfile
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
VERSION 0.8
ARG --global PROFILE=release
ARG --global FEATURES
ci:
BUILD +build
BUILD +test
BUILD +licenses
BUILD +fmt
BUILD +chainspecs
ARG image=sidechains-substrate-node
ARG tags
BUILD +docker --image=$image --tags=$tags
setup:
FROM paritytech/ci-unified:bullseye-1.81.0-2024-09-11-v202409111034
WORKDIR /build
# copy pre-existing $CARGO_HOME artifacts into the cache
RUN cp -rl $CARGO_HOME /tmp/cargo
CACHE --sharing shared --id cargo $CARGO_HOME
RUN cp -rua /tmp/cargo/. $CARGO_HOME && rm -rf /tmp/cargo
COPY Cargo.* .rustfmt.toml rust-toolchain.toml .
RUN rustup show
RUN cargo install --locked cargo-chef && cp "$CARGO_HOME/bin/cargo-chef" /usr/local/bin
source:
FROM +setup
ARG CRATES=$(tomlq -r .workspace.members[] Cargo.toml)
FOR crate IN $CRATES
COPY --dir $crate $crate
END
COPY --dir +build-deps/target .
build-deps:
FROM +fetch-deps
CACHE --sharing shared --id cargo $CARGO_HOME
RUN cargo --locked chef prepare
RUN cargo --locked chef cook --profile=$PROFILE --features=$FEATURES
SAVE ARTIFACT target
build:
FROM +source
LET WASM_BUILD_STD=0
CACHE --sharing shared --id cargo $CARGO_HOME
ARG EARTHLY_GIT_HASH
RUN cargo build --locked --profile=$PROFILE --features=$FEATURES
SAVE ARTIFACT target/*/partner-chains-node AS LOCAL partner-chains-node
SAVE ARTIFACT target/*/partner-chains-node AS LOCAL partner-chains-node-artifact
SAVE ARTIFACT target/*/partner-chains-cli AS LOCAL partner-chains-cli-artifact
test:
FROM +build
LET WASM_BUILD_STD=0
DO github.com/earthly/lib:3.0.2+INSTALL_DIND
CACHE --sharing shared --id cargo $CARGO_HOME
RUN cargo test --no-run --locked --profile=$PROFILE --features=$FEATURES,runtime-benchmarks
WITH DOCKER
RUN cargo test --locked --profile=$PROFILE --features=$FEATURES,runtime-benchmarks
END
licenses:
FROM +source
COPY scripts/validate_workspace_licenses.py validate_workspace_licenses.py
RUN pip install toml
RUN cargo install --locked cargo-license
RUN python3 validate_workspace_licenses.py
fmt:
FROM +source
CACHE --sharing shared --id cargo $CARGO_HOME
RUN find node/runtime/src/weights -type f -name '*.rs' -exec cargo fmt -- {} +
RUN cargo fmt --check
docker:
FROM debian:bullseye-slim
ARG image=sidechains-substrate-node
ARG tags
DO +INSTALL
RUN useradd -m -u 1000 -U -s /bin/sh -d /substrate substrate \
&& mkdir -p /data /substrate/.local/share/partner-chains-node \
&& chown -R substrate:substrate /data /substrate \
# remove package managers
&& rm -rf /usr/bin/apt* /usr/bin/dpkg* \
&& ln -s /data /substrate/.local/share/partner-chains-node
USER substrate
#p2p
EXPOSE 30333
#prometheus exporter
EXPOSE 9615
#JSON-RPC HTTP
EXPOSE 9933
#JSON-RPC WS
EXPOSE 9944
VOLUME ["/data"]
ENTRYPOINT ["./usr/local/bin/partner-chains-node"]
ARG EARTHLY_GIT_HASH
ENV EARTHLY_GIT_HASH=$EARTHLY_GIT_HASH
FOR tag IN $EARTHLY_GIT_HASH $tags
SAVE IMAGE --push $image:$tag
END
deps:
FROM +source
COPY +build/partner-chains-node .
# calculate libary deps
RUN ldd partner-chains-node \
| awk 'NF == 4 { system("echo " $3) }' \
| tar -czf deps.tgz --files-from=-
SAVE ARTIFACT deps.tgz deps
mock:
FROM +setup
ARG CRATES=$(tomlq -r '.workspace.members[]' Cargo.toml)
ARG SRCS=$(tomlq -r '.workspace.members[] + "/src"' Cargo.toml)
ARG LIBS=$(tomlq -r '.workspace.dependencies[]|select(type == "object" and has("path")).path + "/src/lib.rs"' Cargo.toml)
FOR crate IN $CRATES
COPY --if-exists $crate/Cargo.toml $crate/Cargo.toml
END
RUN mkdir -p $SRCS \
&& touch $LIBS \
&& for crate in $SRCS; do if [ ! -f $crate/lib.rs ]; then touch $crate/main.rs; fi; done \
&& touch node/node/src/lib.rs
fetch-deps:
FROM +mock
CACHE --sharing shared --id cargo $CARGO_HOME
RUN --ssh cargo fetch --locked
INSTALL:
FUNCTION
COPY +build/partner-chains-node /usr/local/bin
COPY +deps/deps /tmp/deps.tgz
# install deps
RUN tar -v -C / -xzf /tmp/deps.tgz \
&& rm -rf /tmp/deps.tgz
# Sanity checks
RUN ldd /usr/local/bin/partner-chains-node \
&& /usr/local/bin/partner-chains-node --version
chainspecs:
FROM +setup
DO +INSTALL
COPY dev/envs/devnet/.envrc dev/envs/devnet/.envrc
COPY dev/envs/devnet/addresses.json dev/envs/devnet/addresses.json
COPY dev/envs/staging-preview/.envrc dev/envs/staging-preview/.envrc
COPY dev/envs/staging-preview/addresses.json dev/envs/staging-preview/addresses.json
COPY dev/envs/staging-preprod/.envrc dev/envs/staging-preprod/.envrc
COPY dev/envs/staging-preprod/addresses.json dev/envs/staging-preprod/addresses.json
RUN . ./dev/envs/devnet/.envrc \
&& partner-chains-node build-spec --chain local --disable-default-bootnode > devnet_chain_spec.json
RUN . ./dev/envs/staging-preview/.envrc \
&& partner-chains-node build-spec --chain staging --disable-default-bootnode > staging_preview_chain_spec.json
RUN . ./dev/envs/staging-preprod/.envrc \
&& partner-chains-node build-spec --chain staging --disable-default-bootnode > staging_preprod_chain_spec.json
SAVE ARTIFACT devnet_chain_spec.json AS LOCAL devnet_chain_spec.json
SAVE ARTIFACT staging_preview_chain_spec.json AS LOCAL staging_preview_chain_spec.json
SAVE ARTIFACT staging_preprod_chain_spec.json AS LOCAL staging_preprod_chain_spec.json