Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: build rs-tenderdash-abci in Docker #14

Merged
merged 37 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dc15e1c
build: sample Dockerfile image
lklimek Mar 23, 2023
8872d1f
chore: fix dockerfile
lklimek Mar 23, 2023
13841b8
chore: try to fix caching
lklimek Mar 23, 2023
ca73254
chore: dockerfile improvements
lklimek Mar 23, 2023
4babf94
build: disable arm64 build
lklimek Mar 23, 2023
42c98b9
build: simplify Dockerfile
lklimek Mar 24, 2023
f85ec7a
build(docker): silence apt-get
lklimek Mar 24, 2023
3101dfc
build(github): docer image only for arm
lklimek Mar 24, 2023
efd505f
chore(Dockerfile): trying to get arm to build
lklimek Mar 24, 2023
5c2ca54
build(docker): trying to fix arm build
lklimek Mar 24, 2023
f2dbb34
build(docker): fixed image for arm
lklimek Mar 24, 2023
7ae5d6a
build(docker): refer to correct branch
lklimek Mar 24, 2023
2501430
build(github): on PR, build only amd64 image
lklimek Mar 24, 2023
ba7e32a
chore: typo
lklimek Mar 24, 2023
9d63afc
chore: typo
lklimek Mar 24, 2023
04f968f
chore: typo
lklimek Mar 24, 2023
3400c9b
chore: typo
lklimek Mar 24, 2023
d182f1f
build(proto-compiler): use vendored-openssl
lklimek Mar 27, 2023
1360294
build(docker): add Alpine docker image to be built
lklimek Mar 27, 2023
4604fab
build(docker): typo
lklimek Mar 27, 2023
ddb0b98
build(github): build only amd64 on non-master branch
lklimek Mar 27, 2023
061371b
build(github): enable sccache
lklimek Mar 30, 2023
9237cf2
build(github): enable Github cache for sccache in Docker images
lklimek Mar 30, 2023
64f1e08
build(docker): minor caching fix
lklimek Mar 30, 2023
40043d3
build(docker): avoid sccache port conflicts on parallel build in github
lklimek Apr 5, 2023
fb80ffe
build(github): allow manual run of docker job
lklimek Apr 5, 2023
b598ea8
build(docker): add missing dependency for arm64
lklimek Apr 5, 2023
9fe3fd1
chore: remove unused dependencies
lklimek Apr 5, 2023
942c033
chore: display some stats
lklimek Apr 5, 2023
976bc88
chore(proto-compiler): use vendored openssl
lklimek Apr 5, 2023
ae9ade1
chore: fix comments
lklimek Apr 5, 2023
956e195
build(github): don't cache /target to use less space
lklimek Apr 5, 2023
8a49d5d
build(github): don't precompile protobuf definitions
lklimek Apr 5, 2023
ab1be54
chore(proto-compiler): replace openssl with openssl-sys
lklimek Apr 5, 2023
a4b580b
Revert "build(github): don't precompile protobuf definitions"
lklimek Apr 5, 2023
e4e563b
chore(proto-compiler): optimize dependencies
lklimek Apr 5, 2023
1eeda88
refactor(proto-compiler): use ureq instead of reqwest to improve perf…
lklimek Apr 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
15 changes: 12 additions & 3 deletions .github/actions/deps/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ runs:
unzip /tmp/protoc.zip -d ${HOME}/.local
echo "PROTOC=${HOME}/.local/bin/protoc" >> $GITHUB_ENV
export PATH="${PATH}:${HOME}/.local/bin"
- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.3
- name: Set sccache variables
shell: bash
run: |
echo SCCACHE_GHA_ENABLED=true >> $GITHUB_ENV
echo RUSTC_WRAPPER=sccache >> $GITHUB_ENV
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-directories: |
proto/src/prost
- name: Compile Protobuf definitions
# Don't cache ./target, as it takes tons of space, use sccache instead.
cache-targets: false
# We set a shared key, as our cache is reusable between jobs
shared-key: rust-cargo
- name: "Compile Protobuf definitions (needed by fmt, doc, etc.)"
shell: bash
run: cargo build -p tenderdash-proto
65 changes: 65 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Docker

on:
workflow_dispatch:
pull_request:
paths-ignore:
- "docs/**"
push:
paths-ignore:
- "docs/**"
branches:
- master
- "v*.*.*"

jobs:
build:
strategy:
matrix:
os: [alpine, debian]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.3

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: amd64

- name: Set up Docker Build
uses: docker/setup-buildx-action@v2.4.1

# ARM build takes very long time, so we build PRs for AMD64 only
- name: Select target platform
id: select_platforms
run: |
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]] ; then
echo "build_platforms=linux/amd64" >> $GITHUB_ENV
else
echo "build_platforms=linux/amd64,linux/arm64" >> $GITHUB_ENV
fi

- name: Build Docker sample image
id: docker_build
uses: docker/build-push-action@v4.0.0
with:
context: .
file: ./Dockerfile-${{ matrix.os }}
build-args: |
REVISION=${{ github.ref }}
SCCACHE_GHA_ENABLED=true
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
platforms: ${{ env.build_platforms }}
push: false
cache-from: |
type=gha
cache-to: |
type=gha,mode=max

- name: Show Docker image digest
run: echo ${{ steps.docker_build.outputs.digest }}
68 changes: 68 additions & 0 deletions Dockerfile-alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This is an example Dockerfile, demonstrating build process of rs-tenderdash-abci

# rust:alpine3.17, published Mar 24, 2023 at 2:55 am
FROM rust:alpine3.17

RUN apk add --no-cache \
git \
wget \
alpine-sdk \
openssl-dev \
libc6-compat \
perl \
unzip \
sccache \
bash

SHELL ["/bin/bash", "-c"]

# one of: aarch_64, x86_64
# ARG PROTOC_ARCH=x86_64
ARG TARGETPLATFORM
ARG BUILDPLATFORM

# Install protoc - protobuf compiler
# The one shipped with Alpine does not work
RUN if [[ "$BUILDPLATFORM" == "linux/arm64" ]] ; then export PROTOC_ARCH=aarch_64; else export PROTOC_ARCH=x86_64 ; fi; \
wget -q -O /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v22.2/protoc-22.2-linux-${PROTOC_ARCH}.zip && \
unzip -qd /opt/protoc /tmp/protoc.zip && \
rm /tmp/protoc.zip && \
ln -s /opt/protoc/bin/protoc /usr/bin/

# Set RUSTC_WRAPPER=/usr/bin/sccache to enable `sccache` caching.
ARG RUSTC_WRAPPER=/usr/bin/sccache
# These should be set for Github Actions caching
ARG SCCACHE_GHA_ENABLED
ARG ACTIONS_CACHE_URL
ARG ACTIONS_RUNTIME_TOKEN

# Create a dummy package
RUN cargo init /usr/src/abci-app
WORKDIR /usr/src/abci-app

# Let's display ABCI version instead of "hello world"
RUN sed -i'' -e 's/println!("Hello, world!");/println!("ABCI version: {}",tenderdash_abci::proto::ABCI_VERSION);/' src/main.rs

# revspec or SHA of commit/branch/tag to use
ARG REVISION="refs/heads/master"

# Add tenderdash-abci as a dependency and build the package
#
# Some notes here:
# 1. All these --mount... are to cache reusable info between runs.
# See https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
# 2. We add `--config net.git-fetch-with-cli=true` to address ARM build issue,
# see https://github.com/rust-lang/cargo/issues/10781#issuecomment-1441071052
# 3. To preserve space on github cache, we call `cargo clean`.
# 4. We set SCCACHE_SERVER_PORT to avoid conflicts during parallel builds
RUN --mount=type=cache,sharing=shared,target=/root/.cache/sccache \
--mount=type=cache,sharing=shared,target=${CARGO_HOME}/registry/index \
--mount=type=cache,sharing=shared,target=${CARGO_HOME}/registry/cache \
--mount=type=cache,sharing=shared,target=${CARGO_HOME}/git/db \
SCCACHE_SERVER_PORT=$((RANDOM+1025)) cargo add --config net.git-fetch-with-cli=true \
--git https://github.com/dashpay/rs-tenderdash-abci --rev "${REVISION}" tenderdash-abci && \
cargo build --config net.git-fetch-with-cli=true && \
cargo run --config net.git-fetch-with-cli=true && \
cargo clean && \
sccache --show-stats

62 changes: 62 additions & 0 deletions Dockerfile-debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This is an example Dockerfile, demonstrating build process of rs-tenderdash-abci

# We use Debian base image, as Alpine has some segmentation fault issue
FROM rust:bullseye

RUN --mount=type=cache,sharing=locked,target=/var/lib/apt/lists \
--mount=type=cache,sharing=locked,target=/var/cache/apt \
rm -f /etc/apt/apt.conf.d/docker-clean && \
apt-get update -qq && \
apt-get install -qq --yes \
protobuf-compiler \
git \
wget \
bash


#
# Install sccache - build cache for Rust.
# This is optional, but it will speed up the build process
#
ARG SCCACHE_URL="https://github.com/mozilla/sccache/releases/download/v0.4.0/sccache-v0.4.0-x86_64-unknown-linux-musl.tar.gz"
RUN wget -q -O /tmp/sccache.tar.gz ${SCCACHE_URL} \
&& mkdir -p /tmp/sccache \
&& tar -z -C /tmp/sccache -xf /tmp/sccache.tar.gz \
&& mv /tmp/sccache/sccache*/sccache /usr/bin/sccache \
&& rm -r /tmp/sccache.tar.gz /tmp/sccache

# Set RUSTC_WRAPPER=/usr/bin/sccache to enable `sccache` caching.
ARG RUSTC_WRAPPER=/usr/bin/sccache
# These should be set for Github Actions caching
ARG SCCACHE_GHA_ENABLED
ARG ACTIONS_CACHE_URL
ARG ACTIONS_RUNTIME_TOKEN

# Create a dummy package
RUN cargo init /usr/src/abci-app
WORKDIR /usr/src/abci-app


# revspec or SHA of commit/branch/tag to use
ARG REVISION="refs/heads/master"

SHELL ["/bin/bash", "-c"]

# Add tenderdash-abci as a dependency and build the package
#
# Some notes here:
# 1. All these --mount... are to cache reusable info between runs.
# See https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
# 2. We add `--config net.git-fetch-with-cli=true` to address ARM build issue,
# see https://github.com/rust-lang/cargo/issues/10781#issuecomment-1441071052
# 3. To preserve space on github cache, we call `cargo clean`.
# 4. We set SCCACHE_SERVER_PORT to avoid conflicts during parallel builds
RUN --mount=type=cache,sharing=shared,target=/root/.cache/sccache \
--mount=type=cache,sharing=shared,target=${CARGO_HOME}/registry/index \
--mount=type=cache,sharing=shared,target=${CARGO_HOME}/registry/cache \
--mount=type=cache,sharing=shared,target=${CARGO_HOME}/git/db \
SCCACHE_SERVER_PORT=$((RANDOM+1025)) cargo add --config net.git-fetch-with-cli=true \
--git https://github.com/dashpay/rs-tenderdash-abci --rev "${REVISION}" tenderdash-abci && \
cargo build --config net.git-fetch-with-cli=true && \
cargo clean && \
sccache --show-stats
4 changes: 2 additions & 2 deletions proto-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ publish = false
walkdir = { version = "2.3" }
prost-build = { version = "0.11" }
tempfile = { version = "3.2.0" }
subtle-encoding = { version = "0.5" }
regex = { "version" = "1.7.1" }
reqwest = { "version" = "0.11.16", features = ["blocking"] }
# Use of native-tls-vendored should build vendored openssl, which is required for Alpine build
ureq = { "version" = "2.6.2" }
zip = { version = "0.6.4", default-features = false, features = ["deflate"] }
fs_extra = { version = "1.3.0" }
13 changes: 4 additions & 9 deletions proto-compiler/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,10 @@ fn download_and_unzip(url: &str, archive_file: &Path, dest_dir: &Path) {
// We download only if the file does not exist
if !archive_file.is_file() {
let mut file = File::create(archive_file).expect("cannot create file");

let mut rb = reqwest::blocking::get(url).expect("cannot download archive");
if !rb.status().is_success() {
panic!(
"cannot download tenderdash sources from {url}: {:?}",
rb.status()
)
}
rb.copy_to(&mut file).expect("cannot save downloaded data");
let rb = ureq::get(url).call().expect("cannot download archive");
// let mut rb = reqwest::blocking::get(url).expect("cannot download archive");
let mut reader = rb.into_reader();
std::io::copy(&mut reader, &mut file).expect("cannot save downloaded data");
file.flush().expect("flush of archive file failed");
}

Expand Down
4 changes: 0 additions & 4 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ all-features = true

[dependencies]
prost = { version = "0.11", default-features = false }
prost-types = { version = "0.11", default-features = false }
bytes = { version = "1.0", default-features = false, features = ["serde"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_bytes = { version = "0.11", default-features = false, features = [
"alloc",
] }
subtle-encoding = { version = "0.5", default-features = false, features = [
"hex",
"base64",
Expand Down