Skip to content

Commit

Permalink
ultimate docker solution
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Apr 18, 2024
1 parent c1c05c4 commit 3d263d5
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 13 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/docker-core.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 1 addition & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Docker meta
id: meta
Expand Down Expand Up @@ -50,6 +48,6 @@ jobs:
with:
context: .
push: true
platforms: linux/amd64,linux/arm64/v8
platforms: linux/amd64,linux/arm64/v8,linux/arm/v7,linux/386
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
12 changes: 9 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install upx -yq
Expand Down Expand Up @@ -70,13 +71,18 @@ jobs:
#### Build Sing-Box
git clone -b v1.8.7 https://github.com/SagerNet/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
cd ..
### Build s-ui
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 ..
upx --ultra-brute -9 -v --lzma --best --force sui
Expand All @@ -86,7 +92,7 @@ jobs:
cp sing-box.service s-ui/
mkdir 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
run: tar -zcvf s-ui-linux-${{ matrix.platform }}.tar.gz s-ui
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM node:alpine as front-builder
FROM --platform=$BUILDPLATFORM node:alpine as front-builder
WORKDIR /app
COPY frontend/ ./
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
ARG TARGETARCH
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
Expand All @@ -13,7 +13,7 @@ COPY backend/ ./
COPY --from=front-builder /app/dist/ /app/web/html/
RUN go build -o sui main.go

FROM alpine
FROM --platform=$BUILDPLATFORM alpine
LABEL org.opencontainers.image.authors="alireza7@gmail.com"
ENV TZ=Asia/Tehran
WORKDIR /app
Expand Down
4 changes: 4 additions & 0 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func GetDBPath() string {
}

func GetDefaultConfig() string {
apiEnv := GetEnvApi()
if len(apiEnv) > 0 {
return strings.Replace(defaultConfig, "127.0.0.1:1080", apiEnv, 1)
}
return defaultConfig
}

Expand Down
6 changes: 3 additions & 3 deletions backend/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func (s *ServerService) GetNetInfo() map[string]interface{} {

func (s *ServerService) GetSingboxInfo() map[string]interface{} {
info := make(map[string]interface{}, 0)
if s.SingBoxService.IsRunning() {
sysStats, err := s.SingBoxService.GetSysStats()
if err == nil {
info["running"] = true
sysStats, _ := s.SingBoxService.GetSysStats()
info["stats"] = sysStats
} else {
info["running"] = false
info["running"] = s.SingBoxService.IsRunning()
}
return info
}
Expand Down
5 changes: 4 additions & 1 deletion backend/service/sinxbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ func (s *SingBoxService) GetStats() 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()
resp, err := s.V2rayAPI.GetSysStats()
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions core/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
File renamed without changes.
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 3d263d5

Please sign in to comment.