Setup CircleCI build (#107)

* Add circleci config file

* Try enable IPv6

* Make sure `test` uses machine executor

* Add an integration_test step in parallel

* Explicit docker runs for machine tests

* Try make the integration test work

* Hide Dockerfile in a subfolder

* Fix the ping example hanging

* Explicitely pass the port to the ping client
This commit is contained in:
Pierre Krieger
2018-01-23 19:21:41 +01:00
committed by GitHub
parent 1413bb8935
commit bd17f2ea96
4 changed files with 64 additions and 1 deletions

54
.circleci/config.yml Normal file
View File

@ -0,0 +1,54 @@
version: 2
workflows:
version: 2
build:
jobs:
- test
- integration_test
jobs:
test:
machine:
enabled: true
docker_layer_caching: true
steps:
- checkout
- run:
name: Enable ipv6
command: |
cat <<'EOF' | sudo tee /etc/docker/daemon.json
{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64"
}
EOF
sudo service docker restart
- restore_cache:
key: test-cache
- run:
name: Prepare docker container for building
command: docker build -t rust-libp2p -f .circleci/images/rust-libp2p/Dockerfile .
- run:
name: Run tests, inside a docker image
command: docker run --rm -v "/cache/cargo/registry:/usr/local/cargo/registry" -v "/cache/target:/app/target" -it rust-libp2p cargo test
- save_cache:
key: docker-cache
paths:
- "/cache"
integration_test:
docker:
- image: rust
- image: ipfs/go-ipfs
steps:
- checkout
- restore_cache:
key: integration-test-cache
- run:
command: cargo run -p example --example ping-client -- /ip4/127.0.0.1/tcp/4001
- save_cache:
key: integration-test-cache
paths:
- "~/.cargo"
- "./target"

View File

@ -0,0 +1,5 @@
FROM rust
RUN mkdir /app
WORKDIR /app
COPY . /app

View File

@ -45,3 +45,4 @@ Progress for the `impl Trait` syntax can be tracked in [this issue of the Rust r
Once this syntax is stable in the nightly version, we will consider requiring the nightly version Once this syntax is stable in the nightly version, we will consider requiring the nightly version
of the compiler and switching to this syntax. of the compiler and switching to this syntax.

View File

@ -29,6 +29,7 @@ extern crate tokio_core;
extern crate tokio_io; extern crate tokio_io;
use futures::Future; use futures::Future;
use futures::sync::oneshot;
use std::env; use std::env;
use swarm::{UpgradeExt, Transport, DeniedConnectionUpgrade}; use swarm::{UpgradeExt, Transport, DeniedConnectionUpgrade};
use tcp::TcpConfig; use tcp::TcpConfig;
@ -79,11 +80,13 @@ fn main() {
}); });
// We now use the controller to dial to the address. // We now use the controller to dial to the address.
let (tx, rx) = oneshot::channel();
swarm_controller swarm_controller
.dial_custom_handler(target_addr.parse().expect("invalid multiaddr"), ping::Ping, .dial_custom_handler(target_addr.parse().expect("invalid multiaddr"), ping::Ping,
|(mut pinger, future)| { |(mut pinger, future)| {
let ping = pinger.ping().map_err(|_| unreachable!()).inspect(|_| { let ping = pinger.ping().map_err(|_| unreachable!()).inspect(|_| {
println!("Received pong from the remote"); println!("Received pong from the remote");
let _ = tx.send(());
}); });
ping.select(future).map(|_| ()).map_err(|(e, _)| e) ping.select(future).map(|_| ()).map_err(|(e, _)| e)
}) })
@ -98,5 +101,5 @@ fn main() {
// `swarm_future` is a future that contains all the behaviour that we want, but nothing has // `swarm_future` is a future that contains all the behaviour that we want, but nothing has
// actually started yet. Because we created the `TcpConfig` with tokio, we need to run the // actually started yet. Because we created the `TcpConfig` with tokio, we need to run the
// future through the tokio core. // future through the tokio core.
core.run(swarm_future).unwrap(); core.run(rx.select(swarm_future.map_err(|_| unreachable!())).map_err(|(e, _)| e).map(|_| ())).unwrap();
} }