-
Notifications
You must be signed in to change notification settings - Fork 286
improvement: better docker builds #1098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.3.3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # syntax=docker/dockerfile:1.7 | ||
|
|
||
| ARG ZORAXY_BASE_IMAGE=zoraxy-base | ||
|
|
||
| ## Build Zoraxy | ||
| FROM docker.io/golang:alpine AS build-zoraxy | ||
|
|
||
| RUN mkdir -p /opt/zoraxy/source/ &&\ | ||
| mkdir -p /usr/local/bin/ | ||
|
|
||
| # If you build it yourself, you will need to add the src directory into the docker directory. | ||
| COPY ./src/ /opt/zoraxy/source/ | ||
|
|
||
| WORKDIR /opt/zoraxy/source/ | ||
|
|
||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| --mount=type=cache,target=/root/.cache/go-build \ | ||
| go mod tidy &&\ | ||
| go build -o /usr/local/bin/zoraxy &&\ | ||
| chmod 755 /usr/local/bin/zoraxy | ||
|
|
||
|
|
||
| ## Base Zoraxy image for standalone ZeroTier builds | ||
| FROM docker.io/alpine:latest AS zoraxy-base | ||
|
|
||
| RUN apk add --update --no-cache tzdata python3 sudo netcat-openbsd libressl-dev openssh ca-certificates libc6-compat libstdc++ &&\ | ||
| rm -rf /var/cache/apk/* /tmp/* | ||
|
|
||
| COPY --chmod=700 ./entrypoint.py /opt/zoraxy/ | ||
|
|
||
| COPY --from=build-zoraxy /usr/local/bin/zoraxy /usr/local/bin/zoraxy | ||
|
|
||
| RUN mkdir -p /opt/zoraxy/plugin/ &&\ | ||
| echo "tun" | tee -a /etc/modules | ||
|
|
||
| WORKDIR /opt/zoraxy/config/ | ||
|
|
||
| ENV TZ="Etc/UTC" | ||
| ENV ZEROTIER="false" | ||
| ENV ZEROTIER_BIN="/usr/local/bin/zerotier-one" | ||
|
|
||
| ENV AUTORENEW="86400" | ||
| ENV CFGUPGRADE="true" | ||
| ENV DB="auto" | ||
| ENV DOCKER="true" | ||
| ENV EARLYRENEW="30" | ||
| ENV ENABLELOG="true" | ||
| ENV FASTGEOIP="false" | ||
| ENV MDNS="true" | ||
| ENV MDNSNAME="''" | ||
| ENV NOAUTH="false" | ||
| ENV PLUGIN="/opt/zoraxy/plugin/" | ||
| ENV PORT="8000" | ||
| ENV SSHLB="false" | ||
| ENV UPDATE_GEOIP="false" | ||
| ENV VERSION="false" | ||
| ENV WEBROOT="./www" | ||
|
|
||
| VOLUME [ "/opt/zoraxy/config/" ] | ||
|
|
||
| LABEL com.imuslab.zoraxy.container-identifier="Zoraxy" | ||
|
|
||
| ENTRYPOINT [ "python3", "-u", "/opt/zoraxy/entrypoint.py" ] | ||
|
|
||
| HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=3 CMD nc -vz 127.0.0.1 $PORT || exit 1 | ||
|
|
||
| ## Build ZeroTier | ||
| FROM docker.io/rust:1.79-alpine AS build-zerotier | ||
|
|
||
| RUN mkdir -p /opt/zerotier/source/ &&\ | ||
| mkdir -p /usr/local/bin/ | ||
|
|
||
| WORKDIR /opt/zerotier/source/ | ||
|
|
||
| RUN apk add --update --no-cache curl make gcc g++ linux-headers openssl-dev nano | ||
|
|
||
| RUN --mount=type=cache,target=/root/.cargo/registry \ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again here, what is this for? Additionally, the Zoraxy build stage in this Dockerfile looks the same as in the normal Dockerfile. Shouldn't need to also build it here |
||
| --mount=type=cache,target=/root/.cargo/git \ | ||
| curl -Lo ZeroTierOne.tar.gz https://codeload.github.com/zerotier/ZeroTierOne/tar.gz/refs/tags/1.10.6 &&\ | ||
| tar -xzvf ZeroTierOne.tar.gz &&\ | ||
| cd ZeroTierOne-*/zeroidc &&\ | ||
| cargo update -p getrandom &&\ | ||
| cd .. &&\ | ||
| make -f make-linux.mk &&\ | ||
| mv ./zerotier-one /usr/local/bin/zerotier-one &&\ | ||
| chmod 755 /usr/local/bin/zerotier-one | ||
|
|
||
| FROM ${ZORAXY_BASE_IMAGE} | ||
|
|
||
| COPY --from=build-zerotier /usr/local/bin/zerotier-one /usr/local/bin/zerotier-one | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import os | ||
| import signal | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
| import time | ||
|
|
@@ -68,6 +69,15 @@ def start_zerotier(): | |
|
|
||
| global zerotier_proc | ||
|
|
||
| zerotier_bin = getenv("ZEROTIER_BIN", "/usr/local/bin/zerotier-one") | ||
| resolved_zerotier_bin = zerotier_bin if "/" in zerotier_bin else shutil.which(zerotier_bin) | ||
| if not resolved_zerotier_bin or not os.path.exists(resolved_zerotier_bin): | ||
| print( | ||
| f"ZeroTier requested but binary was not found at {zerotier_bin}. " | ||
| "Use the zoraxydocker/zoraxy:<tag>-zerotier image or mount a binary and set ZEROTIER_BIN." | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| config_dir = "/opt/zoraxy/config/zerotier/" | ||
| zt_path = "/var/lib/zerotier-one" | ||
|
|
||
|
|
@@ -78,13 +88,15 @@ def start_zerotier(): | |
| except FileExistsError: | ||
| print(f"Symlink {zt_path} already exists, skipping creation.") | ||
|
|
||
| zerotier_proc = popen(["zerotier-one"]) | ||
| zerotier_proc = popen([resolved_zerotier_bin]) | ||
|
|
||
| def start_zoraxy(): | ||
| print("Starting Zoraxy...") | ||
|
|
||
| global zoraxy_proc | ||
|
|
||
| mdns_name = getenv("MDNSNAME", "''") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we remove this? it doesn't appear to do anything |
||
|
|
||
| zoraxy_args = [ | ||
| "zoraxy", | ||
| f"-autorenew={ getenv('AUTORENEW', '86400') }", | ||
|
|
@@ -95,7 +107,7 @@ def start_zoraxy(): | |
| f"-enablelog={ getenv('ENABLELOG', 'true') }", | ||
| f"-fastgeoip={ getenv('FASTGEOIP', 'false') }", | ||
| f"-mdns={ getenv('MDNS', 'true') }", | ||
| f"-mdnsname={ getenv('MDNSNAME', "''") }", | ||
| f"-mdnsname={ mdns_name }", | ||
| f"-noauth={ getenv('NOAUTH', 'false') }", | ||
| f"-plugin={ getenv('PLUGIN', '/opt/zoraxy/plugin/') }", | ||
| f"-port=:{ getenv('PORT', '8000') }", | ||
|
|
@@ -128,4 +140,3 @@ def main(): | |
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already build in stages and Zoraxy is only built once, what is this for?