From 961e786cc65e4a3a8333167c6557fcde968b2cd8 Mon Sep 17 00:00:00 2001 From: lyon Date: Sun, 28 May 2023 12:31:46 +0800 Subject: [PATCH] try to support frpc --- docker/Dockerfile | 17 ++++++++++++++++- docker/frpc.ini | 12 ++++++++++++ docker/run.sh | 44 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 docker/frpc.ini diff --git a/docker/Dockerfile b/docker/Dockerfile index f9022c32e..4fc28e1bb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -66,7 +66,7 @@ RUN git clone https://gitee.com/lyon1998/pikascript root/pikascript RUN cd /root/pikascript && git pull RUN apt-get install -y upx -RUN cd /root/pikascript/tools/pikaCompiler && sh build.sh +RUN cd /root/pikascript/tools/pikaCompiler && cargo build ADD .vimrc /root/.vimrc @@ -79,3 +79,18 @@ RUN apt-get install clangd -y RUN apt-get install libmbedtls-dev -y RUN pip install -r /root/pikascript/docker/requirements.txt RUN apt-get install clang-format -y + +# install frps +RUN cd /root && wget https://gitee.com/Lyon1998/pikapython/attach_files/1420660/download -O frp.tar.gz && \ + tar -xzvf frp.tar.gz && \ + mv frp_0.48.0_linux_amd64/frpc /usr/local/bin/frpc + +COPY frpc.ini /etc/frpc.ini +ARG FRPC_SERVER_ADDR +ARG FRPC_SERVER_PORT +ARG FRPC_REMOTE_PORT +ARG FRPC_TOKEN +RUN sed -i "s|%FRPC_SERVER_ADDR%|${FRPC_SERVER_ADDR}|" /etc/frpc.ini && \ + sed -i "s|%FRPC_SERVER_PORT%|${FRPC_SERVER_PORT}|" /etc/frpc.ini && \ + sed -i "s|%FRPC_REMOTE_PORT%|${FRPC_REMOTE_PORT}|" /etc/frpc.ini && \ + sed -i "s|%FRPC_TOKEN%|${FRPC_TOKEN}|" /etc/frpc.ini diff --git a/docker/frpc.ini b/docker/frpc.ini new file mode 100644 index 000000000..3e71b506c --- /dev/null +++ b/docker/frpc.ini @@ -0,0 +1,12 @@ +# 全局配置 +[common] +server_addr = %FRPC_SERVER_ADDR% +server_port = %FRPC_SERVER_PORT% +token = %FRPC_TOKEN% + +# SSH代理配置 +[ssh] +type = tcp +local_ip = 127.0.0.1 +local_port = 22 +remote_port = %FRPC_REMOTE_PORT% diff --git a/docker/run.sh b/docker/run.sh index 9a8c7d3ed..45edb757f 100644 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,9 +1,41 @@ +#!/bin/bash + DOCKER_NAME=pikadev docker rm $DOCKER_NAME -f -docker run -it --name $DOCKER_NAME \ ---restart always \ --p 8080:8080 \ --w /root/pikascript \ -$DOCKER_NAME \ -bash + +# 解析命令行参数 +while getopts ":p:s:t:r:" opt; do + case $opt in + p) frpc_port=$OPTARG;; + s) frpc_server_addr=$OPTARG;; + t) frpc_token=$OPTARG;; + r) frpc_remote_port=$OPTARG;; + \?) echo "Invalid option -$OPTARG" >&2;; + esac +done + +# 检查是否设置了frpc_port参数 +if [ -n "$frpc_port" ]; then + # 启动frpc + echo "Starting frpc..." + docker run -d --name $DOCKER_NAME \ + --restart always \ + -w /root/pikascript \ + -e FRPC_REMOTE_PORT=$frpc_remote_port \ + -e FRPC_SERVER_ADDR=$frpc_server_addr \ + -e FRPC_SERVER_PORT=$frpc_server_port \ + -e FRPC_TOKEN=$frpc_token \ + $DOCKER_NAME \ + /usr/local/bin/frpc -c /etc/frpc.ini + echo "frpc started." +else + # 不启动frpc + echo "frpc_port is not set. Skipping frpc startup." + docker run -it --name $DOCKER_NAME \ + --restart always \ + -w /root/pikascript \ + $DOCKER_NAME \ + bash +fi +