1
0
Fork 0

Add docker to test

This commit is contained in:
Florian RICHER 2023-01-31 14:36:59 +01:00
parent 535abde7c0
commit 115855ac75
No known key found for this signature in database
GPG key ID: 6BF27BF8A1E71623
5 changed files with 43 additions and 6 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
target/
.git/

30
Dockerfile Normal file
View file

@ -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

View file

@ -2,4 +2,10 @@
## Requirements ## Requirements
- `protobuf` see [tonic dependencies](https://github.com/hyperium/tonic#dependencies) - `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\": []}"`

View file

@ -8,10 +8,9 @@ use tonic::Response;
#[cfg(unix)] #[cfg(unix)]
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
// let arg = std::env::args() let arg = std::env::args()
// .skip(1) .skip(1)
// .next().unwrap(); .last().unwrap();
let arg = String::from("{\"command\": \"/usr/bin/nu\", \"envs\": {}, \"args\": []}");
let mut command : std::process::Command = serde_json::from_str::<libcommand::Command>(&arg) let mut command : std::process::Command = serde_json::from_str::<libcommand::Command>(&arg)
.unwrap() .unwrap()
.into(); .into();

View file

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use serde::{Serialize, Deserialize}; 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 { pub mod internal {
tonic::include_proto!("internal"); tonic::include_proto!("internal");