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

feat: add an option to Dockerfile to can be integrated the code-server #265

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm
RUN apt-get update && apt-get install -y build-essential cmake libclang-dev lldb
RUN wget https://github.com/tsenart/vegeta/releases/download/v12.11.1/vegeta_12.11.1_linux_arm64.tar.gz
RUN tar -xvf vegeta_12.11.1_linux_arm64.tar.gz
RUN mv ./vegeta /usr/local/bin/vegeta
23 changes: 23 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Rust",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/jungaretti/features/make:1": {},
"ghcr.io/lee-orr/rusty-dev-containers/cargo-make:0": {}
},
"runArgs": [
"--rm",
"--privileged"
],
"customizations": {
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"eamodio.gitlens",
"ms-azuretools.vscode-docker"
]
}
}
}
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
38 changes: 35 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# syntax=docker/dockerfile:1.4
FROM rust:1.74.1-bookworm as builder

ARG TARGETPLATFORM
ARG GIT_V_VERSION
ARG ONNXRUNTIME_VERSION=1.17.0

RUN apt-get update && apt-get install -y llvm-dev libclang-dev clang cmake
WORKDIR /usr/src/edge-runtime
RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} \
Expand All @@ -16,11 +18,41 @@ RUN ./scripts/install_onnx.sh $ONNXRUNTIME_VERSION $TARGETPLATFORM /root/libonnx


FROM debian:bookworm-slim

ARG TARGETARCH
ARG USE_CODE_SERVER_INTEGRATION

ENV USE_CODE_SERVER_INTEGRATION ${USE_CODE_SERVER_INTEGRATION}
ENV DENO_VERSION 1.40.3
ENV CODE_SERVER_VERSION 4.20.0
ENV CODE_SERVER_HOST 0.0.0.0
ENV CODE_SERVER_PORT 8999
ENV CODE_SERVER_EXTENSIONS denoland.vscode-deno
ENV ORT_DYLIB_PATH=/usr/local/bin/libonnxruntime.so
ENV SB_AI_MODELS_DIR=/etc/sb_ai/models

RUN apt-get update && apt-get install -y libssl-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get remove -y perl && apt-get autoremove -y

COPY --from=builder /root/edge-runtime /usr/local/bin/edge-runtime
COPY --from=builder /root/libonnxruntime.so /usr/local/bin/libonnxruntime.so
COPY ./models /etc/sb_ai/models
ENV ORT_DYLIB_PATH=/usr/local/bin/libonnxruntime.so
ENV SB_AI_MODELS_DIR=/etc/sb_ai/models
ENTRYPOINT ["edge-runtime"]
COPY ./bin/entrypoint.sh /usr/local/bin

RUN chmod u+x /usr/local/bin/entrypoint.sh

# vscode-server integration
RUN if [ -n "$USE_CODE_SERVER_INTEGRATION" ]; then \
apt-get update && apt-get install -y ca-certificates curl wget unzip dumb-init \
&& wget https://github.com/coder/code-server/releases/download/v${CODE_SERVER_VERSION}/code-server_${CODE_SERVER_VERSION}_${TARGETARCH}.deb -P /tmp \
&& dpkg -i /tmp/code-server_${CODE_SERVER_VERSION}_${TARGETARCH}.deb \
&& rm -f /tmp/code-server_${CODE_SERVER_VERSION}_${TARGETARCH}.deb; \
if [ "${TARGETARCH}" = "arm64" ]; then \
wget https://github.com/LukeChannings/deno-arm64/releases/download/v${DENO_VERSION}/deno-linux-arm64.zip -P /tmp \
&& unzip /tmp/deno-linux-arm64.zip -d /usr/local/bin; \
else \
curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh; \
fi \
fi

ENTRYPOINT ["dumb-init", "--", "/usr/local/bin/entrypoint.sh"]
40 changes: 40 additions & 0 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
set -eu

export PS1='\w $ '

EXTENSIONS="${CODE_SERVER_EXTENSIONS:-none}"

if [ -z "$USE_CODE_SERVER_INTEGRATION" ]; then
edge-runtime $@ &
else
mkdir -p /root/.local/share/code-server/User
cat > /root/.local/share/code-server/User/settings.json << EOF
{
"workbench.colorTheme": "Visual Studio Dark",
"deno.enable": true
}
EOF

if [ ${EXTENSIONS} != "none" ]; then
echo "Installing Extensions"
for extension in $(echo ${EXTENSIONS} | tr "," "\n")
do
if [ "${extension}" != "" ]; then
/usr/bin/code-server \
--install-extension "${extension}" \
/home/deno/functions
fi
done
fi

(/usr/bin/code-server \
--bind-addr "${CODE_SERVER_HOST}":"${CODE_SERVER_PORT}" \
--auth none \
/home/deno/functions \
) &

edge-runtime $@ &
fi

wait -n
Loading