-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dockerization for http client eg
- Loading branch information
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Use a Rust base image | ||
FROM rust:latest | ||
|
||
# Install tmux and other utilities | ||
RUN apt-get update && apt-get install -y tmux bash && apt-get clean | ||
|
||
# Set the working directory | ||
WORKDIR /usr/src/swarmnl-http-client-demo | ||
|
||
# Copy the Rust project into the container | ||
COPY . . | ||
|
||
# Prebuild dependencies to speed up the runtime builds | ||
RUN cargo build --release --features=first-node && \ | ||
cargo build --release --features=second-node && \ | ||
cargo build --release --features=third-node | ||
|
||
# Copy the tmux startup script | ||
COPY run_nodes.sh /run_nodes.sh | ||
RUN chmod +x /run_nodes.sh | ||
|
||
# Start tmux with the script | ||
CMD ["/run_nodes.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# HTTP client example | ||
|
||
SwarmNL supports seamless integration with HTTP clients working in the application layer by providing interfaces to handle network events as they occur. This example demonstrates how to send an HTTP POST request to a remote server in response to incoming replication data events. | ||
|
||
To run this example, cd into the root of this directory and in separate terminals launch the following commands: | ||
|
||
```bash | ||
cargo run --features=first-node | ||
``` | ||
|
||
Then the second node: | ||
|
||
```bash | ||
cargo run --features=second-node | ||
``` | ||
|
||
And the third node: | ||
|
||
```bash | ||
cargo run --features=first-node | ||
``` | ||
|
||
Replicate data across the network: | ||
|
||
```bash | ||
# in the first terminal | ||
repl wonderful | ||
|
||
# in the second terminal | ||
repl great | ||
|
||
# in the third terminal | ||
repl amazing | ||
``` | ||
|
||
You should see the message `Successfully sent POST request.` printed to the terminal. | ||
|
||
## Run with Docker | ||
|
||
Build: | ||
|
||
```bash | ||
docker build -t http-client . | ||
``` | ||
|
||
Run: | ||
|
||
```bash | ||
docker run -it http-client | ||
``` | ||
|
||
The Docker image will open three terminals and the script will submit commands to each one to demonstrate the example. To quit, use the `exit` command in each terminal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# Start tmux session | ||
tmux new-session -d -s rust-nodes "cargo run --features=first-node" | ||
tmux split-window -h "cargo run --features=second-node" | ||
tmux split-window -v "cargo run --features=third-node" | ||
|
||
# Arrange panes for better layout | ||
tmux select-layout tiled | ||
|
||
# Give the nodes some time to start | ||
sleep 10 | ||
|
||
# Send commands to each pane | ||
# Pane 0 (first node) | ||
tmux send-keys -t rust-nodes:0.0 "repl wonderful" C-m | ||
sleep 3 | ||
|
||
# Pane 1 (second node) | ||
tmux send-keys -t rust-nodes:0.1 "repl great" C-m | ||
sleep 3 | ||
|
||
# Pane 2 (third node) | ||
tmux send-keys -t rust-nodes:0.2 "repl amazing" C-m | ||
sleep 3 | ||
|
||
# Attach to the session so you can observe the output | ||
tmux attach-session -t rust-nodes | ||
|
||
# Exit the sessions | ||
tmux send-keys -t rust-nodes:0.0 "exit" C-m | ||
tmux send-keys -t rust-nodes:0.1 "exit" C-m | ||
tmux send-keys -t rust-nodes:0.2 "exit" C-m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters