Skip to content

Commit

Permalink
Merge pull request Snawoot#1 from Snawoot/new_cfg_templater
Browse files Browse the repository at this point in the history
Build and startup improvements
  • Loading branch information
Snawoot authored May 6, 2021
2 parents 83da15b + b32840c commit 89108bf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 92 deletions.
26 changes: 18 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
FROM debian:sid

RUN set -ex\
&& apt update -y \
&& apt upgrade -y \
&& apt install -y wget unzip qrencode\
&& apt install -y shadowsocks-libev\
&& apt install -y nginx\
&& apt autoremove -y
ARG V2RAY_VERSION=v1.3.1

COPY wwwroot.tar.gz /wwwroot/wwwroot.tar.gz
COPY conf/ /conf
COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh
ARG DEBIAN_FRONTEND=noninteractive
RUN set -ex\
&& apt update -y \
&& apt upgrade -y \
&& apt install -y wget unzip qrencode \
&& apt install -y shadowsocks-libev \
&& apt install -y nginx-light \
&& apt autoremove -y \
&& apt clean -y \
&& tar xvf /wwwroot/wwwroot.tar.gz -C /wwwroot \
&& rm -rf /wwwroot/wwwroot.tar.gz \
&& chmod +x /entrypoint.sh \
&& mkdir -p /etc/shadowsocks-libev /v2raybin \
&& wget -O- "https://github.com/shadowsocks/v2ray-plugin/releases/download/${V2RAY_VERSION}/v2ray-plugin-linux-amd64-${V2RAY_VERSION}.tar.gz" | \
tar zx -C /v2raybin \
&& install /v2raybin/v2ray-plugin_linux_amd64 /usr/bin/v2ray-plugin \
&& rm -rf /v2raybin

CMD /entrypoint.sh
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ windows:

<https://github.com/shadowsocks/shadowsocks-windows/wiki/Shadowsocks-Windows-%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E>

## 3. Update

To update the v2ray-plugin version, visit <https://dashboard.heroku.com/apps> and select the deployed app. If the VER variable is latest, directly select More --> Restart all dynos, the program will restart automatically and the progress can be confirmed through view Logs.

(Update the specified version: Settings --> Reveal Config Varsapp -->VER, modify to the required version number, such as 1.2)

2020/03/01 The current version is working normally:

+ shadowsocks-libev: 3.3.4+ds-2(debian apt)

+ v2ray-plugin: v1.3.0

# Reference

https://github.com/ygcaicn/ss-heroku
Expand Down
5 changes: 0 additions & 5 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
"value": "5c301bb8-6c77-41a0-a606-4ba11bbab084"
},

"VER": {
"description": "v2ray-plugin version, the latest version is installed by default, you can go to https://github.com/shadowsocks/v2ray-plugin/releasesV2Ray to select the version (for example: 1.1.0)",
"value": "latest"
},

"V2_Path": {
"description": "Path path, default /s233, you can also replace s233 with uuid for safety, / cannot be less. If anti-generation is turned on, do not repeat with anti-generation uri",
"value": "/s233"
Expand Down
24 changes: 17 additions & 7 deletions conf/nginx_ss.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The content of the top grid comment will be removed during sed processing and will not appear in the final configuration file

#!/bin/bash
cat <<EOF
server {
listen ${PORT};
listen [::]:${PORT};
Expand All @@ -8,23 +8,33 @@ server {
resolver 8.8.8.8:53;
location / {
EOF

if [[ "${ProxySite}" ]]; then
cat << EOF
proxy_pass https://${ProxySite};
EOF
>&2 echo "site:use local wwwroot html"
fi

cat <<EOF
}
location ${QR_Path} {
root /wwwroot;
}
location = ${V2_Path} {
if ($http_upgrade != "websocket") { # WebSocket return this when negotiation fails 404
if (\$http_upgrade != "websocket") { # WebSocket return this when negotiation fails 404
return 404;
}
proxy_redirect off;
proxy_pass http://127.0.0.1:2333;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header Host \$http_host;
# Show real IP in v2ray access.log
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF
6 changes: 4 additions & 2 deletions conf/shadowsocks-libev_config.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# The content of the top grid comment will be removed during sed processing and will not appear in the final configuration file
#!/bin/bash
# Fast_open must be false on heroku
cat <<EOF
{
"server":"127.0.0.1",
"server_port":"2333",
"password":"${PASSWORD}",
"timeout":300,
"method":"${ENCRYPT}",
"mode": "tcp_and_udp",
"mode": "tcp_only",
"fast_open":false,
"reuse_port":true,
"no_delay":true,
"plugin": "v2ray-plugin",
"plugin_opts":"server;path=${V2_Path}"
}
EOF
65 changes: 7 additions & 58 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,86 +1,35 @@
#!/bin/bash

#v2ray-plugin版本
if [[ -z "${VER}" ]]; then
VER="latest"
fi
echo ${VER}

if [[ -z "${PASSWORD}" ]]; then
PASSWORD="5c301bb8-6c77-41a0-a606-4ba11bbab084"
export PASSWORD="5c301bb8-6c77-41a0-a606-4ba11bbab084"
fi
echo ${PASSWORD}

if [[ -z "${ENCRYPT}" ]]; then
ENCRYPT="chacha20-ietf-poly1305"
export ENCRYPT="chacha20-ietf-poly1305"
fi


if [[ -z "${V2_Path}" ]]; then
V2_Path="/s233"
export V2_Path="/s233"
fi
echo ${V2_Path}

if [[ -z "${QR_Path}" ]]; then
QR_Path="/qr_img"
export QR_Path="/qr_img"
fi
echo ${QR_Path}


if [ "$VER" = "latest" ]; then
V_VER=`wget -qO- "https://api.github.com/repos/shadowsocks/v2ray-plugin/releases/latest" | sed -n -r -e 's/.*"tag_name".+?"([vV0-9\.]+?)".*/\1/p'`
[[ -z "${V_VER}" ]] && V_VER="v1.3.0"
else
V_VER="v$VER"
fi

mkdir /v2raybin
cd /v2raybin
V2RAY_URL="https://github.com/shadowsocks/v2ray-plugin/releases/download/${V_VER}/v2ray-plugin-linux-amd64-${V_VER}.tar.gz"
echo ${V2RAY_URL}
wget --no-check-certificate ${V2RAY_URL}
tar -zxvf v2ray-plugin-linux-amd64-$V_VER.tar.gz
rm -rf v2ray-plugin-linux-amd64-$V_VER.tar.gz
mv v2ray-plugin_linux_amd64 /usr/bin/v2ray-plugin
rm -rf /v2raybin

cd /wwwroot
tar xvf wwwroot.tar.gz
rm -rf wwwroot.tar.gz

if [ ! -d /etc/shadowsocks-libev ]; then
mkdir /etc/shadowsocks-libev
fi

# TODO: bug when PASSWORD contain '/'
sed -e "/^#/d"\
-e "s/\${PASSWORD}/${PASSWORD}/g"\
-e "s/\${ENCRYPT}/${ENCRYPT}/g"\
-e "s|\${V2_Path}|${V2_Path}|g"\
/conf/shadowsocks-libev_config.json > /etc/shadowsocks-libev/config.json
bash /conf/shadowsocks-libev_config.json > /etc/shadowsocks-libev/config.json
echo /etc/shadowsocks-libev/config.json
cat /etc/shadowsocks-libev/config.json

if [[ -z "${ProxySite}" ]]; then
s="s/proxy_pass/#proxy_pass/g"
echo "site:use local wwwroot html"
else
s="s|\${ProxySite}|${ProxySite}|g"
echo "site: ${ProxySite}"
fi

sed -e "/^#/d"\
-e "s/\${PORT}/${PORT}/g"\
-e "s|\${V2_Path}|${V2_Path}|g"\
-e "s|\${QR_Path}|${QR_Path}|g"\
-e "$s"\
/conf/nginx_ss.conf > /etc/nginx/conf.d/ss.conf
bash /conf/nginx_ss.conf > /etc/nginx/conf.d/ss.conf
echo /etc/nginx/conf.d/ss.conf
cat /etc/nginx/conf.d/ss.conf


if [ "$AppName" = "no" ]; then
echo "不生成二维码"
echo "Do not generate QR-code"
else
[ ! -d /wwwroot/${QR_Path} ] && mkdir /wwwroot/${QR_Path}
plugin=$(echo -n "v2ray;path=${V2_Path};host=${AppName}.herokuapp.com;tls" | sed -e 's/\//%2F/g' -e 's/=/%3D/g' -e 's/;/%3B/g')
Expand Down

0 comments on commit 89108bf

Please sign in to comment.