mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-06-03 06:07:20 +02:00
Changed dockerfile to better cache
This commit is contained in:
parent
d1e5581eea
commit
c49f2fd1db
@ -1,19 +1,27 @@
|
|||||||
|
# Stage 1: Build Zoraxy
|
||||||
FROM docker.io/golang:alpine AS build-zoraxy
|
FROM docker.io/golang:alpine AS build-zoraxy
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
RUN mkdir -p /opt/zoraxy/source/ &&\
|
RUN mkdir -p /opt/zoraxy/source/ &&\
|
||||||
mkdir -p /usr/local/bin/
|
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/
|
WORKDIR /opt/zoraxy/source/
|
||||||
|
|
||||||
RUN go mod tidy &&\
|
# Copy go.mod and go.sum first to leverage Docker cache
|
||||||
go build -o /usr/local/bin/zoraxy &&\
|
COPY ./src/go.mod ./src/go.sum ./
|
||||||
|
RUN go mod tidy
|
||||||
|
|
||||||
|
# Copy the rest of the source code
|
||||||
|
COPY ./src/ .
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
RUN go build -o /usr/local/bin/zoraxy &&\
|
||||||
chmod 755 /usr/local/bin/zoraxy
|
chmod 755 /usr/local/bin/zoraxy
|
||||||
|
|
||||||
|
# Stage 2: Build ZeroTier
|
||||||
FROM docker.io/ubuntu:latest AS build-zerotier
|
FROM docker.io/ubuntu:latest AS build-zerotier
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
RUN mkdir -p /opt/zerotier/source/ &&\
|
RUN mkdir -p /opt/zerotier/source/ &&\
|
||||||
mkdir -p /usr/local/bin/
|
mkdir -p /usr/local/bin/
|
||||||
|
|
||||||
@ -22,6 +30,7 @@ WORKDIR /opt/zerotier/source/
|
|||||||
RUN apt-get update -y &&\
|
RUN apt-get update -y &&\
|
||||||
apt-get install -y curl jq build-essential pkg-config clang cargo libssl-dev
|
apt-get install -y curl jq build-essential pkg-config clang cargo libssl-dev
|
||||||
|
|
||||||
|
# Download and build ZeroTier
|
||||||
RUN curl -Lo ZeroTierOne.tar.gz https://codeload.github.com/zerotier/ZeroTierOne/tar.gz/refs/tags/1.10.6 &&\
|
RUN curl -Lo ZeroTierOne.tar.gz https://codeload.github.com/zerotier/ZeroTierOne/tar.gz/refs/tags/1.10.6 &&\
|
||||||
tar -xzvf ZeroTierOne.tar.gz &&\
|
tar -xzvf ZeroTierOne.tar.gz &&\
|
||||||
cd ZeroTierOne-* &&\
|
cd ZeroTierOne-* &&\
|
||||||
@ -29,19 +38,24 @@ RUN curl -Lo ZeroTierOne.tar.gz https://codeload.github.com/zerotier/ZeroTierOne
|
|||||||
mv ./zerotier-one /usr/local/bin/zerotier-one &&\
|
mv ./zerotier-one /usr/local/bin/zerotier-one &&\
|
||||||
chmod 755 /usr/local/bin/zerotier-one
|
chmod 755 /usr/local/bin/zerotier-one
|
||||||
|
|
||||||
|
# Stage 3: Final image
|
||||||
FROM docker.io/ubuntu:latest
|
FROM docker.io/ubuntu:latest
|
||||||
|
|
||||||
|
# Install runtime dependencies
|
||||||
RUN apt-get update -y &&\
|
RUN apt-get update -y &&\
|
||||||
apt-get install -y bash sudo netcat-openbsd libssl-dev ca-certificates
|
apt-get install -y bash sudo netcat-openbsd libssl-dev ca-certificates
|
||||||
|
|
||||||
|
# Copy entrypoint script
|
||||||
COPY --chmod=700 ./entrypoint.sh /opt/zoraxy/
|
COPY --chmod=700 ./entrypoint.sh /opt/zoraxy/
|
||||||
|
|
||||||
|
# Copy built binaries from previous stages
|
||||||
COPY --from=build-zoraxy /usr/local/bin/zoraxy /usr/local/bin/zoraxy
|
COPY --from=build-zoraxy /usr/local/bin/zoraxy /usr/local/bin/zoraxy
|
||||||
COPY --from=build-zerotier /usr/local/bin/zerotier-one /usr/local/bin/zerotier-one
|
COPY --from=build-zerotier /usr/local/bin/zerotier-one /usr/local/bin/zerotier-one
|
||||||
|
|
||||||
WORKDIR /opt/zoraxy/config/
|
WORKDIR /opt/zoraxy/config/
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
ENV ZEROTIER="false"
|
ENV ZEROTIER="false"
|
||||||
|
|
||||||
ENV AUTORENEW="86400"
|
ENV AUTORENEW="86400"
|
||||||
ENV CFGUPGRADE="true"
|
ENV CFGUPGRADE="true"
|
||||||
ENV DB="auto"
|
ENV DB="auto"
|
||||||
@ -60,9 +74,12 @@ ENV WEBROOT="./www"
|
|||||||
ENV ZTAUTH=""
|
ENV ZTAUTH=""
|
||||||
ENV ZTPORT="9993"
|
ENV ZTPORT="9993"
|
||||||
|
|
||||||
|
# Define volumes
|
||||||
VOLUME [ "/opt/zoraxy/config/" ]
|
VOLUME [ "/opt/zoraxy/config/" ]
|
||||||
|
|
||||||
|
# Set entrypoint
|
||||||
ENTRYPOINT [ "/opt/zoraxy/entrypoint.sh" ]
|
ENTRYPOINT [ "/opt/zoraxy/entrypoint.sh" ]
|
||||||
|
|
||||||
|
# Healthcheck
|
||||||
HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=3 CMD nc -vz 127.0.0.1 $PORT || exit 1
|
HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=3 CMD nc -vz 127.0.0.1 $PORT || exit 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user