Browse Source

add devcontainer

liuyuqi-dellpc 10 months ago
parent
commit
5d5030a2f4
10 changed files with 369 additions and 6 deletions
  1. 50 0
      .devcontainer/Dockerfile
  2. 75 0
      .devcontainer/build.sh
  3. 34 0
      .devcontainer/devcontainer.json
  4. 3 0
      .devcontainer/noop.txt
  5. 23 0
      .devcontainer/setup.sh
  6. 12 0
      .github/dependabot.yml
  7. 55 0
      Dockerfile
  8. 0 6
      README.md
  9. 81 0
      dev.md
  10. 36 0
      entrypoint.sh

+ 50 - 0
.devcontainer/Dockerfile

@@ -0,0 +1,50 @@
+FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04
+ENV HOME=/home/vscode
+ENV WORKDIR=$HOME/rustdesk
+
+WORKDIR $HOME
+RUN sudo apt update -y && sudo apt install -y g++ gcc git curl wget nasm yasm libgtk-3-dev clang libxcb-randr0-dev libxdo-dev libxfixes-dev libxcb-shape0-dev libxcb-xfixes0-dev libasound2-dev libpulse-dev cmake unzip zip sudo libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
+WORKDIR /
+
+RUN git clone https://github.com/microsoft/vcpkg 
+WORKDIR vcpkg
+RUN git checkout 2023.04.15
+RUN /vcpkg/bootstrap-vcpkg.sh -disableMetrics
+ENV VCPKG_ROOT=/vcpkg
+RUN $VCPKG_ROOT/vcpkg --disable-metrics install libvpx libyuv opus aom
+
+WORKDIR /
+RUN wget https://github.com/rustdesk/doc.rustdesk.com/releases/download/console/dep.tar.gz && tar xzf dep.tar.gz
+
+
+USER vscode
+WORKDIR $HOME
+RUN wget https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.lnx/x64/libsciter-gtk.so
+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
+RUN chmod +x rustup.sh
+RUN $HOME/rustup.sh -y
+RUN $HOME/.cargo/bin/rustup target add aarch64-linux-android
+RUN $HOME/.cargo/bin/cargo install cargo-ndk
+
+# Install Flutter
+RUN wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.10.1-stable.tar.xz
+RUN tar xf flutter_linux_3.10.1-stable.tar.xz && rm flutter_linux_3.10.1-stable.tar.xz
+ENV PATH="$PATH:$HOME/flutter/bin"
+RUN dart pub global activate ffigen 5.0.1
+
+
+# Install packages
+RUN sudo apt-get install -y libclang-dev
+RUN sudo apt install -y gcc-multilib
+
+WORKDIR $WORKDIR
+ENV ANDROID_NDK_HOME=/opt/android/ndk/22.1.7171670
+
+# Somehow try to automate flutter pub get
+# https://rustdesk.com/docs/en/dev/build/android/
+# Put below steps in entrypoint.sh
+# cd flutter
+# wget https://github.com/rustdesk/doc.rustdesk.com/releases/download/console/so.tar.gz
+# tar xzf so.tar.gz
+
+# own /opt/android

+ 75 - 0
.devcontainer/build.sh

@@ -0,0 +1,75 @@
+#!/bin/bash
+
+set -e
+
+MODE=${1:---debug}
+TYPE=${2:-linux}
+MODE=${MODE/*-/}
+
+
+build(){
+    pwd
+    $WORKDIR/entrypoint $1
+}
+
+build_arm64(){
+    CWD=$(pwd)
+    cd $WORKDIR/flutter
+    flutter pub get
+    cd $WORKDIR
+    $WORKDIR/flutter/ndk_arm64.sh
+    cp $WORKDIR/target/aarch64-linux-android/release/liblibrustdesk.so $WORKDIR/flutter/android/app/src/main/jniLibs/arm64-v8a/librustdesk.so
+    cd $CWD
+}
+
+build_apk(){
+    cd $WORKDIR/flutter
+    MODE=$1 $WORKDIR/flutter/build_android.sh
+    cd $WORKDIR
+}
+
+key_gen(){
+    if [ ! -f $WORKDIR/flutter/android/key.properties ]
+    then
+        if [ ! -f $HOME/upload-keystore.jks ]
+        then
+            $WORKDIR/.devcontainer/setup.sh key
+        fi
+        read -r -p "enter the password used to generate $HOME/upload-keystore.jks\n" password
+        echo -e "storePassword=${password}\nkeyPassword=${password}\nkeyAlias=upload\nstoreFile=$HOME/upload-keystore.jks" > $WORKDIR/flutter/android/key.properties
+    else
+        echo "Believing storeFile is created ref: $WORKDIR/flutter/android/key.properties"
+    fi
+}
+
+android_build(){
+    if [ ! -d $WORKDIR/flutter/android/app/src/main/jniLibs/arm64-v8a ]
+    then
+        $WORKDIR/.devcontainer/setup.sh android
+    fi
+    build_arm64
+    case $1 in
+        debug)
+        build_apk debug
+        ;;
+        release)
+        key_gen
+        build_apk release
+        ;;
+    esac
+}
+
+case "$MODE:$TYPE" in
+    "debug:linux")
+    build
+    ;;
+    "release:linux")
+    build --release
+    ;;
+    "debug:android")
+    android_build debug
+    ;;
+    "release:android")
+    android_build release
+    ;;
+esac

+ 34 - 0
.devcontainer/devcontainer.json

@@ -0,0 +1,34 @@
+{
+    "name": "rustdesk",
+    "build": {
+        "dockerfile": "./Dockerfile",
+        "context": "."
+    },
+    "workspaceMount": "source=${localWorkspaceFolder},target=/home/vscode/rustdesk,type=bind,consistency=cache",
+    "workspaceFolder": "/home/vscode/rustdesk",
+    "postStartCommand": ".devcontainer/build.sh",
+    "features": {
+        "ghcr.io/devcontainers/features/java:1": {},
+        "ghcr.io/akhildevelops/devcontainer-features/android-cli:latest": {
+            "PACKAGES": "platform-tools,ndk;23.2.8568313"
+        }
+    },
+    "customizations": {
+        "vscode": {
+            "extensions": [
+                "vadimcn.vscode-lldb",
+                "mutantdino.resourcemonitor",
+                "rust-lang.rust-analyzer",
+                "tamasfe.even-better-toml",
+                "serayuzgur.crates",
+                "mhutchie.git-graph",
+                "eamodio.gitlens"
+            ],
+            "settings": {
+                "files.watcherExclude": {
+                    "**/target/**": true
+                }
+            }
+        }
+    }
+}

+ 3 - 0
.devcontainer/noop.txt

@@ -0,0 +1,3 @@
+This file copied into the container along with environment.yml* from the parent
+folder. This file is included to prevents the Dockerfile COPY instruction from 
+failing if no environment.yml is found.

+ 23 - 0
.devcontainer/setup.sh

@@ -0,0 +1,23 @@
+#!/bin/bash
+set -e
+case $1 in
+    android)
+    # install deps
+    cd $WORKDIR/flutter
+    flutter pub get
+    wget https://github.com/rustdesk/doc.rustdesk.com/releases/download/console/so.tar.gz
+    tar xzf so.tar.gz
+    rm so.tar.gz
+    sudo chown -R $(whoami) $ANDROID_HOME
+    echo "Setup is Done."
+    ;;
+    linux)
+    echo "Linux Setup"
+    ;;
+    key)
+    echo -e "\n$HOME/upload-keystore.jks is not created.\nLet's create it.\nRemember the password you enter in keytool!"
+    keytool -genkey -v -keystore $HOME/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
+    ;;
+esac
+
+    

+ 12 - 0
.github/dependabot.yml

@@ -0,0 +1,12 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for more information:
+# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+# https://containers.dev/guide/dependabot
+
+version: 2
+updates:
+ - package-ecosystem: "devcontainers"
+   directory: "/"
+   schedule:
+     interval: weekly

+ 55 - 0
Dockerfile

@@ -0,0 +1,55 @@
+FROM debian:bullseye-slim
+
+WORKDIR /
+ARG DEBIAN_FRONTEND=noninteractive
+RUN apt update -y && \
+    apt install --yes --no-install-recommends \
+    g++ \
+    gcc \
+    git \
+    curl \
+    nasm \
+    yasm \
+    libgtk-3-dev \
+    clang \
+    libxcb-randr0-dev \
+    libxdo-dev \
+    libxfixes-dev \
+    libxcb-shape0-dev \
+    libxcb-xfixes0-dev \
+    libasound2-dev \
+    libpam0g-dev \
+    libpulse-dev \
+    make \
+    cmake \
+    unzip \
+    zip \
+    sudo \
+    libgstreamer1.0-dev \
+    libgstreamer-plugins-base1.0-dev \
+    ca-certificates \
+    ninja-build && \
+    rm -rf /var/lib/apt/lists/*
+
+RUN git clone --branch 2023.04.15 --depth=1 https://github.com/microsoft/vcpkg && \
+    /vcpkg/bootstrap-vcpkg.sh -disableMetrics && \
+    /vcpkg/vcpkg --disable-metrics install libvpx libyuv opus aom
+
+RUN groupadd -r user && \
+    useradd -r -g user user --home /home/user && \
+    mkdir -p /home/user/rustdesk && \
+    chown -R user: /home/user && \
+    echo "user ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/user
+
+WORKDIR /home/user
+RUN curl -LO https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.lnx/x64/libsciter-gtk.so
+
+USER user
+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh && \
+    chmod +x rustup.sh && \
+    ./rustup.sh -y
+
+USER root
+ENV HOME=/home/user
+COPY ./entrypoint.sh /
+ENTRYPOINT ["/entrypoint.sh"]

+ 0 - 6
README.md

@@ -19,12 +19,6 @@ export VCPKG_ROOT=$PWD/vcpkg
 vcpkg/vcpkg install libvpx:x64-windows-static libyuv:x64-windows-static opus:x64-windows-static aom:x64-windows-static
 vcpkg/vcpkg install libvpx:x64-windows-static libyuv:x64-windows-static opus:x64-windows-static aom:x64-windows-static
 
 
 
 
-git clone https://github.com/rustdesk/rustdesk
-cd rustdesk
-mkdir -p target/debug
-wget https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.win/x64/sciter.dll
-mv sciter.dll target/debug
-cargo run
 
 
 ```
 ```
 
 

+ 81 - 0
dev.md

@@ -0,0 +1,81 @@
+# dev
+
+## 构建开发容器
+
+.devcontainer\Dockerfile 
+```
+# 安装依赖
+RUN sudo apt update -y && sudo apt install -y g++ gcc git curl wget nasm yasm libgtk-3-dev clang libxcb-randr0-dev libxdo-dev libxfixes-dev libxcb-shape0-dev libxcb-xfixes0-dev libasound2-dev libpulse-dev cmake unzip zip sudo libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
+
+# 安装vcpkg
+RUN git clone https://github.com/microsoft/vcpkg 
+WORKDIR vcpkg
+RUN git checkout 2023.04.15
+RUN /vcpkg/bootstrap-vcpkg.sh -disableMetrics
+ENV VCPKG_ROOT=/vcpkg
+
+# 安装rust
+RUN wget https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.lnx/x64/libsciter-gtk.so
+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
+RUN chmod +x rustup.sh
+RUN $HOME/rustup.sh -y
+
+# 安装flutter 3.10.1
+RUN wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.10.1-stable.tar.xz
+RUN tar xf flutter_linux_3.10.1-stable.tar.xz && rm flutter_linux_3.10.1-stable.tar.xz
+ENV PATH="$PATH:$HOME/flutter/bin"
+
+```
+
+在 .devcontainer\devcontainer.json 配置镜像,并设置初始化脚本 .devcontainer\build.sh ,以及默认插件,默认执行:
+
+```
+build(){
+    pwd
+    $WORKDIR/entrypoint $1
+}
+```
+构建镜像较久,首次启动会很慢。
+
+配置国内镜像:
+```
+RUN sed -i "s/deb.debian.org/mirrors.163.com/g" /etc/apt/sources.list
+RUN sed -i "s/security.debian.org/mirrors.163.com/g" /etc/apt/sources.list
+
+RUN echo '[source.crates-io]' > ~/.cargo/config \
+ && echo 'registry = "https://github.com/rust-lang/crates.io-index"'  >> ~/.cargo/config \
+ && echo '# 替换成你偏好的镜像源'  >> ~/.cargo/config \
+ && echo "replace-with = 'sjtu'"  >> ~/.cargo/config \
+ && echo '# 上海交通大学'   >> ~/.cargo/config \
+ && echo '[source.sjtu]'   >> ~/.cargo/config \
+ && echo 'registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"'  >> ~/.cargo/config \
+ && echo '' >> ~/.cargo/config
+
+ENV http_proxy=http://host:port
+ENV https_proxy=http://host:port
+```
+
+构建镜像:
+```
+docker build -t "rustdesk-builder" . --build-arg http_proxy=http://host:port --build-arg https_proxy=http://host:port
+
+docker run --rm -it -v $PWD:/home/user/rustdesk -v rustdesk-git-cache:/home/user/.cargo/git -v rustdesk-registry-cache:/home/user/.cargo/registry -e PUID="$(id -u)" -e PGID="$(id -g)" rustdesk-builder
+
+# 运行
+./target/debug/rustdesk
+```
+
+
+## 构建本地开发环境
+
+依照dockerfile中参考,安装并构建:
+
+```
+git clone https://github.com/rustdesk/rustdesk
+cd rustdesk
+mkdir -p target/debug
+wget https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.win/x64/sciter.dll
+mv sciter.dll target/debug
+cargo run
+
+```

+ 36 - 0
entrypoint.sh

@@ -0,0 +1,36 @@
+#!/bin/sh
+
+cd "$HOME"/rustdesk || exit 1
+# shellcheck source=/dev/null
+. "$HOME"/.cargo/env
+
+argv=$*
+
+while test $# -gt 0; do
+  case "$1" in
+  --release)
+    mkdir -p target/release
+    test -f target/release/libsciter-gtk.so || cp "$HOME"/libsciter-gtk.so target/release/
+    release=1
+    shift
+    ;;
+  --target)
+    shift
+    if test $# -gt 0; then
+      rustup target add "$1"
+      shift
+    fi
+    ;;
+  *)
+    shift
+    ;;
+  esac
+done
+
+if [ -z $release ]; then
+  mkdir -p target/debug
+  test -f target/debug/libsciter-gtk.so || cp "$HOME"/libsciter-gtk.so target/debug/
+fi
+set -f
+#shellcheck disable=2086
+VCPKG_ROOT=/vcpkg cargo build $argv