Skip to content

Commit

Permalink
Added shadowsocks-rust Docker Image
Browse files Browse the repository at this point in the history
  • Loading branch information
teddysun committed Nov 3, 2020
1 parent 3ad8172 commit 597f64e
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 0 deletions.
59 changes: 59 additions & 0 deletions docker/shadowsocks-rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Dockerfile for shadowsocks-rust based alpine
# Copyright (C) 2020 Teddysun <[email protected]>
# Reference URL:
# https://github.com/shadowsocks/shadowsocks-rust
# https://github.com/shadowsocks/simple-obfs
# https://github.com/shadowsocks/v2ray-plugin

FROM alpine:edge AS builder

RUN set -ex \
&& runDeps="git build-base c-ares-dev autoconf automake libev-dev libtool libsodium-dev linux-headers mbedtls-dev pcre-dev openssl-dev cargo" \
&& apk add --no-cache --virtual .build-deps ${runDeps} \
&& mkdir -p /root/obfs \
&& cd /root/obfs \
&& git clone --depth=1 https://github.com/shadowsocks/simple-obfs.git . \
&& git submodule update --init --recursive \
&& ./autogen.sh \
&& ./configure --prefix=/root --disable-documentation \
&& make install \
&& mkdir -p /root/rust \
&& cd /root/rust \
&& VERSION=$(wget --no-check-certificate -qO- https://api.github.com/repos/shadowsocks/shadowsocks-rust/releases/latest | grep 'tag_name' | cut -d\" -f4) \
&& git clone -b ${VERSION} --depth=1 https://github.com/shadowsocks/shadowsocks-rust.git . \
&& cargo build --release --features "aes-pmac-siv local-redir" \
&& cp -pv target/release/sslocal /root/bin \
&& cp -pv target/release/ssmanager /root/bin \
&& cp -pv target/release/ssserver /root/bin \
&& cp -pv target/release/ssurl /root/bin

FROM alpine:latest
LABEL maintainer="Teddysun <[email protected]>"

COPY --from=builder /root/bin/obfs-local /usr/bin/
COPY --from=builder /root/bin/obfs-server /usr/bin/
COPY --from=builder /root/bin/sslocal /usr/bin/
COPY --from=builder /root/bin/ssmanager /usr/bin/
COPY --from=builder /root/bin/ssserver /usr/bin/
COPY --from=builder /root/bin/ssurl /usr/bin/
COPY v2ray-plugin.sh /root/v2ray-plugin.sh
COPY config_sample.json /etc/shadowsocks-rust/config.json

WORKDIR /root
RUN set -ex \
&& apk add --no-cache \
tzdata \
rng-tools \
ca-certificates \
libgcc \
$(scanelf --needed --nobanner /usr/bin/ss* \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| xargs -r apk info --installed \
| sort -u) \
&& chmod +x /root/v2ray-plugin.sh \
&& /root/v2ray-plugin.sh \
&& rm -f /root/v2ray-plugin.sh

VOLUME /etc/shadowsocks-rust
ENV TZ=Asia/Shanghai
CMD [ "/usr/bin/ssserver", "-c", "/etc/shadowsocks-rust/config.json" ]
60 changes: 60 additions & 0 deletions docker/shadowsocks-rust/Dockerfile.architecture
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Dockerfile for shadowsocks-rust based alpine
# Copyright (C) 2020 Teddysun <[email protected]>
# Reference URL:
# https://github.com/shadowsocks/shadowsocks-rust
# https://github.com/shadowsocks/simple-obfs
# https://github.com/shadowsocks/v2ray-plugin

FROM --platform=${TARGETPLATFORM} alpine:edge AS builder

RUN set -ex \
&& runDeps="git build-base c-ares-dev autoconf automake libev-dev libtool libsodium-dev linux-headers mbedtls-dev pcre-dev openssl-dev cargo" \
&& apk add --no-cache --virtual .build-deps ${runDeps} \
&& mkdir -p /root/obfs \
&& cd /root/obfs \
&& git clone --depth=1 https://github.com/shadowsocks/simple-obfs.git . \
&& git submodule update --init --recursive \
&& ./autogen.sh \
&& ./configure --prefix=/root --disable-documentation \
&& make install \
&& mkdir -p /root/rust \
&& cd /root/rust \
&& VERSION=$(wget --no-check-certificate -qO- https://api.github.com/repos/shadowsocks/shadowsocks-rust/releases/latest | grep 'tag_name' | cut -d\" -f4) \
&& git clone -b ${VERSION} --depth=1 https://github.com/shadowsocks/shadowsocks-rust.git . \
&& cargo build --release --features "aes-pmac-siv local-redir" \
&& cp -pv target/release/sslocal /root/bin \
&& cp -pv target/release/ssmanager /root/bin \
&& cp -pv target/release/ssserver /root/bin \
&& cp -pv target/release/ssurl /root/bin

FROM --platform=${TARGETPLATFORM} alpine:latest
LABEL maintainer="Teddysun <[email protected]>"

COPY --from=builder /root/bin/obfs-local /usr/bin/
COPY --from=builder /root/bin/obfs-server /usr/bin/
COPY --from=builder /root/bin/sslocal /usr/bin/
COPY --from=builder /root/bin/ssmanager /usr/bin/
COPY --from=builder /root/bin/ssserver /usr/bin/
COPY --from=builder /root/bin/ssurl /usr/bin/
COPY v2ray-plugin.sh /root/v2ray-plugin.sh
COPY config_sample.json /etc/shadowsocks-rust/config.json

ARG TARGETPLATFORM
WORKDIR /root
RUN set -ex \
&& apk add --no-cache \
tzdata \
rng-tools \
ca-certificates \
libgcc \
$(scanelf --needed --nobanner /usr/bin/ss* \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| xargs -r apk info --installed \
| sort -u) \
&& chmod +x /root/v2ray-plugin.sh \
&& /root/v2ray-plugin.sh "${TARGETPLATFORM}" \
&& rm -f /root/v2ray-plugin.sh

VOLUME /etc/shadowsocks-rust
ENV TZ=Asia/Shanghai
CMD [ "/usr/bin/ssserver", "-c", "/etc/shadowsocks-rust/config.json" ]
103 changes: 103 additions & 0 deletions docker/shadowsocks-rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
## Shadowsocks-rust Docker Image by Teddysun

![Shadowsocks](https://github.com/teddysun/shadowsocks_install/raw/master/shadowsocks.png)

[shadowsocks-rust][1] is a fast tunnel proxy that helps you bypass firewalls.

It is a port of [shadowsocks][2] created by @zonyitoo.

Based on alpine with latest version [shadowsocks-libev](https://github.com/shadowsocks/shadowsocks-libev) and [simple-obfs](https://github.com/shadowsocks/simple-obfs) and [v2ray-plugin](https://github.com/teddysun/v2ray-plugin) ( based [v2ray-core](https://github.com/v2fly/v2ray-core) v4.32.0 ).

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/shadowsocks-rust
```

This pulls the latest release of shadowsocks-rust.

It can be found at [Docker Hub][5].

## Start a container

You **must create a configuration file** `/etc/shadowsocks-rust/config.json` in host at first:

```
$ mkdir -p /etc/shadowsocks-rust
```

A sample in JSON like below:

```
{
"server":"0.0.0.0",
"server_port":9000,
"password":"password0",
"timeout":300,
"method":"aes-256-gcm",
"fast_open":true,
"nameserver":"8.8.8.8",
"mode":"tcp_and_udp"
}
```

If you want to enable **simple-obfs**, a sample in JSON like below:

```
{
"server":"0.0.0.0",
"server_port":9000,
"password":"password0",
"timeout":300,
"method":"aes-256-gcm",
"fast_open":true,
"nameserver":"8.8.8.8",
"mode":"tcp_and_udp",
"plugin":"obfs-server",
"plugin_opts":"obfs=tls"
}
```

If you want to enable **v2ray-plugin**, a sample in JSON like below:

```
{
"server":"0.0.0.0",
"server_port":9000,
"password":"password0",
"timeout":300,
"method":"aes-256-gcm",
"fast_open":true,
"nameserver":"8.8.8.8",
"mode":"tcp_and_udp",
"plugin":"v2ray-plugin",
"plugin_opts":"server"
}
```

For more v2ray-plugin configrations please visit [v2ray-plugin usage][6].

This container with sample configuration `/etc/shadowsocks-rust/config.json`

There is an example to start a container that listens on `9000` (both TCP and UDP):

```bash
$ docker run -d -p 9000:9000 -p 9000:9000/udp --name ss-rust --restart=always -v /etc/shadowsocks-rust:/etc/shadowsocks-rust teddysun/shadowsocks-rust
```

**Warning**: The port number must be same as configuration and opened in firewall.

[1]: https://github.com/shadowsocks/shadowsocks-rust
[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/shadowsocks-rust/
[6]: https://github.com/shadowsocks/v2ray-plugin#usage
44 changes: 44 additions & 0 deletions docker/shadowsocks-rust/build_v2ray-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh
#
# This is a Shell script for build multi-architectures v2ray-plugin binary file
#
# Supported architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
#
# Copyright (C) 2020 Teddysun <[email protected]>
#
# Reference URL:
# https://github.com/shadowsocks/v2ray-plugin

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/v2ray-plugin.git
cd v2ray-plugin || exit 2

VERSION="$(git describe --tags)"
LDFLAGS="-X main.VERSION=$VERSION -s -w"
GCFLAGS=""
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 v2ray-plugin_linux_${ARCH}${V}"
env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GOARM=${V} go build -v -ldflags "${LDFLAGS}" -gcflags "${GCFLAGS}" -o ${cur_dir}/v2ray-plugin_linux_${ARCH}${V}
done
else
echo "Building v2ray-plugin_linux_${ARCH}"
env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -ldflags "${LDFLAGS}" -gcflags "${GCFLAGS}" -o ${cur_dir}/v2ray-plugin_linux_${ARCH}
fi
done

# clean up
cd ${cur_dir} && rm -fr v2ray-plugin
10 changes: 10 additions & 0 deletions docker/shadowsocks-rust/config_sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"server":"0.0.0.0",
"server_port":9000,
"password":"password0",
"timeout":300,
"method":"aes-256-gcm",
"fast_open":true,
"nameserver":"8.8.8.8",
"mode":"tcp_and_udp"
}
52 changes: 52 additions & 0 deletions docker/shadowsocks-rust/v2ray-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
#
# This is a Shell script for shadowsocks-libev based alpine with Docker image
#
# Copyright (C) 2019 - 2020 Teddysun <[email protected]>
#
# 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"

0 comments on commit 597f64e

Please sign in to comment.