From 2521a30f8733e7ed53e8502bf6f7def73dc0a2ef Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 20 Jul 2021 13:53:09 +0800 Subject: [PATCH] Build the basic release docker image (#232) * 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. --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- README.md | 16 ++++++++++++++++ release/Dockerfile | 6 ++++++ release/release.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 release/Dockerfile create mode 100755 release/release.sh diff --git a/Cargo.lock b/Cargo.lock index 8254dc22..522a842e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1984,9 +1984,9 @@ dependencies = [ [[package]] name = "rdkafka" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8acd8f5c5482fdf89e8878227bafa442d8c4409f6287391c85549ca83626c27" +checksum = "af78bc431a82ef178c4ad6db537eb9cc25715a8591d27acc30455ee7227a76f4" dependencies = [ "futures", "libc", @@ -2001,9 +2001,9 @@ dependencies = [ [[package]] name = "rdkafka-sys" -version = "3.0.0+1.6.0" +version = "4.0.0+1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca35e95c88e08cdc643b25744e38ccee7c93c7e90d1ac6850fe74cbaa40803c3" +checksum = "54f24572851adfeb525fdc4a1d51185898e54fed4e8d8dba4fadb90c6b4f0422" dependencies = [ "cmake", "libc", diff --git a/Cargo.toml b/Cargo.toml index 7737ab70..a5b01ee5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" ] } diff --git a/README.md b/README.md index 884c61c0..cca736f2 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/release/Dockerfile b/release/Dockerfile new file mode 100644 index 00000000..afd03a60 --- /dev/null +++ b/release/Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:20.04 + +COPY config /config +COPY target/x86_64-unknown-linux-gnu/release/matchengine /usr/bin/ + +CMD 'matchengine' diff --git a/release/release.sh b/release/release.sh new file mode 100755 index 00000000..a56acb0d --- /dev/null +++ b/release/release.sh @@ -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