From 6f91a79081ad040797dc3fb80fbfc8966cd93ace Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sat, 9 May 2026 09:04:28 +0800 Subject: [PATCH] docs: add minimal Alpine gpclient image --- .dockerignore | 6 +++ README.md | 22 +++++++++- apps/gpclient/src/connect.rs | 10 ++++- packaging/docker/cli-alpine/Dockerfile | 60 ++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 packaging/docker/cli-alpine/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..31fd3d7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.build +.git +.vendor +apps/gpgui-helper/node_modules +target +vendor.tar.xz diff --git a/README.md b/README.md index d24e4d7..7ed69b6 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,26 @@ sudo apk add --allow-untrusted globalprotect-openconnect-*.apk The package uses Alpine's native musl build. Make sure the `community` repository is enabled so GUI dependencies such as `webkit2gtk-4.1`, `libsecret`, and `libayatana-appindicator` can be resolved. GUI-launched connections use polkit, and VPN tunnel creation requires `/dev/net/tun`. +#### Minimal CLI Docker Image + +For a container that only needs `gpclient`, build the Alpine CLI image from source: + +```bash +git clone https://github.com/yuezk/GlobalProtect-openconnect.git +cd GlobalProtect-openconnect +git submodule update --init --recursive +docker build -f packaging/docker/cli-alpine/Dockerfile -t gpclient-alpine . +``` + +Run it with access to the TUN device: + +```bash +docker run --rm -it --cap-add=NET_ADMIN --device=/dev/net/tun gpclient-alpine \ + connect --cookie-on-stdin +``` + +The image uses `BUILD_GUI_HELPER=0` and `INCLUDE_GUI=0`, so it does not build or install `gpgui-helper` or `gpgui`. + ### Gentoo Available via the `guru` and `lamdness` overlays: @@ -318,7 +338,7 @@ This project includes a DevContainer configuration that provides a consistent, r --tty -v "$(pwd)":/workspace -w /workspace gpoc-devcontainer \ bash -c "export PATH=/usr/local/cargo/bin:\$PATH && make build" ``` - To build without the GUI helper run the same command as above, but with `BUILD_GUI=0` passed as an argument to `make`. + To build without the GUI helper run the same command as above, but with `BUILD_GUI_HELPER=0` passed as an argument to `make`. 5. **Locate build artifacts:** diff --git a/apps/gpclient/src/connect.rs b/apps/gpclient/src/connect.rs index 8cba52f..7c7a70e 100644 --- a/apps/gpclient/src/connect.rs +++ b/apps/gpclient/src/connect.rs @@ -540,7 +540,15 @@ impl<'a> ConnectHandler<'a> { match prelogin { Prelogin::Saml(prelogin) => { let browser = if prelogin.support_default_browser() { - self.args.browser.as_deref() + #[cfg(feature = "webview-auth")] + { + self.args.browser.as_deref() + } + + #[cfg(not(feature = "webview-auth"))] + { + None + } } else if !cfg!(feature = "webview-auth") { bail!( "The server does not support authentication via the default browser and the gpclient is not built with the `webview-auth` feature" diff --git a/packaging/docker/cli-alpine/Dockerfile b/packaging/docker/cli-alpine/Dockerfile new file mode 100644 index 0000000..491da88 --- /dev/null +++ b/packaging/docker/cli-alpine/Dockerfile @@ -0,0 +1,60 @@ +# syntax=docker/dockerfile:1 + +ARG ALPINE_VERSION=3.23 +ARG RUST_VERSION=1.89 + +FROM rust:${RUST_VERSION}-alpine AS builder + +WORKDIR /src + +RUN apk add --no-cache \ + autoconf \ + automake \ + build-base \ + file \ + gettext-dev \ + gmp-dev \ + gnutls-dev \ + libtool \ + libxml2-dev \ + linux-headers \ + lz4-dev \ + make \ + nettle-dev \ + openssl-dev \ + p11-kit-dev \ + patch \ + pkgconf \ + zlib-dev + +COPY . . + +RUN make build \ + BUILD_GUI_HELPER=0 \ + INCLUDE_GUI=0 \ + LIBXML2_STATIC=1 + +RUN install -Dm755 target/release/gpclient /out/usr/bin/gpclient \ + && install -Dm755 packaging/files/usr/libexec/gpclient/vpnc-script /out/usr/libexec/gpclient/vpnc-script \ + && install -Dm755 packaging/files/usr/libexec/gpclient/hipreport.sh /out/usr/libexec/gpclient/hipreport.sh + +FROM alpine:${ALPINE_VERSION} + +RUN apk add --no-cache \ + ca-certificates \ + gmp \ + gnutls \ + iproute2 \ + iputils \ + libxml2 \ + lz4 \ + nettle \ + openssl \ + p11-kit \ + zlib \ + && update-ca-certificates + +COPY --from=builder /out/ / + +ENTRYPOINT ["gpclient"] +CMD ["--help"]