|
1 | 1 | # Image page: <https://hub.docker.com/_/alpine>
|
2 |
| -FROM alpine:latest as builder |
| 2 | +FROM gcc:9.3 as builder |
3 | 3 |
|
4 |
| -# e.g.: `docker build --build-arg "VERSION=0.8.13" .` |
5 |
| -ARG VERSION="0.8.13" |
| 4 | +# e.g.: `docker build --build-arg "VERSION=0.9.3" .` |
| 5 | +ARG VERSION="0.9.3" |
6 | 6 |
|
| 7 | +# Fetch 3proxy sources |
7 | 8 | RUN set -x \
|
8 |
| - && apk add --no-cache \ |
9 |
| - linux-headers \ |
10 |
| - build-base \ |
11 |
| - git \ |
12 |
| - && git clone --branch ${VERSION} https://github.com/z3APA3A/3proxy.git /tmp/3proxy \ |
13 |
| - && cd /tmp/3proxy \ |
14 |
| - && echo '#define ANONYMOUS 1' >> /tmp/3proxy/src/3proxy.h \ |
| 9 | + && git clone --branch "${VERSION}" https://github.com/z3APA3A/3proxy.git /tmp/3proxy |
| 10 | + |
| 11 | +WORKDIR /tmp/3proxy |
| 12 | + |
| 13 | +# Patch sources |
| 14 | +RUN set -x \ |
| 15 | + && echo '#define ANONYMOUS 1' >> ./src/3proxy.h \ |
| 16 | + # proxy.c source: <https://github.com/z3APA3A/3proxy/blob/0.9.3/src/proxy.c> |
15 | 17 | && sed -i 's~\(<\/head>\)~<style>html,body{background-color:#222526;color:#fff;font-family:sans-serif;\
|
16 | 18 | text-align:center;display:flex;flex-direction:column;justify-content:center}h1,h2{margin-bottom:0;font-size:2.5em}\
|
17 | 19 | h2::before{content:'"'"'Proxy error'"'"';display:block;font-size:0.4em;color:#bbb;font-weight:100}\
|
18 |
| -h3,p{color:#bbb}</style>\1~' /tmp/3proxy/src/proxy.c \ |
19 |
| - && cat ./src/proxy.c | grep '</head>' \ |
20 |
| - && make -f Makefile.Linux |
| 20 | +h3,p{color:#bbb}</style>\1~' ./src/proxy.c \ |
| 21 | + && cat ./src/proxy.c | grep '</head>' |
21 | 22 |
|
22 |
| -FROM alpine:latest |
| 23 | +# And compile |
| 24 | +RUN set -x \ |
| 25 | + && echo "" >> ./Makefile.Linux \ |
| 26 | + && echo "PLUGINS = StringsPlugin TrafficPlugin PCREPlugin TransparentPlugin SSLPlugin" >> ./Makefile.Linux \ |
| 27 | + && echo "LIBS = -l:libcrypto.a -l:libssl.a -ldl" >> ./Makefile.Linux \ |
| 28 | + && make -f Makefile.Linux \ |
| 29 | + && strip ./bin/3proxy \ |
| 30 | + && strip ./bin/StringsPlugin.ld.so \ |
| 31 | + && strip ./bin/TrafficPlugin.ld.so \ |
| 32 | + && strip ./bin/PCREPlugin.ld.so \ |
| 33 | + && strip ./bin/TransparentPlugin.ld.so \ |
| 34 | + && strip ./bin/SSLPlugin.ld.so |
23 | 35 |
|
24 |
| -# e.g.: `docker build --build-arg "BUILD_DATE=`date -u +'%Y-%m-%dT%H:%M:%SZ'`" .` |
25 |
| -ARG BUILD_DATE |
| 36 | +# Prepare filesystem for 3proxy running |
| 37 | +FROM busybox:1.32-glibc as buffer |
26 | 38 |
|
27 |
| -LABEL \ |
28 |
| - org.label-schema.name="3proxy" \ |
29 |
| - org.label-schema.description="Tiny free proxy server" \ |
30 |
| - org.label-schema.url="https://github.com/tarampampam/3proxy-docker" \ |
31 |
| - org.label-schema.vcs-url="https://github.com/tarampampam/3proxy-docker" \ |
32 |
| - org.label-schema.docker.cmd="docker run --rm -d -p \"3128:3128/tcp\" -p \"1080:1080/tcp\" this_image" \ |
33 |
| - org.label-schema.vendor="tarampampam" \ |
34 |
| - org.label-schema.build-date="$BUILD_DATE" \ |
35 |
| - org.label-schema.license="WTFPL" \ |
36 |
| - org.label-schema.schema-version="1.0" |
37 |
| - |
38 |
| -COPY 3proxy.cfg /etc/3proxy/3proxy.cfg |
39 |
| -COPY docker-entrypoint.sh /docker-entrypoint.sh |
40 |
| -COPY --from=builder /tmp/3proxy/src/3proxy /usr/bin/3proxy |
| 39 | +# Copy binaries |
| 40 | +COPY --from=builder /lib/x86_64-linux-gnu/libdl.so.* /lib/ |
| 41 | +COPY --from=builder /tmp/3proxy/bin/3proxy /bin/ |
| 42 | +COPY --from=builder /tmp/3proxy/bin/*.ld.so /usr/local/3proxy/libexec/ |
41 | 43 |
|
| 44 | +# Create unprivileged user |
42 | 45 | RUN set -x \
|
43 |
| - # Unprivileged user creation <https://stackoverflow.com/a/55757473/12429735RUN> |
44 | 46 | && adduser \
|
45 | 47 | --disabled-password \
|
46 | 48 | --gecos "" \
|
47 | 49 | --home /nonexistent \
|
48 | 50 | --shell /sbin/nologin \
|
49 | 51 | --no-create-home \
|
50 | 52 | --uid 10001 \
|
51 |
| - 3proxy \ |
52 |
| - && chown 3proxy:3proxy -R /etc/3proxy |
| 53 | + 3proxy |
| 54 | + |
| 55 | +# Prepare files and directories |
| 56 | +RUN set -x \ |
| 57 | + && chown -R 10001:10001 /usr/local/3proxy \ |
| 58 | + && chmod -R 550 /usr/local/3proxy \ |
| 59 | + && chmod -R 555 /usr/local/3proxy/libexec \ |
| 60 | + && chown -R root /usr/local/3proxy/libexec \ |
| 61 | + && mkdir /etc/3proxy \ |
| 62 | + && chown -R 10001:10001 /etc/3proxy |
| 63 | + |
| 64 | +# Copy our config and entrypoint script |
| 65 | +COPY 3proxy.cfg /etc/3proxy/3proxy.cfg |
| 66 | +COPY docker-entrypoint.sh /docker-entrypoint.sh |
| 67 | + |
| 68 | +# Split all buffered layers into one |
| 69 | +FROM scratch |
| 70 | + |
| 71 | +LABEL \ |
| 72 | + org.opencontainers.image.title="3proxy" \ |
| 73 | + org.opencontainers.image.description="Tiny free proxy server" \ |
| 74 | + org.opencontainers.image.url="https://github.com/tarampampam/3proxy-docker" \ |
| 75 | + org.opencontainers.image.source="https://github.com/tarampampam/3proxy-docker" \ |
| 76 | + org.opencontainers.image.vendor="Tarampampam" \ |
| 77 | + org.opencontainers.image.licenses="WTFPL" |
| 78 | + |
| 79 | +# Import from builder |
| 80 | +COPY --from=buffer / / |
53 | 81 |
|
54 | 82 | # Use an unprivileged user
|
55 | 83 | USER 3proxy:3proxy
|
56 | 84 |
|
57 | 85 | ENTRYPOINT ["/docker-entrypoint.sh"]
|
58 | 86 |
|
59 |
| -CMD ["/usr/bin/3proxy", "/etc/3proxy/3proxy.cfg"] |
| 87 | +CMD ["/bin/3proxy", "/etc/3proxy/3proxy.cfg"] |
0 commit comments