Skip to content

Commit

Permalink
Build the basic release docker image (#232)
Browse files Browse the repository at this point in the history
* Builds the basic release docker image.

* Replaces the wrong target `aarch64-unknown-linux-gnu` with `x86_64-unknown-linux-gnu`.

* Tests for the CI lint.

* Updates for RUSTFLAGS.
  • Loading branch information
silathdiir authored Jul 20, 2021
1 parent c232063 commit 2521a30
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ prost = "0.7.0"
prost-types = "0.7.0"
qstring = "0.7.2"
rand = "0.8.3"
rdkafka = { version = "0.25.0", features = [ "cmake-build" ] }
rdkafka = { version = "0.26.0", features = [ "cmake-build" ] }
rust_decimal = { version = "1.10.3", features = [ "postgres", "bytes", "byteorder" ] }
rust_decimal_macros = "1.10.3"
serde = { version = "1.0.124", features = [ "derive" ] }
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ $ cd $DingirExchangeDir/examples/js ; npm i
$ npx ts-node trade.ts
```

## Release

We uses [cross](https://github.com/rust-embedded/cross) to generate release builds for Linux Distributions.
For example, you could generate a static release build via the below command.

```
RUSTFLAGS="-C link-arg=-static -C target-feature=+crt-static" cross build --bin matchengine --target x86_64-unknown-linux-gnu --release
```

And a new Docker image could be generated by the `release` script.

```
# In root directory of this project
./release/release.sh YOUR_DOCKER_REGISTRY_DOMAIN.COM:YOUR_DOMAIN_PORT NEW_IMAGE_TAG
```

## Related Projects

[Peatio](https://github.com/openware/peatio): A full-featured crypto exchange backend, with user account system and crypto deposit/withdraw. Written in Ruby/Rails. It can process less than 200 orders per second.
Expand Down
6 changes: 6 additions & 0 deletions release/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ubuntu:20.04

COPY config /config
COPY target/x86_64-unknown-linux-gnu/release/matchengine /usr/bin/

CMD 'matchengine'
40 changes: 40 additions & 0 deletions release/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
set -u

if [ $# -ne 2 ]
then
echo "Usage: $0 docker-registry image-tag"
exit 1
fi

DOCKER_IMAGE_NAME='dingir-exchange-matchengine'
DOCKER_TARGET="$1/$DOCKER_IMAGE_NAME:$2"

function run() {
install_cross
build_release
docker_build
help_info
}

function install_cross() {
echo 'install cross - https://github.com/rust-embedded/cross'
cargo install cross
}

function build_release() {
echo 'build a release for target x86_64-unknown-linux-gnu'
RUSTFLAGS="-C link-arg=-static -C target-feature=+crt-static" cross build --bin matchengine --target x86_64-unknown-linux-gnu --release
}

function docker_build() {
echo "docker build a image $DOCKER_TARGET"
docker build -t $DOCKER_TARGET -f release/Dockerfile .
}

function help_info() {
echo "Push to Docker Registry: docker push $DOCKER_TARGET"
echo "Run a new Docker Container: docker run $DOCKER_TARGET"
}

run

0 comments on commit 2521a30

Please sign in to comment.