Skip to content

Commit

Permalink
add new guideline: compile from container
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Nov 7, 2023
1 parent 0a0bb53 commit 973aecd
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 57 deletions.
107 changes: 52 additions & 55 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
# Happening in a well-defined setting the Docker builds should be somewhat
# more reproducible than builds relying on the local workstation environment.
# Hence we're going to use the Docker build as the reference one.
# CI and local builds might be considered a second tier build optimizations.
#
# docker build --tag mm2 .

# NB: The version here was picked to match the one tested in our CI. The latest Travis has (as of 2018-11) is Xenial.
FROM docker.io/ubuntu:xenial

RUN \
apt-get update &&\
apt-get install -y git build-essential libssl-dev wget &&\
apt-get install -y cmake &&\
# https://github.com/rust-lang/rust-bindgen/blob/master/book/src/requirements.md#debian-based-linuxes
apt-get install -y llvm-3.9-dev libclang-3.9-dev clang-3.9 lld &&\
# openssl-sys requirements, cf. https://crates.io/crates/openssl-sys
apt-get install -y pkg-config libssl-dev &&\
apt-get clean

RUN \
wget -O- https://sh.rustup.rs > /tmp/rustup-init.sh &&\
sh /tmp/rustup-init.sh -y --default-toolchain none &&\
. /root/.cargo/env &&\
rm -f /tmp/rustup-init.sh

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

# First 7 characters of the commit ID.
ENV MM_VERSION="f236ad1"

RUN cd /tmp &&\
wget https://api.github.com/repos/KomodoPlatform/atomicDEX-API/tarball/$MM_VERSION &&\
tar -xzf $MM_VERSION &&\
ls &&\
mv KomodoPlatform-atomicDEX-API-$MM_VERSION /mm2 &&\
rm $MM_VERSION &&\
echo $MM_VERSION > /mm2/MM_VERSION

RUN cd /mm2 && cargo fetch

# This will overwrite the Git version with the local one.
# Only needed when we're developing or changing something locally.
#COPY . /mm2

# Build MM1 and MM2.
# Increased verbosity here allows us to see the MM1 CMake logs.
RUN cd /mm2 &&\
cargo build -vv &&\
mv target/debug/mm2 /usr/local/bin/marketmaker-mainnet &&\
# We currently need BOB_PASSPHRASE, BOB_USERPASS, ALICE_PASSPHRASE and ALICE_USERPASS for the tests…
#cargo test &&\
cargo clean

CMD marketmaker-testnet
FROM docker.io/debian:buster-slim

MAINTAINER Onur Özkan <[email protected]>

RUN apt-get update -y

RUN apt-get install -y \
build-essential \
cmake \
ca-certificates \
curl \
wget \
gnupg

RUN ln -s /usr/bin/python3 /bin/python

RUN apt install -y \
software-properties-common \
lsb-release

RUN curl --output llvm.sh https://apt.llvm.org/llvm.sh

RUN chmod +x llvm.sh

RUN ./llvm.sh 16

RUN rm ./llvm.sh

RUN ln -s /usr/bin/clang-16 /usr/bin/clang

ENV AR=/usr/bin/llvm-ar-16
ENV CC=/usr/bin/clang-16

RUN mkdir -m 0755 -p /etc/apt/keyrings

RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg

RUN echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

RUN apt-get update -y

RUN apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

ENV PATH="/root/.cargo/bin:$PATH"
6 changes: 4 additions & 2 deletions .docker/Dockerfile.ci-container
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN apt install -y \
lsb-release \
gnupg

RUN wget https://apt.llvm.org/llvm.sh
RUN curl --output llvm.sh https://apt.llvm.org/llvm.sh

RUN chmod +x llvm.sh

Expand Down Expand Up @@ -52,4 +52,6 @@ RUN apt-get install -y \
containerd.io \
docker-buildx-plugin

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

ENV PATH="/root/.cargo/bin:$PATH"
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ For a curated list of Komodo DeFi Framework based projects and resources, check

## Building from source

### On Host System:

[Pre-built release binaries](https://developers.komodoplatform.com/basic-docs/atomicdex/atomicdex-setup/get-started-atomicdex.html) are available for OSX, Linux or Windows.

If you want to build from source, the following prerequisites are required:
Expand All @@ -87,6 +89,24 @@ To build, run `cargo build` (or `cargo build -vv` to get verbose build output).

For more detailed instructions, please refer to the [Installation Guide](https://developers.komodoplatform.com/basic-docs/atomicdex/atomicdex-setup/get-started-atomicdex.html).

### From Container:

If you want to build from source without installing prerequisites to your host system, you can do so by binding the source code inside a container and compiling it there.

Build the image:

```sh
docker build -t mm2-build-container -f .docker/Dockerfile .
```

Bind source code into container and compile it:

```sh
docker run -v "$(pwd)":/app -w /app mm2-build-container cargo build
```

Just like building it on your host system, you will now have the target directory containing the build files.

## Building WASM binary

Please refer to the [WASM Build Guide](./docs/WASM_BUILD.md).
Expand Down

0 comments on commit 973aecd

Please sign in to comment.