diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 991c80d..3cf948e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,7 +22,7 @@ jobs: bin: splash-linux-arm64 - os_name: Linux-x86_64 os: ubuntu-20.04 - target: x86_64-unknown-linux-gnu + target: x86_64-unknown-linux-musl bin: splash-linux-amd64 - os_name: Windows-x86_64 os: windows-latest @@ -40,6 +40,9 @@ jobs: - stable steps: - uses: actions/checkout@v3 + - name: Install Linux musl-tools + if: contains(matrix.platform.target, 'musl') + run: sudo apt-get install --yes --no-install-recommends musl-tools - name: Build binary uses: houseabsolute/actions-rust-cross@v0 with: @@ -62,3 +65,45 @@ jobs: files: | target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256 + docker: + runs-on: ubuntu-latest + name: Build and push image + needs: build + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 + - run: docker context create ci + - run: docker context use ci + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + endpoint: ci + - name: Fetch latest release tag + id: latest-tag + run: | + LATEST_TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) + echo "Latest release tag is $LATEST_TAG" + echo "::set-output name=tag::$LATEST_TAG" + shell: bash + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + platforms: linux/amd64, linux/arm64 + build-args: | + GITHUB_ORG=${{ github.repository_owner }} + GITHUB_REPO=${{ github.event.repository.name }} + tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.latest-tag.outputs.tag }},${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Cargo.lock b/Cargo.lock index 93da301..52cbbe4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,9 +81,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "anstream" -version = "0.6.7" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", @@ -729,17 +729,27 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + [[package]] name = "env_logger" -version = "0.10.1" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +checksum = "05e7cf40684ae96ade6232ed84582f40ce0a66efcd43a5117aef610534f8e0b8" dependencies = [ + "anstream", + "anstyle", + "env_filter", "humantime", - "is-terminal", "log", - "regex", - "termcolor", ] [[package]] @@ -1339,17 +1349,6 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" -[[package]] -name = "is-terminal" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" -dependencies = [ - "hermit-abi", - "rustix", - "windows-sys 0.52.0", -] - [[package]] name = "itoa" version = "1.0.10" @@ -3014,15 +3013,6 @@ dependencies = [ "libc", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.56" @@ -3546,15 +3536,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 13cda45..b108a1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ futures = "0.3.30" libp2p = { version = "0.53.2", features = [ "tokio", "gossipsub", "kad", "noise", "macros", "identify", "tcp", "yamux", "secp256k1", "dns"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } -env_logger = "0.10.1" +env_logger = "0.11.1" clap = { version = "4.4.17", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..84ba399 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM alpine:3.14 + +RUN apk add --no-cache curl jq + +WORKDIR /app + +ARG GITHUB_ORG +ARG GITHUB_REPO +ENV GITHUB_ORG $GITHUB_ORG +ENV GITHUB_REPO $GITHUB_REPO + + +RUN arch=$(uname -m) && \ + os=$(uname -s) && \ + case "$arch" in \ + x86_64) arch="amd64" ;; \ + aarch64) arch="arm64" ;; \ + *) echo "Unsupported architecture: $arch" && exit 1 ;; \ + esac && \ + case "$os" in \ + Linux) os="linux" ;; \ + Darwin) os="darwin" ;; \ + *) echo "Unsupported OS: $os" && exit 1 ;; \ + esac && \ + RELEASE_URL=$(curl -sfL https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases/latest | \ + jq -r --arg binary "${GITHUB_REPO}-${os}-${arch}" '.assets[] | select(.name == $binary) | .browser_download_url') && \ + echo "Downloading binary" && \ + curl -sfL ${RELEASE_URL} -o ${GITHUB_REPO} && \ + chmod +x ${GITHUB_REPO} + +RUN cat > /entrypoint.sh <<'EOF' +#!/bin/sh +exec /app/${GITHUB_REPO} "$@" +EOF + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 80aa0ee..94784ed 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,16 @@ Start a node and reuse identity: `./splash --identify-file identity.json` +## Test the API with Docker + +```bash +docker run -p 11511:11511 -p 4000:4000 dexie-space/splash:latest \ +--listen-offer-submission 0.0.0.0:4000 \ +--listen-address /ip4/0.0.0.0/tcp/11511 +# send the request +curl -X POST -H "Content-Type: application/json" -d '{"offer":"offer1..."}' http://localhost:4000 +``` + ## Become a stable peer To become a stable peer, you need to open an inbound port in your firewall. Then start Splash! with the `--listen-address` option and choose your public interface and the selected port (eg. `11511`). diff --git a/src/main.rs b/src/main.rs index 2db1797..0e01424 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,7 +60,7 @@ async fn main() -> Result<(), Box> { )? .with_dns()? .with_behaviour(|key| { - println!("Our Peer ID: {}", key.public().to_peer_id().to_string()); + println!("Our Peer ID: {}", key.public().to_peer_id()); // We can take the hash of message and use it as an ID. let unique_offer_fn = |message: &gossipsub::Message| { @@ -85,9 +85,9 @@ async fn main() -> Result<(), Box> { // Create a Kademlia behaviour. let mut cfg = kad::Config::default(); - cfg.set_protocol_names(vec![StreamProtocol::try_from_owned(format!( - "/splash/kad/1" - ))?]); + cfg.set_protocol_names(vec![StreamProtocol::try_from_owned( + "/splash/kad/1".to_string(), + )?]); cfg.set_query_timeout(Duration::from_secs(60)); let store = kad::store::MemoryStore::new(key.public().to_peer_id());