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

probably inefficient code, but its fast af so ship it wooo #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uhh for backend to build for rust, just set RUN_LANGUAGE=rust as an env variable, and the same for go.
1 change: 1 addition & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUN_LANGUAGE=rust
38 changes: 29 additions & 9 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
FROM alpine:latest
ARG LANGUAGE=rust

RUN apk add go docker-cli
FROM alpine:latest AS base
RUN apk add --no-cache go docker-cli musl-dev rust cargo
WORKDIR /usr/src/neon

WORKDIR /root
FROM base AS builder-go
COPY go/ ./go/
RUN cd go && \
go mod download && \
go build -o neon-go

COPY go.mod go.sum ./
FROM base AS builder-rust
COPY rust/ ./rust/
RUN cd rust && \
cargo build --release

RUN go mod download
FROM alpine:latest
RUN apk add --no-cache docker-cli
WORKDIR /root

COPY *.go ./
RUN echo '#!/bin/sh\n\
if [ "$LANGUAGE" = "go" ] && [ -f /root/neon ]; then\n\
exec /root/neon\n\
elif [ -f /root/neon-backend ]; then\n\
exec /root/neon-backend\n\
else\n\
echo "No valid binary found"\n\
exit 1\n\
fi' > /root/run.sh && chmod +x /root/run.sh

RUN go build -o neon
ARG LANGUAGE

COPY runner ./runner
COPY --from=builder-go /usr/src/neon/go/neon-go /root/neon
COPY --from=builder-rust /usr/src/neon/rust/target/release/neon-backend /root/neon-backend

ENTRYPOINT ["/root/neon"]
CMD ["/root/run.sh"]
25 changes: 21 additions & 4 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
services:
web:
build: .
expose:
- 8080
build:
context: .
dockerfile: Dockerfile
args:
- LANGUAGE=${RUN_LANGUAGE:-rust}
ports:
- "8080:8080"
privileged: true
user: root
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
- type: bind
source: /dev/shm/neon
target: /dev/shm/neon
target: /dev/shm/neon
bind:
create_host_path: true
environment:
- RUN_LANGUAGE=${RUN_LANGUAGE:-rust}
entrypoint: >
/bin/sh -c "
mkdir -p /dev/shm/neon &&
chmod -R 777 /dev/shm/neon &&
chown -R root:root /dev/shm/neon &&
if [ \"$RUN_LANGUAGE\" = \"go\" ]; then ./neon; else ./neon-backend; fi
"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions backend/runner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk add python3 gcc python3-dev musl-dev

WORKDIR /root

COPY requirements.txt ./
COPY requirements.txt ./

RUN python3 -m venv venv

Expand All @@ -14,4 +14,4 @@ COPY neon_wrappers.py framebufferio.py ./

ENV BLINKA_OS_AGNOSTIC true

ENTRYPOINT ["venv/bin/python3"]
ENTRYPOINT ["venv/bin/python3"]
3 changes: 1 addition & 2 deletions backend/runner/framebufferio.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def _group_to_buffer(self):
displayio._structs.ColorspaceStruct(32),
displayio._area.Area(0, 0, self.width, self.height),
[0 for _ in range(32*64 // 32)],

buffer
)

Expand All @@ -70,4 +69,4 @@ def _group_to_buffer(self):
self.framebuffer[:] = buffer.tobytes()
a.store(0)

return self.framebuffer
return self.framebuffer
2 changes: 1 addition & 1 deletion backend/runner/neon_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ class Board:
def __getattr__(self, item):
return True

sys.modules['board'] = Board()
sys.modules['board'] = Board()
2 changes: 1 addition & 1 deletion backend/runner/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ pyserial==3.5
pyusb==1.3.1
sysv_ipc==1.1.0
typing_extensions==4.12.2
requests==2.32.3
requests==2.32.3
17 changes: 17 additions & 0 deletions backend/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "neon-backend"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.36", features = ["full"] }
tokio-tungstenite = "0.21"
futures-util = "0.3"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tempfile = "3.10"
tracing = "0.1"
tracing-subscriber = "0.3"
libc = "0.2"
parking_lot = "0.12"
Loading