ultimate docker solution
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
name: Sing-box Docker Image CI
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Get latest release
|
||||||
|
id: get_release
|
||||||
|
run: |
|
||||||
|
latest_release=$(curl -Ls "https://api.github.com/repos/sagernet/sing-box/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
||||||
|
echo "latest_release: $latest_release"
|
||||||
|
echo "latest_release=$latest_release" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
alireza7/s-ui-singbox
|
||||||
|
ghcr.io/alireza0/s-ui-singbox
|
||||||
|
tags: |
|
||||||
|
type=sha
|
||||||
|
type=pep440,pattern=${{ steps.get_release.outputs.latest_release }}
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Login to GHCR
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: core/
|
||||||
|
push: true
|
||||||
|
build-args: SINGBOX_VER=${{ steps.get_release.outputs.latest_release }}
|
||||||
|
platforms: linux/amd64,linux/arm64/v8,linux/arm/v7,linux/386
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
@@ -11,8 +11,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
|
|
||||||
- name: Docker meta
|
- name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -50,6 +48,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64/v8
|
platforms: linux/amd64,linux/arm64/v8,linux/arm/v7,linux/386
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
@@ -31,6 +31,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update && sudo apt-get install upx -yq
|
sudo apt-get update && sudo apt-get install upx -yq
|
||||||
@@ -70,13 +71,18 @@ jobs:
|
|||||||
#### Build Sing-Box
|
#### Build Sing-Box
|
||||||
git clone -b v1.8.7 https://github.com/SagerNet/sing-box
|
git clone -b v1.8.7 https://github.com/SagerNet/sing-box
|
||||||
cd sing-box
|
cd sing-box
|
||||||
go build -v -gcflags=all="-l -B -C" -mod=mod -trimpath -ldflags "-s -w -buildid= -extldflags '-static'" -a -tags='netgo osusergo static_build with_v2ray_api with_clash_api with_grpc with_quic with_ech' -o sing-box ./cmd/sing-box
|
go build -v -gcflags=all="-l -B -C" -mod=mod -trimpath \
|
||||||
|
-ldflags "-s -w -buildid= -extldflags '-static'" -a \
|
||||||
|
-tags='netgo osusergo static_build with_quic with_grpc with_wireguard with_ech with_utls with_reality_server with_acme with_v2ray_api with_clash_api with_gvisor' \
|
||||||
|
-o sing-box ./cmd/sing-box
|
||||||
upx --ultra-brute -9 -v --lzma --best --force sing-box
|
upx --ultra-brute -9 -v --lzma --best --force sing-box
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
### Build s-ui
|
### Build s-ui
|
||||||
cd backend
|
cd backend
|
||||||
go build -v -gcflags=all="-l -B -C" -mod=mod -trimpath -ldflags "-s -w -buildid= -extldflags '-static'" -a -tags='netgo osusergo static_build sqlite_omit_load_extension' -o ../sui main.go
|
go build -v -gcflags=all="-l -B -C" -mod=mod -trimpath \
|
||||||
|
-ldflags "-s -w -buildid= -extldflags '-static'" -a -tags='netgo osusergo static_build sqlite_omit_load_extension' \
|
||||||
|
-o ../sui main.go
|
||||||
cd ..
|
cd ..
|
||||||
upx --ultra-brute -9 -v --lzma --best --force sui
|
upx --ultra-brute -9 -v --lzma --best --force sui
|
||||||
|
|
||||||
@@ -86,7 +92,7 @@ jobs:
|
|||||||
cp sing-box.service s-ui/
|
cp sing-box.service s-ui/
|
||||||
mkdir s-ui/bin
|
mkdir s-ui/bin
|
||||||
cp sing-box/sing-box s-ui/bin/
|
cp sing-box/sing-box s-ui/bin/
|
||||||
cp runSingbox.sh s-ui/bin/
|
cp core/runSingbox.sh s-ui/bin/
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
run: tar -zcvf s-ui-linux-${{ matrix.platform }}.tar.gz s-ui
|
run: tar -zcvf s-ui-linux-${{ matrix.platform }}.tar.gz s-ui
|
||||||
|
|||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
FROM node:alpine as front-builder
|
FROM --platform=$BUILDPLATFORM node:alpine as front-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY frontend/ ./
|
COPY frontend/ ./
|
||||||
RUN npm install && npm run build
|
RUN npm install && npm run build
|
||||||
|
|
||||||
FROM golang:1.22-alpine AS backend-builder
|
FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS backend-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
||||||
@@ -13,7 +13,7 @@ COPY backend/ ./
|
|||||||
COPY --from=front-builder /app/dist/ /app/web/html/
|
COPY --from=front-builder /app/dist/ /app/web/html/
|
||||||
RUN go build -o sui main.go
|
RUN go build -o sui main.go
|
||||||
|
|
||||||
FROM alpine
|
FROM --platform=$BUILDPLATFORM alpine
|
||||||
LABEL org.opencontainers.image.authors="alireza7@gmail.com"
|
LABEL org.opencontainers.image.authors="alireza7@gmail.com"
|
||||||
ENV TZ=Asia/Tehran
|
ENV TZ=Asia/Tehran
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@@ -69,6 +69,10 @@ func GetDBPath() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultConfig() string {
|
func GetDefaultConfig() string {
|
||||||
|
apiEnv := GetEnvApi()
|
||||||
|
if len(apiEnv) > 0 {
|
||||||
|
return strings.Replace(defaultConfig, "127.0.0.1:1080", apiEnv, 1)
|
||||||
|
}
|
||||||
return defaultConfig
|
return defaultConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,12 +89,12 @@ func (s *ServerService) GetNetInfo() map[string]interface{} {
|
|||||||
|
|
||||||
func (s *ServerService) GetSingboxInfo() map[string]interface{} {
|
func (s *ServerService) GetSingboxInfo() map[string]interface{} {
|
||||||
info := make(map[string]interface{}, 0)
|
info := make(map[string]interface{}, 0)
|
||||||
if s.SingBoxService.IsRunning() {
|
sysStats, err := s.SingBoxService.GetSysStats()
|
||||||
|
if err == nil {
|
||||||
info["running"] = true
|
info["running"] = true
|
||||||
sysStats, _ := s.SingBoxService.GetSysStats()
|
|
||||||
info["stats"] = sysStats
|
info["stats"] = sysStats
|
||||||
} else {
|
} else {
|
||||||
info["running"] = false
|
info["running"] = s.SingBoxService.IsRunning()
|
||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,10 @@ func (s *SingBoxService) GetStats() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SingBoxService) GetSysStats() (*map[string]interface{}, error) {
|
func (s *SingBoxService) GetSysStats() (*map[string]interface{}, error) {
|
||||||
s.V2rayAPI.Init(ApiAddr)
|
err := s.V2rayAPI.Init(ApiAddr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
defer s.V2rayAPI.Close()
|
defer s.V2rayAPI.Close()
|
||||||
resp, err := s.V2rayAPI.GetSysStats()
|
resp, err := s.V2rayAPI.GetSysStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS singbox-builder
|
||||||
|
LABEL maintainer="Alireza <alireza7@gmail.com>"
|
||||||
|
WORKDIR /app
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
|
ARG SINGBOX_VER=v1.8.10
|
||||||
|
ARG SINGBOX_TAGS="with_quic,with_grpc,with_wireguard,with_ech,with_utls,with_reality_server,with_acme,with_v2ray_api,with_clash_api,with_gvisor"
|
||||||
|
ARG GOPROXY=""
|
||||||
|
ENV GOPROXY ${GOPROXY}
|
||||||
|
ENV CGO_ENABLED=0
|
||||||
|
ENV GOOS=$TARGETOS
|
||||||
|
ENV GOARCH=$TARGETARCH
|
||||||
|
RUN apk --no-cache --update add build-base gcc wget unzip git
|
||||||
|
RUN set -ex \
|
||||||
|
&& git clone --depth 1 --branch $SINGBOX_VER https://github.com/SagerNet/sing-box.git \
|
||||||
|
&& cd sing-box \
|
||||||
|
&& go build -v -trimpath -tags \
|
||||||
|
$SINGBOX_TAGS \
|
||||||
|
-ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$SINGBOX_VER\" -s -w -buildid=" \
|
||||||
|
./cmd/sing-box
|
||||||
|
|
||||||
|
FROM --platform=$BUILDPLATFORM alpine
|
||||||
|
LABEL maintainer="Alireza <alireza7@gmail.com>"
|
||||||
|
ENV TZ=Asia/Tehran
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apk add --no-cache --update ca-certificates tzdata bash
|
||||||
|
COPY --from=singbox-builder /app/sing-box/sing-box .
|
||||||
|
COPY runSingbox.sh .
|
||||||
|
ENTRYPOINT [ "./runSingbox.sh" ]
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
version: "3"
|
||||||
|
|
||||||
|
services:
|
||||||
|
s-ui:
|
||||||
|
image: alireza7/s-ui
|
||||||
|
container_name: s-ui
|
||||||
|
hostname: "S-UI docker"
|
||||||
|
volumes:
|
||||||
|
- "singbox:/app/bin"
|
||||||
|
- "$PWD/db:/app/db"
|
||||||
|
- "$PWD/cert:/app/cert"
|
||||||
|
environment:
|
||||||
|
SINGBOX_API: "sing-box:1080"
|
||||||
|
SUI_DB_FOLDER: "db"
|
||||||
|
tty: true
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "2095:2095"
|
||||||
|
- "2096:2096"
|
||||||
|
networks:
|
||||||
|
- s-ui
|
||||||
|
entrypoint: "./sui"
|
||||||
|
|
||||||
|
sing-box:
|
||||||
|
image: alireza7/s-ui-singbox
|
||||||
|
container_name: sing-box
|
||||||
|
volumes:
|
||||||
|
- "singbox:/app/"
|
||||||
|
- "$PWD/cert:/cert"
|
||||||
|
networks:
|
||||||
|
- s-ui
|
||||||
|
ports:
|
||||||
|
- "443:443"
|
||||||
|
- "1443:1443"
|
||||||
|
- "2443:2443"
|
||||||
|
- "3443:3443"
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
- s-ui
|
||||||
|
|
||||||
|
networks:
|
||||||
|
s-ui:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
singbox:
|
||||||
Reference in New Issue
Block a user