commit 8cef4e15bf86e9262d0bc119568ac5b23a9ff8dc Author: Evans Mike Date: Thu May 4 19:08:53 2023 +0100 init diff --git a/.github/workflows/build-singbox-docker.yml b/.github/workflows/build-singbox-docker.yml new file mode 100644 index 0000000..28251a0 --- /dev/null +++ b/.github/workflows/build-singbox-docker.yml @@ -0,0 +1,98 @@ +name: Build Docker Images +on: + workflow_dispatch: + inputs: + tag: + description: "The tag version or branch you want to build" + required: true + default: "main" + buildType: + description: "The type of build you want to build" + required: true + default: 'standard' + type: choice + options: + - standard + - minimized + - full + distro: + description: "The distro you want to build" + required: true + default: 'alpine' + type: choice + options: + - alpine + - distroless + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Action Repo + uses: actions/checkout@v3 + with: + path: action + - name: Checkout Source Code of 'SagerNet/sing-box' + uses: actions/checkout@v3 + with: + repository: 'SagerNet/sing-box' + ref: ${{ github.event.inputs.branch }} + submodules: true + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Setup QEMU for Docker Buildx + uses: docker/setup-qemu-action@v2 + - name: Select Dockerfile + run: | + if [[ "${{ github.event.inputs.buildType }}" == "full" ]]; then + if [[ "${{ github.event.inputs.distro }}" == "distroless" ]]; then + cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.full" > Dockerfile + echo "tag_postfix=-full-distroless" >> $GITHUB_OUTPUT + else + cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.full" > Dockerfile + echo "tag_postfix=-full" >> $GITHUB_OUTPUT + if [[ "${{ github.event.inputs.distro }}" == "distroless" ]]; then + fi + elif [[ "${{ github.event.inputs.buildType }}" == "minimized" ]]; then + if [[ "${{ github.event.inputs.distro }}" == "distroless" ]]; then + cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.minimized" > Dockerfile + echo "tag_postfix=-mini-distroless" >> $GITHUB_OUTPUT + else + cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.minimized" > Dockerfile + echo "tag_postfix=-mini" >> $GITHUB_OUTPUT + fi + else + if [[ "${{ github.event.inputs.distro }}" == "distroless" ]]; then + cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.standard" > Dockerfile + else + cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.standard" > Dockerfile + fi + fi + - name: Login to Docker Hub Container Registry + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker metadata + id: metadata + uses: docker/metadata-action@v4 + with: + images: etnperlong/sing-box + - name: Get tag to build + id: tag + run: | + echo "latest=etnperlong/sing-box:latest" >> $GITHUB_OUTPUT + if [[ -z "${{ github.event.inputs.tag }}" ]]; then + echo "versioned=etnperlong/sing-box:${{ github.ref_name }}" >> $GITHUB_OUTPUT + else + echo "versioned=etnperlong/sing-box:${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT + fi + - name: Build and release Docker images + uses: docker/build-push-action@v4 + with: + platforms: linux/386,linux/amd64,linux/arm64,linux/arm/v7,linux/s390x + target: dist + tags: | + ${{ steps.tag.outputs.latest }} + ${{ steps.tag.outputs.versioned }} + push: true \ No newline at end of file diff --git a/dockerfiles/Dockerfile.distroless.full b/dockerfiles/Dockerfile.distroless.full new file mode 100644 index 0000000..5d548fa --- /dev/null +++ b/dockerfiles/Dockerfile.distroless.full @@ -0,0 +1,19 @@ +FROM golang:1.20-alpine AS builder +LABEL maintainer="nekohasekai " +COPY . /go/src/github.com/sagernet/sing-box +WORKDIR /go/src/github.com/sagernet/sing-box +ARG GOPROXY="" +ENV GOPROXY ${GOPROXY} +ENV CGO_ENABLED=0 +RUN set -ex \ + && apk add git build-base \ + && export COMMIT=$(git rev-parse --short HEAD) \ + && export VERSION=$(go run ./cmd/internal/read_tag) \ + && go build -v -trimpath -tags with_gvisor,with_quic,with_grpc,with_dhcp,with_wireguard,with_shadowsocksr,with_ech,with_utls,with_reality_server,with_clash_api,with_v2ray_api,with_acme \ + -o /go/bin/sing-box \ + -ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$VERSION\" -s -w -buildid=" \ + ./cmd/sing-box +FROM gcr.io/distroless/base-debian11:nonroot AS dist +LABEL maintainer="Evans Mike " +COPY --from=builder /go/bin/sing-box / +CMD ["/sing-box"] \ No newline at end of file diff --git a/dockerfiles/Dockerfile.distroless.minimized b/dockerfiles/Dockerfile.distroless.minimized new file mode 100644 index 0000000..c389be4 --- /dev/null +++ b/dockerfiles/Dockerfile.distroless.minimized @@ -0,0 +1,19 @@ +FROM golang:1.20-alpine AS builder +LABEL maintainer="nekohasekai " +COPY . /go/src/github.com/sagernet/sing-box +WORKDIR /go/src/github.com/sagernet/sing-box +ARG GOPROXY="" +ENV GOPROXY ${GOPROXY} +ENV CGO_ENABLED=0 +RUN set -ex \ + && apk add git build-base \ + && export COMMIT=$(git rev-parse --short HEAD) \ + && export VERSION=$(go run ./cmd/internal/read_tag) \ + && go build -v -trimpath -tags with_quic,with_utls,with_reality_server \ + -o /go/bin/sing-box \ + -ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$VERSION\" -s -w -buildid=" \ + ./cmd/sing-box +FROM gcr.io/distroless/base-debian11:nonroot AS dist +LABEL maintainer="Evans Mike " +COPY --from=builder /go/bin/sing-box / +CMD ["/sing-box"] \ No newline at end of file diff --git a/dockerfiles/Dockerfile.distroless.standard b/dockerfiles/Dockerfile.distroless.standard new file mode 100644 index 0000000..52f503d --- /dev/null +++ b/dockerfiles/Dockerfile.distroless.standard @@ -0,0 +1,19 @@ +FROM golang:1.20-alpine AS builder +LABEL maintainer="nekohasekai " +COPY . /go/src/github.com/sagernet/sing-box +WORKDIR /go/src/github.com/sagernet/sing-box +ARG GOPROXY="" +ENV GOPROXY ${GOPROXY} +ENV CGO_ENABLED=0 +RUN set -ex \ + && apk add git build-base \ + && export COMMIT=$(git rev-parse --short HEAD) \ + && export VERSION=$(go run ./cmd/internal/read_tag) \ + && go build -v -trimpath -tags with_gvisor,with_quic,with_wireguard,with_utls,with_reality_server,with_clash_api,with_acme \ + -o /go/bin/sing-box \ + -ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$VERSION\" -s -w -buildid=" \ + ./cmd/sing-box +FROM gcr.io/distroless/base-debian11:nonroot AS dist +LABEL maintainer="Evans Mike " +COPY --from=builder /go/bin/sing-box / +CMD ["/sing-box"] \ No newline at end of file diff --git a/dockerfiles/Dockerfile.full b/dockerfiles/Dockerfile.full new file mode 100644 index 0000000..4022b64 --- /dev/null +++ b/dockerfiles/Dockerfile.full @@ -0,0 +1,23 @@ +FROM golang:1.20-alpine AS builder +LABEL maintainer="nekohasekai " +COPY . /go/src/github.com/sagernet/sing-box +WORKDIR /go/src/github.com/sagernet/sing-box +ARG GOPROXY="" +ENV GOPROXY ${GOPROXY} +ENV CGO_ENABLED=0 +RUN set -ex \ + && apk add git build-base \ + && export COMMIT=$(git rev-parse --short HEAD) \ + && export VERSION=$(go run ./cmd/internal/read_tag) \ + && go build -v -trimpath -tags with_gvisor,with_quic,with_grpc,with_dhcp,with_wireguard,with_shadowsocksr,with_ech,with_utls,with_reality_server,with_clash_api,with_v2ray_api,with_acme \ + -o /go/bin/sing-box \ + -ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$VERSION\" -s -w -buildid=" \ + ./cmd/sing-box +FROM alpine AS dist +LABEL maintainer="nekohasekai " +RUN set -ex \ + && apk upgrade \ + && apk add bash tzdata ca-certificates \ + && rm -rf /var/cache/apk/* +COPY --from=builder /go/bin/sing-box /usr/local/bin/sing-box +ENTRYPOINT ["sing-box"] \ No newline at end of file diff --git a/dockerfiles/Dockerfile.minimized b/dockerfiles/Dockerfile.minimized new file mode 100644 index 0000000..a4e996a --- /dev/null +++ b/dockerfiles/Dockerfile.minimized @@ -0,0 +1,23 @@ +FROM golang:1.20-alpine AS builder +LABEL maintainer="nekohasekai " +COPY . /go/src/github.com/sagernet/sing-box +WORKDIR /go/src/github.com/sagernet/sing-box +ARG GOPROXY="" +ENV GOPROXY ${GOPROXY} +ENV CGO_ENABLED=0 +RUN set -ex \ + && apk add git build-base \ + && export COMMIT=$(git rev-parse --short HEAD) \ + && export VERSION=$(go run ./cmd/internal/read_tag) \ + && go build -v -trimpath -tags with_quic,with_utls,with_reality_server \ + -o /go/bin/sing-box \ + -ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$VERSION\" -s -w -buildid=" \ + ./cmd/sing-box +FROM alpine AS dist +LABEL maintainer="nekohasekai " +RUN set -ex \ + && apk upgrade \ + && apk add bash tzdata ca-certificates \ + && rm -rf /var/cache/apk/* +COPY --from=builder /go/bin/sing-box /usr/local/bin/sing-box +ENTRYPOINT ["sing-box"] \ No newline at end of file diff --git a/dockerfiles/Dockerfile.standard b/dockerfiles/Dockerfile.standard new file mode 100644 index 0000000..bd49446 --- /dev/null +++ b/dockerfiles/Dockerfile.standard @@ -0,0 +1,23 @@ +FROM golang:1.20-alpine AS builder +LABEL maintainer="nekohasekai " +COPY . /go/src/github.com/sagernet/sing-box +WORKDIR /go/src/github.com/sagernet/sing-box +ARG GOPROXY="" +ENV GOPROXY ${GOPROXY} +ENV CGO_ENABLED=0 +RUN set -ex \ + && apk add git build-base \ + && export COMMIT=$(git rev-parse --short HEAD) \ + && export VERSION=$(go run ./cmd/internal/read_tag) \ + && go build -v -trimpath -tags with_gvisor,with_quic,with_wireguard,with_utls,with_reality_server,with_clash_api,with_acme \ + -o /go/bin/sing-box \ + -ldflags "-X \"github.com/sagernet/sing-box/constant.Version=$VERSION\" -s -w -buildid=" \ + ./cmd/sing-box +FROM alpine AS dist +LABEL maintainer="nekohasekai " +RUN set -ex \ + && apk upgrade \ + && apk add bash tzdata ca-certificates \ + && rm -rf /var/cache/apk/* +COPY --from=builder /go/bin/sing-box /usr/local/bin/sing-box +ENTRYPOINT ["sing-box"] \ No newline at end of file