From 115855ac75700295670897d586c5fa38fa378846 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Tue, 31 Jan 2023 14:36:59 +0100 Subject: [PATCH] Add docker to test --- .dockerignore | 2 ++ Dockerfile | 30 ++++++++++++++++++++++++++++++ README.md | 8 +++++++- src/client/main.rs | 7 +++---- src/lib.rs | 2 +- 5 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9089a19 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +target/ +.git/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3b04912 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:latest + +# Configure requirements +RUN apt update && apt install openssh-server curl build-essential protobuf-compiler -y +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +RUN useradd -rm -d /home/test -s /opt/gateway/target/release/client test +RUN echo 'test:test' | chpasswd + +# Build project binaries +COPY . /opt/gateway +WORKDIR /opt/gateway +RUN cargo build --release --bin daemon +RUN cargo build --release --bin client +RUN mkdir -p /var/run +RUN chmod ugo+rx /var +RUN chmod ugo+rwx /var/run + +RUN echo '#!/bin/sh\n\ +/usr/sbin/sshd -D&\n\ +su - test -s /bin/sh -c "/opt/gateway/target/release/daemon"' > /opt/startup.sh + +RUN chmod +x /opt/startup.sh + +RUN service ssh start + +EXPOSE 22 + +CMD /opt/startup.sh diff --git a/README.md b/README.md index 5579fd7..23031a3 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,10 @@ ## Requirements -- `protobuf` see [tonic dependencies](https://github.com/hyperium/tonic#dependencies) \ No newline at end of file +- `protobuf` see [tonic dependencies](https://github.com/hyperium/tonic#dependencies) + +## RUN LOCAL + +- `docker build . -t gateway` +- `docker run -p 22:22 gateway` +- `ssh test@localhost "{\"command\": \"/bin/bash\", \"envs\": {}, \"args\": []}"` \ No newline at end of file diff --git a/src/client/main.rs b/src/client/main.rs index 5d72943..eaf2c47 100644 --- a/src/client/main.rs +++ b/src/client/main.rs @@ -8,10 +8,9 @@ use tonic::Response; #[cfg(unix)] #[tokio::main] async fn main() -> Result<(), Box> { - // let arg = std::env::args() - // .skip(1) - // .next().unwrap(); - let arg = String::from("{\"command\": \"/usr/bin/nu\", \"envs\": {}, \"args\": []}"); + let arg = std::env::args() + .skip(1) + .last().unwrap(); let mut command : std::process::Command = serde_json::from_str::(&arg) .unwrap() .into(); diff --git a/src/lib.rs b/src/lib.rs index 8c12f35..eb609f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use serde::{Serialize, Deserialize}; -pub const SOCK_FILE : &'static str = "command_gateway.sock"; +pub const SOCK_FILE : &'static str = "/var/run/command_gateway.sock"; pub mod internal { tonic::include_proto!("internal");