Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine #292

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/backend-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Backend build

on:
pull_request:
types:
- synchronize
- opened
- reopened
paths:
- 'app-server/**'

jobs:
build-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-app-server-pr-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-buildx-app-server-pr-

- name: Build and push image to AWS ECR
uses: docker/build-push-action@v6
with:
context: ./app-server
push: false
platforms: linux/amd64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
54 changes: 53 additions & 1 deletion app-server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ sha3 = "0.10.8"
aws-sdk-s3 = "1.63.0"
base64 = "0.22.1"
sodiumoxide = "0.2.7"
actix-ws = "0.3.0"
tokio-tungstenite = "*"


[build-dependencies]
tonic-build = "0.12.3"
55 changes: 36 additions & 19 deletions app-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
# Uses the bullseye-slim debian image per the rust recommendation.
FROM rust:1.81-slim-bullseye AS builder

# Install g++ and other build essentials for compiling openssl/tls dependencies
RUN apt update
RUN apt install -y build-essential
# Build stage with cargo chef for dependency caching
FROM rust:1.81-slim-bullseye AS chef
WORKDIR /app-server

# Install other openssl / native tls dependencies
RUN apt-get update
RUN apt-get install -y \
# Install build dependencies and cargo-chef
RUN apt-get update && apt-get install -y \
build-essential \
pkg-config \
libssl-dev \
protobuf-compiler \
libfontconfig1-dev \
libfontconfig \
libclang-dev
libfontconfig \
libclang-dev \
&& rm -rf /var/lib/apt/lists/* \
&& cargo install cargo-chef

# Clean up some unnecessary apt artifacts
RUN rm -rf /var/lib/apt/lists/*

WORKDIR /app-server
# Prepare recipe for dependency caching
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

EXPOSE 8000
ARG DATABASE_URL
ENV DATABASE_URL=${DATABASE_URL}
# Build dependencies - this layer is cached
FROM chef AS builder
COPY --from=planner /app-server/recipe.json recipe.json
# Build dependencies
RUN cargo chef cook --release --recipe-path recipe.json

# Build application
COPY . .
ENV SQLX_OFFLINE=true
RUN cargo build --release --all

CMD ["./target/release/app-server"]
# Final runtime stage
FROM debian:bullseye-slim AS runtime
WORKDIR /app-server

# Install only runtime dependencies
RUN apt-get update && apt-get install -y \
libssl1.1 \
libfontconfig1 \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /app-server/target/release/app-server .

EXPOSE 8000

CMD ["./app-server"]
9 changes: 9 additions & 0 deletions app-server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.out_dir("./src/code_executor/")
.compile_protos(&[proto_file], &["proto"])?;

let proto_file = "./proto/machine_manager_grpc.proto";

tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional") // for older systems
.build_client(true)
.build_server(false)
.out_dir("./src/machine_manager/")
.compile_protos(&[proto_file], &["proto"])?;

tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional") // for older systems
.build_client(false)
Expand Down
54 changes: 54 additions & 0 deletions app-server/proto/machine_manager_grpc.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
syntax = "proto3";
package machine_manager_service_grpc;

message StartMachineRequest {}

message StartMachineResponse {
string machine_id = 1;
}

enum ComputerAction {
KEY = 0;
TYPE = 1;
MOUSE_MOVE = 2;
LEFT_CLICK = 3;
LEFT_CLICK_DRAG = 4;
RIGHT_CLICK = 5;
MIDDLE_CLICK = 6;
DOUBLE_CLICK = 7;
SCREENSHOT = 8;
CURSOR_POSITION = 9;
}

message ComputerActionCoordinate {
int32 x = 1;
int32 y = 2;
}

message ComputerActionRequest {
string machine_id = 1;
ComputerAction action = 2;
optional string text = 3;
optional ComputerActionCoordinate coordinates = 4;
}

message ComputerActionResponse {
optional string output = 1;
optional string error = 2;
optional string base64_image = 3;
optional string system = 4;
}

message TerminateMachineRequest {
string machine_id = 1;
}

message TerminateMachineResponse {
bool success = 1;
}

service MachineManagerService {
rpc StartMachine(StartMachineRequest) returns (StartMachineResponse);
rpc TerminateMachine(TerminateMachineRequest) returns (TerminateMachineResponse);
rpc ExecuteComputerAction(ComputerActionRequest) returns (ComputerActionResponse);
}
Loading
Loading