mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-02-28 05:02:59 +00:00
Dockerfile optimization
This commit is contained in:
parent
f421afb7f7
commit
53d3166108
1 changed files with 34 additions and 13 deletions
47
Dockerfile
47
Dockerfile
|
|
@ -3,20 +3,45 @@
|
||||||
# ========================================================
|
# ========================================================
|
||||||
FROM golang:1.25-alpine AS builder
|
FROM golang:1.25-alpine AS builder
|
||||||
|
|
||||||
|
ARG TARGETARCH
|
||||||
|
ARG XRAY_VERSION
|
||||||
|
ENV CGO_ENABLED=1
|
||||||
|
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
||||||
|
ENV XRAY_BUILD_DIR="/app/xray-build"
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache --update \
|
||||||
build-base \
|
build-base \
|
||||||
gcc
|
gcc \
|
||||||
|
curl \
|
||||||
|
unzip \
|
||||||
|
bash
|
||||||
|
|
||||||
|
# Install xray-core and geodat files
|
||||||
|
RUN mkdir -p "$XRAY_BUILD_DIR"
|
||||||
|
COPY lib/geo.sh "$XRAY_BUILD_DIR"/
|
||||||
|
COPY lib/xray-tools.sh "$XRAY_BUILD_DIR"/
|
||||||
|
|
||||||
|
RUN chmod +x "$XRAY_BUILD_DIR"/xray-tools.sh \
|
||||||
|
&& chmod +x "$XRAY_BUILD_DIR"/geo.sh
|
||||||
|
RUN "$XRAY_BUILD_DIR"/xray-tools.sh install_xray_core "$TARGETARCH" "$XRAY_BUILD_DIR"/bin "$XRAY_VERSION" \
|
||||||
|
&& "$XRAY_BUILD_DIR"/geo.sh update_all_geofiles "$XRAY_BUILD_DIR"/bin
|
||||||
|
|
||||||
|
|
||||||
# docker CACHE
|
# docker CACHE
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
COPY . .
|
# Faster build, no extra files or volumes copied
|
||||||
|
COPY config/ config/
|
||||||
|
COPY database/ database/
|
||||||
|
COPY logger/ logger/
|
||||||
|
COPY sub/ sub/
|
||||||
|
COPY web/ web/
|
||||||
|
COPY util/ util/
|
||||||
|
COPY xray/ xray/
|
||||||
|
COPY main.go ./
|
||||||
|
|
||||||
ENV CGO_ENABLED=1
|
|
||||||
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
|
||||||
RUN go build -ldflags "-w -s" -o build/x-ui main.go
|
RUN go build -ldflags "-w -s" -o build/x-ui main.go
|
||||||
|
|
||||||
# ========================================================
|
# ========================================================
|
||||||
|
|
@ -32,9 +57,9 @@ RUN apk add --no-cache \
|
||||||
fail2ban \
|
fail2ban \
|
||||||
bash
|
bash
|
||||||
|
|
||||||
COPY DockerEntrypoint.sh /app/
|
COPY DockerEntrypoint.sh ./
|
||||||
COPY --from=builder /app/build/ /app/
|
COPY --from=builder /app/build/x-ui ./
|
||||||
COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
|
COPY --from=builder /app/xray-build/bin/ /tmp/xray/
|
||||||
|
|
||||||
# Configure fail2ban
|
# Configure fail2ban
|
||||||
RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
|
RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
|
||||||
|
|
@ -43,12 +68,8 @@ RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
|
||||||
&& sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
|
&& sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
|
||||||
&& sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
|
&& sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
|
||||||
|
|
||||||
RUN chmod +x \
|
RUN chmod +x /app/DockerEntrypoint.sh
|
||||||
/app/DockerEntrypoint.sh \
|
|
||||||
/app/x-ui \
|
|
||||||
/usr/bin/x-ui
|
|
||||||
|
|
||||||
ENV XUI_ENABLE_FAIL2BAN="true"
|
|
||||||
EXPOSE 2053
|
EXPOSE 2053
|
||||||
VOLUME [ "/etc/x-ui" ]
|
VOLUME [ "/etc/x-ui" ]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue