Working interop

This commit is contained in:
Tanguy 2022-11-07 18:10:25 +01:00
parent 4d55f50126
commit c8e4b3227e
No known key found for this signature in database
GPG Key ID: 7DD8EC6B6CE6C45E
3 changed files with 125 additions and 5 deletions

View File

@ -0,0 +1,109 @@
[metadata]
name = "go-rust-cross-version-{{ or $.Env.InteropTarget "-" }}-{{ or $.Env.GitReference "" }}"
[global]
plan = "libp2p/ping"
case = "ping"
runner = "local:docker"
concurrent_builds = 1
[global.build_config]
enable_go_build_cache = false # see https://github.com/testground/testground/issues/1361
# disable testground's goproxy which hangs on github runners.
go_proxy_mode = "remote"
go_proxy_url = "https://proxy.golang.org"
{{ with (load_resource "./go.toml") }}
{{ with (index .groups 0) }}
[[groups]]
id = "go-latest-{{ .Id }}"
instances = { count = 1 }
builder = "docker:go"
[groups.build]
selectors = ['{{ .Selector }}']
[groups.build_config]
path = "./go/"
build_base_image = 'golang:{{ .GoVersion }}-buster'
modfile = "{{ .Modfile }}"
{{ end }}
{{ if eq $.Env.InteropTarget "go" }}
{{ if $.Env.GitReference }}
{{ with .custom }}
[[groups]]
id = "go-custom-{{ $.Env.GitReference }}"
instances = { count = 1 }
builder = "docker:go"
[groups.build]
selectors = ['{{ .Selector }}']
[[groups.build.dependencies]]
module = "github.com/libp2p/go-libp2p"
version = "{{ $.Env.GitReference }}"
{{ if $.Env.GitTarget }}
target = "{{ $.Env.GitTarget }}"
{{ end }}
[groups.build_config]
path = "./go/"
build_base_image = 'golang:{{ .GoVersion }}-buster'
modfile = "{{ .Modfile }}"
[groups.build_config.dockerfile_extensions]
# deal with dependency changes in master until we create the new vx.y.z instance
pre_build = """
RUN cd ${PLAN_DIR} && \
go mod download github.com/libp2p/go-libp2p && \
go mod tidy -compat={{ .GoVersion }}
"""
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ with (load_resource "./rust.toml") }}
{{ with (index .groups 0) }}
[[groups]]
id = "rust-latest-{{ .Id }}"
instances = { count = 1 }
builder = "docker:generic"
[groups.build_config]
path = "./rust/"
[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
{{ end }}
{{ if eq $.Env.InteropTarget "rust" }}
{{ if $.Env.GitReference }}
{{ with .custom }}
[[groups]]
id = "rust-custom-{{ $.Env.GitReference }}"
instances = { count = 1 }
builder = "docker:generic"
[groups.build_config]
path = "./rust/"
[groups.build_config.build_args]
CARGO_FEATURES = '{{ .CargoFeatures }}'
CARGO_REMOVE = '{{ .CargoFeatures }}'
CARGO_PATCH = """
{{ .CargoFeatures }} = {package = "libp2p", git = "https://{{ or $.Env.GitTarget "github.com/libp2p/rust-libp2p" }}", rev = "{{ $.Env.GitReference }}", default_features = false, features = [ "websocket", "mplex", "yamux", "tcp", "ping", "noise", "dns", "async-std", "rsa" ], optional = true}
"""
{{ end }}
{{ end }}
{{ end }}
{{ end }}
[[groups]]
id = "nim-latest"
instances = { count = 1 }
builder = "docker:generic"
[groups.build_config]
path = "./nim/"

View File

@ -1,10 +1,11 @@
FROM nimlang/nim:alpine as builder
RUN nimble install -y "https://github.com/status-im/testground-nim-sdk@#9fba8111179c2ace7a2b595d8ed8cb10f0bf9c21"
RUN nimble install -y "https://github.com/status-im/testground-nim-sdk@#c282ff68c08ef85a7ca011e077e3e69eb1a6edec"
RUN nimble install -y "libp2p"
FROM builder
COPY . .
ARG PLAN_PATH="./"
COPY ./plan/${PLAN_PATH} ./plan
RUN cd plan && nimble install -dy && nim c -d:chronicles_log_level=NOTICE main.nim
ENTRYPOINT ["plan/main"]

View File

@ -5,19 +5,29 @@ import sequtils
type
PeerData = object
id: string
addrs: seq[string]
id {.serializedFieldName: "ID".}: string
addrs {.serializedFieldName: "Addrs".}: seq[string]
testground(client):
let addresses = getInterfaces().filterIt(it.name == "eth1").mapIt(it.addresses)
if addresses.len < 1 or addresses[0].len < 1:
quit "Can't find local ip!"
discard await client.signal("initialized_global")
let
maxLatency = client.param(int, "max_latency_ms")
rng = libp2p.newRng()
address = addresses[0][0].host
switch = newStandardSwitch(addrs = MultiAddress.init(address).tryGet(), rng = rng)
switch =
SwitchBuilder
.new()
.withAddress(MultiAddress.init(address).tryGet())
.withRng(rng)
.withYamux()
.withTcpTransport()
.withNoise()
.build()
pingProtocol = Ping.new(rng = rng)
switch.mount(pingProtocol)