This commit is contained in:
leokun
2026-06-30 10:38:52 +08:00
commit c083be5ec2
312 changed files with 146628 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
# Docker image for building this app's Linux amd64 binary from macOS/Linux hosts.
ARG BASE_IMAGE=debian:trixie
FROM ${BASE_IMAGE}
ARG GO_TARBALL_URL=https://go.dev/dl/go1.25.0.linux-amd64.tar.gz
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates curl git nodejs yarnpkg pkg-config gcc libc6-dev \
libgtk-3-dev libwebkit2gtk-4.1-dev \
&& curl -fsSL "${GO_TARBALL_URL}" -o /tmp/go.tar.gz \
&& rm -rf /usr/local/go \
&& tar -C /usr/local -xzf /tmp/go.tar.gz \
&& ln -sf /usr/local/go/bin/go /usr/local/bin/go \
&& ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt \
&& ln -sf /usr/bin/yarnpkg /usr/local/bin/yarn \
&& rm -f /tmp/go.tar.gz \
&& rm -rf /var/lib/apt/lists/*
COPY build-linux.sh /usr/local/bin/build-linux.sh
RUN chmod +x /usr/local/bin/build-linux.sh
WORKDIR /app
ENTRYPOINT ["/usr/local/bin/build-linux.sh"]
+81
View File
@@ -0,0 +1,81 @@
#!/bin/sh
set -eu
log() {
printf '[linux-build] %s\n' "$*"
}
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=1
export CGO_CFLAGS="-w"
APP=${APP_NAME:-$(basename "$(pwd)")}
BIN_PATH="bin/${APP}-linux-amd64"
LOG_MODE=${GO_BUILD_LOG_MODE:-quiet}
case "$LOG_MODE" in
quiet|heartbeat)
;;
verbose|trace)
log "workspace: $(pwd)"
log "target: ${APP} (${GOOS}/${GOARCH})"
log "go version: $(go version)"
log "log mode: ${LOG_MODE}"
;;
*)
log "unknown GO_BUILD_LOG_MODE=${LOG_MODE}, falling back to quiet"
LOG_MODE="quiet"
;;
esac
if [ -d "frontend" ] && [ -f "frontend/package.json" ] && [ ! -d "frontend/dist" ]; then
log "frontend/dist missing, building frontend assets in container"
(
cd frontend
yarn install --frozen-lockfile
yarn run build
)
fi
mkdir -p bin
LDFLAGS="-s -w"
if [ -n "${EXTRA_LDFLAGS:-}" ]; then
LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS"
fi
TAGS="production"
if [ -n "${EXTRA_TAGS:-}" ]; then
TAGS="${TAGS},${EXTRA_TAGS}"
fi
set -- go build
case "$LOG_MODE" in
quiet)
;;
heartbeat)
;;
verbose)
set -- "$@" -v
;;
trace)
set -- "$@" -x -v
;;
esac
set -- "$@" -tags "$TAGS" -trimpath -buildvcs=false -ldflags "$LDFLAGS" -o "$BIN_PATH" .
if "$@"; then
:
else
status="$?"
log "go build failed with exit code ${status}"
exit "$status"
fi
case "$LOG_MODE" in
verbose|trace)
log "built: ${BIN_PATH}"
;;
esac