Integrated unified sh scripts into docker build system + some cache updates

This commit is contained in:
Michael S2pac 2025-11-23 17:16:16 +03:00
parent 3a2988c068
commit e1058b1eaf
5 changed files with 41 additions and 18 deletions

View file

@ -7,3 +7,5 @@ docker-compose.yml
.tmp
.idea
.vscode
LICENSE
README.*

View file

@ -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

View file

@ -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" ]

View file

@ -2,13 +2,15 @@ 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

View file

@ -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
;;