From 99668d9c3e24775678dd6596f86aa39257ef3ee5 Mon Sep 17 00:00:00 2001 From: Winson Lee <100707097+Winson-030@users.noreply.github.com> Date: Sun, 3 Dec 2023 09:12:45 +0000 Subject: [PATCH] create a Dockerfile for Hysteria client image, with wiki in README.md --- docker/hysteria/README.md | 58 ++++++++++++++++++- .../hysteria/client/Dockerfile.architecture | 21 +++++++ docker/hysteria/client/build_hysteria.sh | 55 ++++++++++++++++++ docker/hysteria/{ => client}/client.yaml | 0 docker/hysteria/client/hysteria.sh | 51 ++++++++++++++++ 5 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 docker/hysteria/client/Dockerfile.architecture create mode 100644 docker/hysteria/client/build_hysteria.sh rename docker/hysteria/{ => client}/client.yaml (100%) create mode 100644 docker/hysteria/client/hysteria.sh diff --git a/docker/hysteria/README.md b/docker/hysteria/README.md index 75f2a6e8..86934427 100644 --- a/docker/hysteria/README.md +++ b/docker/hysteria/README.md @@ -24,13 +24,13 @@ It can be found at [Docker Hub][4]. You **must create a configuration file** `/etc/hysteria/server.yaml` in host at first: -``` +```bash $ mkdir -p /etc/hysteria ``` A sample in yaml like below: -``` +```yaml listen: :8998 tls: @@ -56,6 +56,60 @@ There is an example to start a container that listen on port `8998`, run as a Hy $ docker run -d -p 8998:8998 --name hysteria --restart=always -v /etc/hysteria:/etc/hysteria teddysun/hysteria ``` +## Start a container as Hysteria client with socks proxy + +## Pull the image + +```bash +$ docker pull teddysun/hysteria-client +``` + +You **must create a configuration file** `/etc/hysteria/client.yaml` in host at first: + +```bash +$ mkdir -p /etc/hysteria +``` + +A sample in yaml like below: + +```yaml +server: "IP:8998" +# server: "IP:8998,10000-20000" port hopping is availiable + +auth: your_password + +tls: + sni: www.example.com + # sni: www.bing.com + insecure: true + +#need expose socks proxy server port +socks5: + listen: 0.0.0.0:1080 + disableUDP: false + +transport: + udp: + hopInterval: 30s + +#optional +#lazy: true +#bandwidth: + #up: 150 mbps + #down: 150 mbps +# quic: +# initStreamReceiveWindow: 16777216 +# maxStreamReceiveWindow: 16777216 +# initConnReceiveWindow: 33554432 +# maxConnReceiveWindow: 33554432 +``` +There is an example to start a container that listen on port `1080`, run as a Hysteria client like below: + +```bash +$ docker run -d -p 1080:1080 --name hysteria-client --restart=always -v /etc/hysteria:/etc/hysteria teddysun/hysteria-client +``` +Then access socks server with `client_hostIP:1080` + **Warning**: The port number must be same as configuration and opened in firewall. [1]: https://github.com/apernet/hysteria diff --git a/docker/hysteria/client/Dockerfile.architecture b/docker/hysteria/client/Dockerfile.architecture new file mode 100644 index 00000000..f32a8f49 --- /dev/null +++ b/docker/hysteria/client/Dockerfile.architecture @@ -0,0 +1,21 @@ +# Dockerfile for hysteria client based alpine +# Copyright (C) 2023 Teddysun +# Reference URL: +# https://github.com/HyNetwork/hysteria + +FROM --platform=${TARGETPLATFORM} alpine:latest +LABEL maintainer="Teddysun " + +ARG TARGETPLATFORM +WORKDIR /root +COPY hysteria.sh /root/hysteria.sh +COPY client.yaml /etc/hysteria/client.yaml +RUN set -ex \ + && apk add --no-cache bash tzdata ca-certificates \ + && chmod +x /root/hysteria.sh \ + && /root/hysteria.sh "${TARGETPLATFORM}" \ + && rm -fv /root/hysteria.sh + +VOLUME /etc/hysteria +ENV TZ=Asia/Shanghai +CMD [ "/usr/bin/hysteria", "client", "-c", "/etc/hysteria/client.yaml" ] \ No newline at end of file diff --git a/docker/hysteria/client/build_hysteria.sh b/docker/hysteria/client/build_hysteria.sh new file mode 100644 index 00000000..216600b9 --- /dev/null +++ b/docker/hysteria/client/build_hysteria.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# +# This is a Shell script for build multi-architectures hysteria binary file +# +# Supported architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x +# +# Copyright (C) 2022 - 2023 Teddysun +# +# Reference URL: +# https://github.com/apernet/hysteria + +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} +echo "git clone https://github.com/apernet/hysteria.git" +git clone https://github.com/apernet/hysteria.git +cd hysteria || exit 2 + +APP_SRC_CMD_PKG="github.com/apernet/hysteria/app/cmd" +VERSION="$(git describe)" +COMMIT="$(git rev-parse HEAD)" +TIMESTAMP="$(date "+%F")" + +LDFLAGS="-s -w -X '${APP_SRC_CMD_PKG}.appVersion=${VERSION}' -X '${APP_SRC_CMD_PKG}.appCommit=${COMMIT}' -X '${APP_SRC_CMD_PKG}.appDate=${TIMESTAMP}' -X '${APP_SRC_CMD_PKG}.appType=release' -buildid=" +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 hysteria_linux_${ARCH}${V}" + env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GOARM=${V} go build -v -trimpath -ldflags "${LDFLAGS} -X '${APP_SRC_CMD_PKG}.appPlatform=linux' -X '${APP_SRC_CMD_PKG}.appArch=${ARCH}'" -o ${cur_dir}/hysteria_linux_${ARCH}${V} ./app || exit 1 + done + else + echo "Building hysteria_linux_${ARCH}" + env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -trimpath -ldflags "${LDFLAGS} -X '${APP_SRC_CMD_PKG}.appPlatform=linux' -X '${APP_SRC_CMD_PKG}.appArch=${ARCH}'" -o ${cur_dir}/hysteria_linux_${ARCH} ./app || exit 1 + fi +done + +ARCHS=( 386 amd64 ) +for ARCH in ${ARCHS[@]}; do + echo "Building hysteria_windows_${ARCH}.exe" + env CGO_ENABLED=0 GOOS=windows GOARCH=${ARCH} go build -v -trimpath -ldflags "${LDFLAGS} -X '${APP_SRC_CMD_PKG}.appPlatform=windows' -X '${APP_SRC_CMD_PKG}.appArch=${ARCH}'" -o ${cur_dir}/hysteria_windows_${ARCH}.exe ./app +done + +chmod +x ${cur_dir}/hysteria_* +# clean up +cd ${cur_dir} && rm -fr hysteria diff --git a/docker/hysteria/client.yaml b/docker/hysteria/client/client.yaml similarity index 100% rename from docker/hysteria/client.yaml rename to docker/hysteria/client/client.yaml diff --git a/docker/hysteria/client/hysteria.sh b/docker/hysteria/client/hysteria.sh new file mode 100644 index 00000000..47f7933c --- /dev/null +++ b/docker/hysteria/client/hysteria.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# +# This is a Shell script for hysteria based alpine with Docker image +# +# Copyright (C) 2022 Teddysun +# +# Reference URL: +# https://github.com/HyNetwork/hysteria + +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 +HYSTERIA_FILE="hysteria_linux_${ARCH}" + +echo "Downloading binary file: ${HYSTERIA_FILE}" +wget -O /usr/bin/hysteria https://dl.lamp.sh/files/${HYSTERIA_FILE} > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: Failed to download binary file: ${HYSTERIA_FILE}" && exit 1 +fi +echo "Download binary file: ${HYSTERIA_FILE} completed" +chmod +x /usr/bin/hysteria