Skip to content

Commit

Permalink
Solana tests can now be run on an Apple M[1,2,3,4] computer once the …
Browse files Browse the repository at this point in the history
…steps outlined in src/integration-tests/resources/README.md are followed
  • Loading branch information
ml-james committed Oct 13, 2024
1 parent 3d5d8c7 commit 1833abd
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ All the `Solana Programs` that have been implemented have been conformance teste
is that these tests act as living documentation of how the library can be used. Any future implemented programs should also
have accompanying integration tests so that we can carry on extending this living documentation!

A note about the integration tests. If you're running on a shiny `Apple M[1,2,3,4]` machine, then
there are extra steps you need to take in order to run them locally. Please find the `README.md` in `src/integration-test/resources/README.md`!

We hope that you enjoy using the library, and we welcome any feedback. We especially welcome PRs!

### Features
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ task integrationTest(type: Test) {
showCauses true
showStackTraces true
}
maxHeapSize = "1g"
}

tasks.processTestResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class IntegrationTestBase
{
try
{
SOLANA_VALIDATOR = new GenericContainer<>(new ImageFromDockerfile().withDockerfile(Path.of(MountableFile.forClasspathResource("Dockerfile").getFilesystemPath())))
SOLANA_VALIDATOR = new GenericContainer<>(new ImageFromDockerfile().withDockerfile(Path.of(MountableFile.forClasspathResource("Aarch64Dockerfile").getFilesystemPath())))
.withCopyFileToContainer(MountableFile.forClasspathResource("solana-run.sh"), "/solana-run.sh")
.withCopyFileToContainer(MountableFile.forClasspathResource("fetch-spl.sh"), "/fetch-spl.sh")
.withCopyFileToContainer(MountableFile.forClasspathResource("lmax_multisig.so"), "/lmax_multisig.so")
Expand Down
21 changes: 21 additions & 0 deletions src/integration-test/resources/Aarch64Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM --platform=linux/aarch64 ubuntu:20.04

ENV SOLANA_VERSION=1.18.25

USER root

RUN apt-get update && apt-get install -y wget curl

COPY solana-release-aarch64-unknown-linux-gnu-$SOLANA_VERSION.tar.bz2 /solana-release-aarch64-unknown-linux-gnu-$SOLANA_VERSION.tar.bz2

ENV SOLANA_TAR=/solana-release-aarch64-unknown-linux-gnu-$SOLANA_VERSION.tar.bz2

RUN tar -xvjf $SOLANA_TAR && rm -f $SOLANA_TAR && mv /home/solana/.local/share/solana/install/releases/$SOLANA_VERSION/bin/* /usr/local/bin/

COPY solana-run.sh /usr/bin/solana-run.sh
RUN chmod +x /usr/bin/solana-run.sh

COPY fetch-spl.sh /usr/bin/fetch-spl.sh
RUN chmod +x /usr/bin/fetch-spl.sh

ENTRYPOINT ["/usr/bin/solana-run.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM --platform=linux/aarch64 ubuntu:20.04

ARG SOLANA_VERSION
ENV DEBIAN_FRONTEND=noninteractive

RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime \
&& apt update \
&& apt install -y tzdata \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& apt install -y \
libssl-dev \
libudev-dev \
pkg-config \
zlib1g-dev \
llvm \
clang \
cmake \
make \
libprotobuf-dev \
protobuf-compiler \
curl \
wget \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ENV DEBIAN_FRONTEND=dialog

RUN useradd -m -s /bin/bash solana

USER solana

WORKDIR /home/solana

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

ENV PATH="/home/solana/.cargo/bin:${PATH}"

RUN git clone https://github.com/solana-labs/solana.git --depth 1 --branch v$SOLANA_VERSION /home/solana/solana-src-v$SOLANA_VERSION

RUN /bin/bash -c "/home/solana/solana-src-v$SOLANA_VERSION/scripts/cargo-install-all.sh /home/solana/.local/share/solana/install/releases/$SOLANA_VERSION"

RUN tar -cvjf solana-release-aarch64-unknown-linux-gnu-$SOLANA_VERSION.tar.bz2 /home/solana/.local/share/solana/install/

CMD ["sleep", "infinity"]
4 changes: 2 additions & 2 deletions src/integration-test/resources/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ USER root

RUN apt-get update && apt-get install -y wget curl

ENV SOLANA_VERSION v1.18.25
ENV SOLANA_VERSION 1.18.25
ENV SOLANA_TAR solana-release-x86_64-unknown-linux-gnu.tar.bz2
ENV SOLANA_URL https://github.com/solana-labs/solana/releases/download/$SOLANA_VERSION/$SOLANA_TAR
ENV SOLANA_URL https://github.com/solana-labs/solana/releases/download/v$SOLANA_VERSION/$SOLANA_TAR

RUN wget $SOLANA_URL && tar -xvjf $SOLANA_TAR && rm -f $SOLANA_TAR && mv solana-release/bin/* /usr/local/bin/

Expand Down
22 changes: 22 additions & 0 deletions src/integration-test/resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#### Why does this README.md exist?

Well, Solana Labs release multiple different versions of the Solana validator, but they _don't_ release
`solana-release-aarch64-unknown-linux-gnu.tar.bz2`, which is rather irritating. In order
to run a `solana-test-validator` on an `amd64` based architecture,
in particular on an `Apple M[1,2,3,4]` chip, _within_ a `Docker` container, you need it.

The `Github` runner at `https://github.com/LMAX-Exchange/solana4j` runs on an `x86_64` architecture, so that will remain the default in this project. However,
in the interest that all computer architectures should be treated equally, I have provided a way that you can build your own
image, on a `Apple M[1,2,3,4]` based laptop, and run the integration tests.

I will not check the artifact into source, but allow the user to generate it themselves and reference the `Aarch64Dockerfile` in `IntegrationTestBase.java`;
be careful to not actually commit these changes, as the pipeline in `Github` will fail.

```java
SOLANA_VALIDATOR = new GenericContainer<>(new ImageFromDockerfile().withDockerfile(Path.of(MountableFile.forClasspathResource("Aarch64Dockerfile").getFilesystemPath())))
```

In order to build `solana-release-x86_64-unknown-linux-gnu.tar-1.18.25.bz2`, you should run the script `build_aarch64_solana_image.sh`. It will put the artifact exactly where you need
it, if you run the script from `src/integration-test/resources`, as you should. You will need to beef up a lot of resources on
`Docker Desktop`, particularly the `Virtual disk limit`. Running that script and making the above code change, should
be enough to run the integration tests locally on an `Apple M[1,2,3,4]` computer.
14 changes: 14 additions & 0 deletions src/integration-test/resources/build_aarch64_solana_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -xeou pipefail

trap "docker rm --force solana-aarch64-build-container" EXIT

solana_version=${1:-1.18.25}

docker build -t solana-aarch64-build-image -f BuildMeAnAarch64CompliantSolanaDockerImagePleaseDockerfile --build-arg SOLANA_VERSION=$solana_version .

docker run -d --name solana-aarch64-build-container solana-aarch64-build-image

docker cp solana-aarch64-build-container:/home/solana/solana-release-aarch64-unknown-linux-gnu-$solana_version.tar.bz2 .

docker rm --force solana-aarch64-build-container

0 comments on commit 1833abd

Please sign in to comment.