diff --git a/.dockerignore b/.dockerignore index 096960c3..99bb78cc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,4 +6,6 @@ Dockerfile docker-compose.yml .tmp .idea -.vscode \ No newline at end of file +.vscode +LICENSE +README.* \ No newline at end of file diff --git a/DockerEntrypoint.sh b/DockerEntrypoint.sh index 7511d2ea..277026b8 100644 --- a/DockerEntrypoint.sh +++ b/DockerEntrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh # Start fail2ban -[ $XUI_ENABLE_FAIL2BAN == "true" ] && fail2ban-client -x start +[ "$XUI_ENABLE_FAIL2BAN" = "true" ] && fail2ban-client -x start # Run x-ui exec /app/x-ui diff --git a/Dockerfile b/Dockerfile index cddc945c..e3d04a17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,27 +2,44 @@ # Stage: Builder # ======================================================== FROM golang:1.25-alpine AS builder + WORKDIR /app -ARG TARGETARCH RUN apk --no-cache --update add \ build-base \ - gcc \ - wget \ - unzip + gcc + +# docker CACHE +COPY go.mod go.sum ./ +RUN go mod download COPY . . ENV CGO_ENABLED=1 ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE" RUN go build -ldflags "-w -s" -o build/x-ui main.go -RUN ./DockerInit.sh "$TARGETARCH" + +# ======================================================== +# Stage: Xray downloader +# ======================================================== +FROM alpine AS xray-downloader + +ARG TARGETARCH +ARG XRAY_VERSION + +WORKDIR /app +RUN apk add --no-cache wget unzip + +COPY xray-tools.sh . +RUN chmod +x /app/xray-tools.sh +RUN ./xray-tools.sh install_xray_core "$TARGETARCH" "/app/bin" "$XRAY_VERSION" +RUN ./xray-tools.sh update_geodata_in_docker "/app/bin" # ======================================================== # Stage: Final Image of 3x-ui # ======================================================== FROM alpine -ENV TZ=Asia/Tehran + WORKDIR /app RUN apk add --no-cache --update \ @@ -31,9 +48,11 @@ RUN apk add --no-cache --update \ fail2ban \ bash +COPY DockerEntrypoint.sh /app/ COPY --from=builder /app/build/ /app/ -COPY --from=builder /app/DockerEntrypoint.sh /app/ +#COPY --from=builder /app/DockerEntrypoint.sh /app/ COPY --from=builder /app/x-ui.sh /usr/bin/x-ui +COPY --from=xray-downloader /app/bin /app/bin # Configure fail2ban @@ -51,5 +70,5 @@ RUN chmod +x \ ENV XUI_ENABLE_FAIL2BAN="true" EXPOSE 2053 VOLUME [ "/etc/x-ui" ] -CMD [ "./x-ui" ] +#CMD [ "./x-ui" ] ENTRYPOINT [ "/app/DockerEntrypoint.sh" ] diff --git a/docker-compose.yml b/docker-compose.yml index 198df198..53f96a97 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,15 +2,17 @@ services: 3xui: build: context: . - dockerfile: ./Dockerfile + args: + XRAY_VERSION: "v25.10.15" + GEOUPDATE_CRON_SCHEDULE: "0 */6 * * *" container_name: 3xui_app - # hostname: yourhostname <- optional volumes: - $PWD/db/:/etc/x-ui/ - $PWD/cert/:/root/cert/ environment: + TZ: "Asia/Tehran" XRAY_VMESS_AEAD_FORCED: "false" XUI_ENABLE_FAIL2BAN: "true" tty: true network_mode: host - restart: unless-stopped + restart: unless-stopped \ No newline at end of file diff --git a/xray-tools.sh b/xray-tools.sh index c28c8537..a2ddd682 100644 --- a/xray-tools.sh +++ b/xray-tools.sh @@ -38,7 +38,7 @@ update_geodata_in_docker() { } -update_xray_core() { +install_xray_core() { TARGETARCH="$1" WORKDIR="$2" XRAY_VERSION="$3" @@ -46,7 +46,7 @@ update_xray_core() { OLD_DIR=$(pwd) trap 'cd "$OLD_DIR"' EXIT - echo "[$(date)] Running update_xray_core" + echo "[$(date)] Running install_xray_core" case $1 in amd64) @@ -94,9 +94,9 @@ if [ "${0##*/}" = "xray-tools.sh" ]; then shift || true case "$cmd" in - update_xray_core) + install_xray_core) # args: TARGETARCH WORKDIR XRAY_VERSION - update_xray_core "$@" + install_xray_core "$@" ;; update_geodata_in_docker) # args: WORKDIR @@ -104,7 +104,7 @@ if [ "${0##*/}" = "xray-tools.sh" ]; then ;; ""|help|-h|--help) echo "Usage:" - echo " $0 update_xray_core TARGETARCH WORKDIR XRAY_VERSION" + echo " $0 install_xray_core TARGETARCH WORKDIR XRAY_VERSION" echo " $0 update_geodata_in_docker WORKDIR" exit 1 ;;