From 4c2bd0af4adea225cdd4ab5fd638d634fe827bc4 Mon Sep 17 00:00:00 2001 From: monsoon <29970829+monsoon235@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:33:36 +0800 Subject: [PATCH] Support to build Docker image with all build tags in CI/CD --- .github/workflows/docker.yml | 11 +++++++++++ Dockerfile | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 52046a49..7e87e5f6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -43,3 +43,14 @@ jobs: ${{ steps.tag.outputs.latest }} ${{ steps.tag.outputs.versioned }} push: true + - name: Build with all tags and release Docker images + uses: docker/build-push-action@v5 + with: + platforms: linux/386,linux/amd64,linux/arm64,linux/s390x + target: dist + tags: | + ${{ steps.tag.outputs.latest }}-full + ${{ steps.tag.outputs.versioned }}-full + build-args: | + WITH_ALL_TAGS=1 + push: true diff --git a/Dockerfile b/Dockerfile index 89574502..32c92da3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,21 +3,31 @@ LABEL maintainer="nekohasekai " COPY . /go/src/github.com/sagernet/sing-box WORKDIR /go/src/github.com/sagernet/sing-box ARG GOPROXY="" +ARG WITH_ALL_TAGS=0 ENV GOPROXY ${GOPROXY} ENV CGO_ENABLED=0 RUN set -ex \ - && apk add git build-base \ + && if [ -n "$WITH_ALL_TAGS" ] && [ "$WITH_ALL_TAGS" != "0" ]; then \ + export CGO_ENABLED=1 \ + && export EXTRA_PKGS="openssl1.1-compat-dev libevent-dev zlib-dev linux-headers" \ + && export EXTRA_TAGS=",with_grpc,with_v2ray_api,with_embedded_tor,with_lwip"; \ + fi \ + && apk add git build-base $EXTRA_PKGS \ && 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_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_clash_api,with_acme \ + && go build -v -trimpath -tags with_gvisor,with_quic,with_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_clash_api,with_acme$EXTRA_TAGS \ -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 " +ARG WITH_ALL_TAGS=0 RUN set -ex \ + && if [ -n "$WITH_ALL_TAGS" ] && [ "$WITH_ALL_TAGS" != "0" ]; then \ + export EXTRA_PKGS="openssl1.1-compat libevent zlib"; \ + fi \ && apk upgrade \ - && apk add bash tzdata ca-certificates \ + && apk add bash tzdata ca-certificates $EXTRA_PKGS \ && 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