mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-02-27 20:53:01 +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
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG XRAY_VERSION
|
||||
ENV CGO_ENABLED=1
|
||||
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
||||
ENV XRAY_BUILD_DIR="/app/xray-build"
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache \
|
||||
RUN apk add --no-cache --update \
|
||||
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
|
||||
COPY go.mod go.sum ./
|
||||
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
|
||||
|
||||
# ========================================================
|
||||
|
|
@ -32,9 +57,9 @@ RUN apk add --no-cache \
|
|||
fail2ban \
|
||||
bash
|
||||
|
||||
COPY DockerEntrypoint.sh /app/
|
||||
COPY --from=builder /app/build/ /app/
|
||||
COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
|
||||
COPY DockerEntrypoint.sh ./
|
||||
COPY --from=builder /app/build/x-ui ./
|
||||
COPY --from=builder /app/xray-build/bin/ /tmp/xray/
|
||||
|
||||
# Configure fail2ban
|
||||
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/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
|
||||
|
||||
RUN chmod +x \
|
||||
/app/DockerEntrypoint.sh \
|
||||
/app/x-ui \
|
||||
/usr/bin/x-ui
|
||||
RUN chmod +x /app/DockerEntrypoint.sh
|
||||
|
||||
ENV XUI_ENABLE_FAIL2BAN="true"
|
||||
EXPOSE 2053
|
||||
VOLUME [ "/etc/x-ui" ]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue