From db5d1596544406b5c637fc9c3f29cf21f479c602 Mon Sep 17 00:00:00 2001 From: Teddysun Date: Mon, 9 Mar 2020 23:47:30 +0900 Subject: [PATCH] Added go-shadowsocks2 Docker Image --- .../go-shadowsocks2/Dockerfile.architecture | 28 +++++++++ docker/go-shadowsocks2/README.md | 60 +++++++++++++++++++ .../go-shadowsocks2/build_go-shadowsocks2.sh | 44 ++++++++++++++ docker/go-shadowsocks2/go-shadowsocks2.sh | 50 ++++++++++++++++ docker/go-shadowsocks2/v2ray-plugin.sh | 52 ++++++++++++++++ 5 files changed, 234 insertions(+) create mode 100644 docker/go-shadowsocks2/Dockerfile.architecture create mode 100644 docker/go-shadowsocks2/README.md create mode 100644 docker/go-shadowsocks2/build_go-shadowsocks2.sh create mode 100644 docker/go-shadowsocks2/go-shadowsocks2.sh create mode 100644 docker/go-shadowsocks2/v2ray-plugin.sh diff --git a/docker/go-shadowsocks2/Dockerfile.architecture b/docker/go-shadowsocks2/Dockerfile.architecture new file mode 100644 index 00000000..9918f387 --- /dev/null +++ b/docker/go-shadowsocks2/Dockerfile.architecture @@ -0,0 +1,28 @@ +# Dockerfile for go-shadowsocks2 based alpine +# Copyright (C) 2019 - 2020 Teddysun +# Reference URL: +# https://github.com/shadowsocks/go-shadowsocks2 + +FROM --platform=${TARGETPLATFORM} alpine:latest +LABEL maintainer="Teddysun " + +ARG TARGETPLATFORM +WORKDIR /root +COPY go-shadowsocks2.sh /root/go-shadowsocks2.sh +COPY v2ray-plugin.sh /root/v2ray-plugin.sh +RUN set -ex \ + && apk add --no-cache tzdata \ + && chmod +x /root/go-shadowsocks2.sh /root/v2ray-plugin.sh \ + && /root/go-shadowsocks2.sh "${TARGETPLATFORM}" \ + && /root/v2ray-plugin.sh "${TARGETPLATFORM}" \ + && rm -fv /root/go-shadowsocks2.sh /root/v2ray-plugin.sh + +ENV TZ=Asia/Shanghai +ENV SERVER_PORT=9000 +ENV METHOD=AEAD_CHACHA20_POLY1305 +ENV PASSWORD=teddysun.com +ENV ARGS= +CMD exec go-shadowsocks2 \ + -s "ss://${METHOD}:${PASSWORD}@:${SERVER_PORT}" \ + -verbose \ + ${ARGS} \ No newline at end of file diff --git a/docker/go-shadowsocks2/README.md b/docker/go-shadowsocks2/README.md new file mode 100644 index 00000000..2d4363fb --- /dev/null +++ b/docker/go-shadowsocks2/README.md @@ -0,0 +1,60 @@ +## Go-shadowsocks2 Docker Image by Teddysun + +[go-shadowsocks2][1] is a fresh implementation of Shadowsocks in Go which can help you get through firewalls. + +Based on alpine with latest version [go-shadowsocks2][1] and [v2ray-plugin][6]. + +Docker images are built for quick deployment in various computing cloud providers. + +For more information on docker and containerization technologies, refer to [official document][3]. + +## Prepare the host + +If you need to install docker by yourself, follow the [official installation guide][4]. + +## Pull the image + +```bash +$ docker pull teddysun/go-shadowsocks2 +``` + +This pulls the latest release of go-shadowsocks2. + +It can be found at [Docker Hub][5]. + +## Start a container + +You **must set environment variable** at first. + +- `SERVER_PORT`: Server listening on port, defaults to `9000`; +- `METHOD`: Encryption method to use, available ciphers: `AEAD_AES_128_GCM`, `AEAD_AES_256_GCM`, `AEAD_CHACHA20_POLY1305`, defaults to `AEAD_CHACHA20_POLY1305`; +- `PASSWORD`: Your own password, defaults to `teddysun.com`; +- `ARGS`: Additional arguments, for example: `-plugin v2ray-plugin -plugin-opts "server"`. For more `v2ray-plugin` configrations please visit v2ray-plugin [usage][7]. + +**1.** There is an example to start a container with default environment variables: + +```bash +$ docker run -d -p 9000:9000 -p 9000:9000/udp --name go-ss --restart=always teddysun/go-shadowsocks2 +``` + +**2.** There is an example to start a container that listen on port `8989`, using `AEAD_AES_256_GCM` AEAD cipher with password `password00`: + +```bash +$ docker run -d -p 8989:8989 -p 8989:8989/udp --name go-ss --restart=always -e SERVER_PORT=8989 -e METHOD=AEAD_AES_256_GCM -e PASSWORD=password00 teddysun/go-shadowsocks2 +``` + +**3.** There is an example to start a container that listen on port `8989`, using `AEAD_AES_256_GCM` AEAD cipher with password `password00` and supported SIP003 plugins: + +```bash +$ docker run -d -p 8989:8989 -p 8989:8989/udp --name go-ss --restart=always -e SERVER_PORT=8989 -e METHOD=AEAD_AES_256_GCM -e PASSWORD=password00 -e ARGS="-plugin v2ray-plugin -plugin-opts "server"" teddysun/go-shadowsocks2 +``` + +**Warning**: The port number must be opened in firewall. + +[1]: https://github.com/shadowsocks/go-shadowsocks2 +[2]: https://shadowsocks.org/en/index.html +[3]: https://docs.docker.com/ +[4]: https://docs.docker.com/install/ +[5]: https://hub.docker.com/r/teddysun/go-shadowsocks2/ +[6]: https://github.com/shadowsocks/v2ray-plugin +[7]: https://github.com/shadowsocks/v2ray-plugin#usage \ No newline at end of file diff --git a/docker/go-shadowsocks2/build_go-shadowsocks2.sh b/docker/go-shadowsocks2/build_go-shadowsocks2.sh new file mode 100644 index 00000000..a16d0cf0 --- /dev/null +++ b/docker/go-shadowsocks2/build_go-shadowsocks2.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# +# This is a Shell script for build multi-architectures go-shadowsocks2 binary file +# +# Supported architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x +# +# Copyright (C) 2020 Teddysun +# +# Reference URL: +# https://github.com/shadowsocks/go-shadowsocks2 + +cur_dir="$(pwd)" + +COMMANDS=( git go ) +for CMD in "${COMMANDS[@]}"; do + if [ ! "$(command -v "${CMD}")" ]; then + echo "${CMD} is not installed, please install it and try again" && exit 1 + fi +done + +cd ${cur_dir} +git clone https://github.com/shadowsocks/go-shadowsocks2.git +cd go-shadowsocks2 || exit 2 +go get -d -v + +LDFLAGS="-s -w" +ARCHS=( 386 amd64 arm arm64 ppc64le s390x ) +ARMS=( 6 7 ) + +for ARCH in ${ARCHS[@]}; do + if [ "${ARCH}" = "arm" ]; then + for V in ${ARMS[@]}; do + echo "Building go-shadowsocks2_linux_${ARCH}${V}" + env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GOARM=${V} go build -v -ldflags "${LDFLAGS}" -o ${cur_dir}/go-shadowsocks2_linux_${ARCH}${V} + done + else + echo "Building go-shadowsocks2_linux_${ARCH}" + env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -ldflags "${LDFLAGS}" -o ${cur_dir}/go-shadowsocks2_linux_${ARCH} + fi +done + +chmod +x ${cur_dir}/go-shadowsocks2_linux_* +# clean up +cd ${cur_dir} && rm -fr go-shadowsocks2 diff --git a/docker/go-shadowsocks2/go-shadowsocks2.sh b/docker/go-shadowsocks2/go-shadowsocks2.sh new file mode 100644 index 00000000..b726b645 --- /dev/null +++ b/docker/go-shadowsocks2/go-shadowsocks2.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# +# This is a Shell script for go-shadowsocks2 based alpine with Docker image +# +# Copyright (C) 2019 - 2020 Teddysun +# +# Reference URL: +# https://github.com/shadowsocks/go-shadowsocks2 + +PLATFORM=$1 +if [ -z "$PLATFORM" ]; then + ARCH="amd64" +else + case "$PLATFORM" in + linux/386) + ARCH="386" + ;; + linux/amd64) + ARCH="amd64" + ;; + linux/arm/v6) + ARCH="arm6" + ;; + linux/arm/v7) + ARCH="arm7" + ;; + linux/arm64|linux/arm64/v8) + ARCH="arm64" + ;; + linux/ppc64le) + ARCH="ppc64le" + ;; + linux/s390x) + ARCH="s390x" + ;; + *) + ARCH="" + ;; + esac +fi +[ -z "${ARCH}" ] && echo "Error: Not supported OS Architecture" && exit 1 +# Download binary file +GO_SHADOWSOCKS2_FILE="go-shadowsocks2_linux_${ARCH}" +echo "Downloading go-shadowsocks2 binary file: ${GO_SHADOWSOCKS2_FILE}" +wget -O /usr/bin/go-shadowsocks2 https://dl.lamp.sh/files/${GO_SHADOWSOCKS2_FILE} > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: Failed to download go-shadowsocks2 binary file: ${GO_SHADOWSOCKS2_FILE}" && exit 1 +fi +chmod +x /usr/bin/go-shadowsocks2 +echo "Download go-shadowsocks2 binary file: ${GO_SHADOWSOCKS2_FILE} completed" diff --git a/docker/go-shadowsocks2/v2ray-plugin.sh b/docker/go-shadowsocks2/v2ray-plugin.sh new file mode 100644 index 00000000..765f318a --- /dev/null +++ b/docker/go-shadowsocks2/v2ray-plugin.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# +# This is a Shell script for go-shadowsocks2 supported SIP003 plugins based alpine with Docker image +# +# Copyright (C) 2019 - 2020 Teddysun +# +# Reference URL: +# https://github.com/shadowsocks/shadowsocks-libev +# https://github.com/shadowsocks/simple-obfs +# https://github.com/shadowsocks/v2ray-plugin + +PLATFORM=$1 +if [ -z "$PLATFORM" ]; then + ARCH="amd64" +else + case "$PLATFORM" in + linux/386) + ARCH="386" + ;; + linux/amd64) + ARCH="amd64" + ;; + linux/arm/v6) + ARCH="arm6" + ;; + linux/arm/v7) + ARCH="arm7" + ;; + linux/arm64|linux/arm64/v8) + ARCH="arm64" + ;; + linux/ppc64le) + ARCH="ppc64le" + ;; + linux/s390x) + ARCH="s390x" + ;; + *) + ARCH="" + ;; + esac +fi +[ -z "${ARCH}" ] && echo "Error: Not supported OS Architecture" && exit 1 +# Download v2ray-plugin binary file +V2RAY_PLUGIN_FILE="v2ray-plugin_linux_${ARCH}" +echo "Downloading v2ray-plugin binary file: ${V2RAY_PLUGIN_FILE}" +wget -O /usr/bin/v2ray-plugin https://dl.lamp.sh/files/${V2RAY_PLUGIN_FILE} > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: Failed to download v2ray-plugin binary file: ${V2RAY_PLUGIN_FILE}" && exit 1 +fi +chmod +x /usr/bin/v2ray-plugin +echo "Download v2ray-plugin binary file: ${V2RAY_PLUGIN_FILE} completed"