Skip to content

Commit

Permalink
solana: deterministic builds via Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
kcsongor committed Apr 30, 2024
1 parent 39d67c0 commit ac8b948
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ docker_build(
context = "./",
only = ["./sdk", "./solana"],
ignore=["./sdk/__tests__", "./sdk/Dockerfile", "./sdk/ci.yaml", "./sdk/**/dist", "./sdk/node_modules", "./sdk/**/node_modules"],
target = "dev-builder",
dockerfile = "./solana/Dockerfile",
)
k8s_yaml_with_ns("./solana/solana-devnet.yaml")
Expand All @@ -53,7 +54,7 @@ docker_build(
context = "./sdk",
dockerfile = "./sdk/Dockerfile",
)
k8s_yaml_with_ns("./sdk/ci.yaml")
k8s_yaml_with_ns("./sdk/ci.yaml")
k8s_resource(
"ntt-ci-tests",
labels = ["ntt"],
Expand Down
1 change: 1 addition & 0 deletions solana/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**/*.rs.bk
node_modules
test-ledger
artifacts-*
20 changes: 16 additions & 4 deletions solana/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ COPY solana/Cargo.toml Cargo.toml
COPY solana/modules modules
COPY solana/programs programs
COPY solana/rust-toolchain rust-toolchain
COPY solana/scripts scripts

ENV RUST_BACKTRACE=1

FROM anchor AS builder
FROM anchor AS dev-builder

RUN mkdir -p /opt/solana/deps

Expand All @@ -37,8 +38,19 @@ COPY --from=solana-contract /opt/solana/deps/cpi_poster.so /opt/solana/deps/cpi_
COPY --from=solana-contract /opt/solana/deps/mpl_token_metadata.so /opt/solana/deps/mpl_token_metadata.so
COPY --from=solana-contract /opt/solana/deps/wormhole_migration.so /opt/solana/deps/wormhole_migration.so

COPY sdk ../sdk
COPY solana/Makefile Makefile
COPY solana/scripts scripts

RUN make target/idl/example_native_token_transfers.json
COPY solana/ts ts

FROM anchor as mainnet-builder

ARG SOLANA_NETWORK
RUN [ -z "$SOLANA_NETWORK" ] && echo "SOLANA_NETWORK is required" && exit 1 || echo "SOLANA_NETWORK=$SOLANA_NETWORK"

RUN --mount=type=cache,target=/opt/solana/deps/target,id=build_anchor_ntt_target \
--mount=type=cache,target=/usr/local/cargo/registry,id=cargo_registry \
--mount=type=cache,target=.anchor,id=anchor_cache \
anchor build --arch sbf -- --no-default-features --features $SOLANA_NETWORK

FROM scratch as export
COPY --from=mainnet-builder /usr/src/solana/target/deploy /
22 changes: 22 additions & 0 deletions solana/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ idl: target/idl/example_native_token_transfers.json
node_modules: package-lock.json
npm ci

.PHONY: artifacts-mainnet
artifacts-mainnet: NETWORK=mainnet
artifacts-mainnet: _artifacts
mv _artifacts $@

.PHONY: artifacts-solana-devnet
artifacts-solana-devnet: NETWORK=solana-devnet
artifacts-solana-devnet: _artifacts
mv _artifacts $@

.PHONY: artifacts-tilt-devnet
artifacts-tilt-devnet: NETWORK=tilt-devnet
artifacts-tilt-devnet: _artifacts
mv _artifacts $@

.PHONY: _artifacts
_artifacts:
rm -rf $@
DOCKER_BUILDKIT=1 cd .. && docker build -f solana/Dockerfile --build-arg="SOLANA_NETWORK=$(NETWORK)" -t export -o solana/$@ .
@cd $@ && ls | xargs sha256sum > checksums.txt
@cat $@/checksums.txt

.PHONY: clean
clean:
anchor clean
Expand Down
25 changes: 21 additions & 4 deletions solana/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
# Solana
# Solana

## Prequisities

Ensure that you are using the correct version of the Solana and Anchor CLI tools by consulting `Anchor.toml`.
```toml
[toolchain]
anchor_version = "0.29.0" # CLI
solana_version = "1.17.2"
solana_version = "1.18.10"
```

You will also need to install the toolchain listed in `rust-toolchain`.
You will also need `rustup`.

For building the mainnet binaries, the only requirements are `docker` and `make`:

```sh
make artifacts-mainnet
```

which will produce the object files into the `artifacts-mainnet` directory.
This is the recommended way of building the binaries as it results in deterministic builds.
For Solana devnet builds, or local testing builds, use the

``` sh
make artifacts-solana-devnet
make artifacts-tilt-devnet
```

commands.

## Design Overview

Expand Down Expand Up @@ -104,4 +121,4 @@ To ensure the SDK has the generated IDL, run the tests with the make command:

```sh
make anchor-test
```
```

0 comments on commit ac8b948

Please sign in to comment.