From 9577d9c925828afca0c0133c78dca41ff983e650 Mon Sep 17 00:00:00 2001 From: Paramtamtam Date: Sat, 11 Jul 2020 00:03:52 +0500 Subject: [PATCH] Basic repository files added --- .editorconfig | 12 +++++ .github/workflows/release.yml | 28 +++++++++++ .github/workflows/tests.yml | 52 ++++++++++++++++++++ .gitignore | 3 ++ CHANGELOG.md | 14 ++++++ Dockerfile | 54 ++++++++++++++++++++ LICENSE | 9 ++++ README.md | 93 +++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 63 ++++++++++++++++++++++++ 9 files changed, 328 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100755 docker-entrypoint.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b2afad8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.{yml, yaml, sh, conf}] +indent_size = 2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b8b9ffe --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: release + +on: + release: # Docs: + types: [published] + +jobs: + docker-image: + name: Build docker image + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Generate image tag value + run: echo "::set-env name=IMAGE_TAG::${GITHUB_REF##*/[vV]}" # `/refs/tags/v1.2.3` -> `1.2.3` + + - name: Make docker login + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_LOGIN }}" --password-stdin &> /dev/null + + - name: Build image + run: docker build --tag "tarampampam/3proxy:${IMAGE_TAG}" --tag "tarampampam/3proxy:latest" -f ./Dockerfile . + + - name: Push version image + run: docker push "tarampampam/3proxy:${IMAGE_TAG}" + + - name: Push latest image + run: docker push "tarampampam/3proxy:latest" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..fc42304 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,52 @@ +name: tests + +on: + push: + branches: + - master + tags-ignore: + - '**' + pull_request: + schedule: + - cron: '0 0 * * 0' # once in a week, docs: + +jobs: # Docs: + docker-image: + name: Build and use docker image + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Build docker image + run: docker build -f ./Dockerfile --tag image:local . + + - name: Run docker image with default settings + run: docker run --rm -d -p "3128:3128/tcp" -p "1080:1080/tcp" image:local + + - name: Pause + run: sleep 2 + + - name: Try to use HTTP proxy + run: curl -v --fail --proxy http://127.0.0.1:3128 --connect-timeout 3 --max-time 3 https://github.com/robots.txt + + - name: Try to use SOCKS proxy + run: curl -v --fail --proxy socks5://127.0.0.1:1080 --connect-timeout 3 --max-time 3 https://github.com/robots.txt + + - name: Stop container + run: docker stop $(docker ps -a --filter ancestor=image:local -q) + + - name: Run docker image with auth settings + run: docker run --rm -d -p "3128:3128/tcp" -p "1080:1080/tcp" -e "AUTH_REQUIRED=true" -e "PROXY_LOGIN=evil" -e "PROXY_PASSWORD=live" image:local + + - name: Pause + run: sleep 2 + + - name: Try to use HTTP proxy + run: curl -v --fail --proxy http://127.0.0.1:3128 --proxy-user evil:live --connect-timeout 3 --max-time 3 https://github.com/robots.txt + + - name: Try to use SOCKS proxy + run: curl -v --fail --proxy socks5://127.0.0.1:1080 --proxy-user evil:live --connect-timeout 3 --max-time 3 https://github.com/robots.txt + + - name: Stop container + run: docker stop $(docker ps -a --filter ancestor=image:local -q) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..763ca6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +## IDEs +/.vscode +/.idea diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1741942 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this package will be documented in this file. + +The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver]. + +## v0.1.0 + +### Changed + +- First project release + +[keepachangelog]:https://keepachangelog.com/en/1.0.0/ +[semver]:https://semver.org/spec/v2.0.0.html diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ab655f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +# Image page: +FROM alpine:latest as builder + +# e.g.: `docker build --build-arg "VERSION=0.8.13" .` +ARG VERSION="0.8.13" + +RUN set -x \ + && apk add --no-cache \ + ca-certificates \ + linux-headers \ + build-base \ + git \ + && update-ca-certificates \ + && git clone --branch ${VERSION} https://github.com/z3APA3A/3proxy.git /tmp/3proxy \ + && cd /tmp/3proxy \ + && echo '#define ANONYMOUS 1' >> /tmp/3proxy/src/3proxy.h \ + && make -f Makefile.Linux + +FROM alpine:latest + +LABEL \ + org.label-schema.name="3proxy" \ + org.label-schema.description="Tiny free proxy server" \ + org.label-schema.url="https://github.com/tarampampam/3proxy-docker" \ + org.label-schema.vcs-url="https://github.com/tarampampam/3proxy-docker" \ + org.label-schema.docker.cmd="docker run --rm -d -p \"3128:3128/tcp\" -p \"1080:1080/tcp\" this_image" \ + org.label-schema.vendor="tarampampam" \ + org.label-schema.license="WTFPL" \ + org.label-schema.schema-version="1.0" + +COPY docker-entrypoint.sh /docker-entrypoint.sh +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /tmp/3proxy/src/3proxy /usr/bin/3proxy +COPY --from=builder /tmp/3proxy/cfg/3proxy.cfg.sample /etc/3proxy/3proxy.cfg + +RUN set -x \ + # Unprivileged user creation + && adduser \ + --disabled-password \ + --gecos "" \ + --home /nonexistent \ + --shell /sbin/nologin \ + --no-create-home \ + --uid 10001 \ + 3proxy \ + && touch /etc/3proxy/passwd \ + && chown 3proxy:3proxy -R /etc/3proxy + +# Use an unprivileged user +USER 3proxy:3proxy + +ENTRYPOINT ["/docker-entrypoint.sh"] + +CMD ["/usr/bin/3proxy", "/etc/3proxy/3proxy.cfg"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a51c2e7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +Copyright (C) tarampampam + +Everyone is permitted to copy and distribute verbatim or modified copies of this license +document, and changing it is allowed as long as the name is changed. + +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, +DISTRIBUTION AND MODIFICATION + +0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..40540c8 --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +

+ +

+ +# Docker image with [3proxy][link_3proxy] + +[![Build Status][badge_build_status]][link_build_status] +[![Release Status][badge_release_status]][link_build_status] +[![Image size][badge_size_latest]][link_docker_hub] +[![Docker Pulls][badge_docker_pulls]][link_docker_hub] +[![License][badge_license]][link_license] + +## Why this image created? + +3proxy is awesome and lightweight proxy-server. This image contains stable version with it and can be configured using environment variables. + +> Page on `hub.docker.com` can be [found here][link_docker_hub]. + +## Supported tags + +[![image stats](https://dockeri.co/image/tarampampam/3proxy)][link_docker_tags] + +All supported image tags [can be found here][link_docker_tags]. + +## Supported environment variables + +Variable name | Description | Example +---------------- | ----------------------------------------- | --------------- +`AUTH_REQUIRED` | Require authorization? (default: `false`) | `true`, `false` +`PROXY_LOGIN` | Authorization login | `username` +`PROXY_PASSWORD` | Authorization password | `password` + +## How can I use this? + +For example: + +```bash +$ docker run --rm -d \ + -p "3128:3128/tcp" \ + -p "1080:1080/tcp" \ + tarampampam/3proxy:latest +``` + +Or with auth settings: + +```bash +$ docker run --rm -d \ + -e "AUTH_REQUIRED=true" \ + -e "PROXY_LOGIN=evil" \ + -e "PROXY_PASSWORD=live" \ + -p "3128:3128/tcp" \ + -p "1080:1080/tcp" \ + tarampampam/3proxy:latest +``` + +## Changes log + +[![Release date][badge_release_date]][link_releases] +[![Commits since latest release][badge_commits_since_release]][link_commits] + +Changes log can be [found here][link_changes_log]. + +## Support + +[![Issues][badge_issues]][link_issues] +[![Issues][badge_pulls]][link_pulls] + +If you will find any package errors, please, [make an issue][link_create_issue] in current repository. + +## License + +WTFPL. Use anywhere for your pleasure. + +[badge_build_status]:https://img.shields.io/github/workflow/status/tarampampam/3proxy-docker/tests/master?logo=github&label=build +[badge_release_status]:https://img.shields.io/github/workflow/status/tarampampam/3proxy-docker/release/master?logo=github&label=release +[badge_release_date]:https://img.shields.io/github/release-date/tarampampam/3proxy-docker.svg?style=flat-square&maxAge=180 +[badge_commits_since_release]:https://img.shields.io/github/commits-since/tarampampam/3proxy-docker/latest.svg?style=flat-square&maxAge=180 +[badge_issues]:https://img.shields.io/github/issues/tarampampam/3proxy-docker.svg?style=flat-square&maxAge=180 +[badge_pulls]:https://img.shields.io/github/issues-pr/tarampampam/3proxy-docker.svg?style=flat-square&maxAge=180 +[badge_license]:https://img.shields.io/github/license/tarampampam/3proxy-docker.svg?longCache=true +[badge_size_latest]:https://img.shields.io/docker/image-size/tarampampam/3proxy/latest?maxAge=30 +[badge_docker_pulls]:https://img.shields.io/docker/pulls/tarampampam/3proxy.svg +[link_releases]:https://github.com/tarampampam/3proxy-docker/releases +[link_commits]:https://github.com/tarampampam/3proxy-docker/commits +[link_changes_log]:https://github.com/tarampampam/3proxy-docker/blob/master/CHANGELOG.md +[link_issues]:https://github.com/tarampampam/3proxy-docker/issues +[link_pulls]:https://github.com/tarampampam/3proxy-docker/pulls +[link_build_status]:https://travis-ci.org/tarampampam/3proxy-docker +[link_create_issue]:https://github.com/tarampampam/3proxy-docker/issues/new +[link_license]:https://github.com/tarampampam/3proxy-docker/blob/master/LICENSE +[link_docker_tags]:https://hub.docker.com/r/tarampampam/3proxy/tags +[link_docker_hub]:https://hub.docker.com/r/tarampampam/3proxy/ +[link_3proxy]:https://github.com/z3APA3A/3proxy diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..e5d1346 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env sh +set -e + +AUTH_REQUIRED=${AUTH_REQUIRED:-false} # true|false +PROXY_LOGIN=${PROXY_LOGIN:-} # string +PROXY_PASSWORD=${PROXY_PASSWORD:-} # string + +if [ "$AUTH_REQUIRED" = "true" ]; then + if [ -z "$PROXY_LOGIN" ]; then + (>&2 echo "$0: environment variable 'PROXY_LOGIN' is not specified!"); exit 1; + fi; + + if [ -z "$PROXY_PASSWORD" ]; then + (>&2 echo "$0: environment variable 'PROXY_PASSWORD' is not specified!"); exit 1; + fi; + + echo "$0: setup '${PROXY_LOGIN}:${PROXY_PASSWORD}' as proxy user"; + echo "${PROXY_LOGIN}:CL:${PROXY_PASSWORD}" > /etc/3proxy/passwd +fi; + +echo "$0: rewrite configuration file"; +cat << \EOF > /etc/3proxy/3proxy.cfg +#!/usr/bin/3proxy +config /etc/3proxy/3proxy.cfg + +# you may use system to execute some external command if proxy starts +system "echo `which 3proxy`': Starting 3proxy'" + +# We can configure nservers to avoid unsafe gethostbyname() usage +nserver 1.0.0.1 +nserver 1.1.1.1 +nserver 8.8.4.4 +nserver 8.8.8.8 + +# nscache is good to save speed, traffic and bandwidth +nscache 65536 + +# Here we can change timeout values +timeouts 1 5 30 60 180 1800 15 60 + +# Include passwd file. For included files and are treated as field separators +users $/etc/3proxy/passwd + +log /dev/stdout +logformat "- +_L%t.%. %N.%p %E %U %C:%c %R:%r %O %I %h %T" + +maxconn 1024 + +#AUTH_SETTINGS + +proxy -a -p3128 +socks -a -p1080 + +flush +EOF + +if [ "$AUTH_REQUIRED" = "true" ]; then + echo "$0: setup auth settings in configuration file"; + + sed -i "s~#AUTH_SETTINGS~auth strong\nallow ${PROXY_LOGIN}~" /etc/3proxy/3proxy.cfg +fi; + +exec "$@"