Files
CLIProxyAPI/docker-build-local.sh
T
songyu 05ecfb6241 feat: add local Docker build script and update compose configuration
- Introduced a new script `docker-build-local.sh` to build a local Docker image and start services using Docker Compose.
- Updated `docker-compose.yml` to allow dynamic pull policy configuration via the `CLI_PROXY_PULL_POLICY` environment variable.
- Modified `Dockerfile` to support build arguments for Go module proxy settings during the `go mod download` step.
2026-04-30 14:01:56 +08:00

51 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build local image with docker build (no buildx required),
# then start services via docker compose.
set -euo pipefail
if ! command -v docker >/dev/null 2>&1; then
echo "Error: docker command not found."
exit 1
fi
if ! docker compose version >/dev/null 2>&1; then
echo "Error: docker compose plugin not available."
exit 1
fi
IMAGE_TAG="${CLI_PROXY_IMAGE:-cli-proxy-api:local}"
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
VERSION="$(git describe --tags --always --dirty)"
COMMIT="$(git rev-parse --short HEAD)"
else
VERSION="dev"
COMMIT="none"
fi
BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "Building local image with:"
echo " Image Tag: ${IMAGE_TAG}"
echo " Version: ${VERSION}"
echo " Commit: ${COMMIT}"
echo " Build Date: ${BUILD_DATE}"
echo "----------------------------------------"
docker build \
-t "${IMAGE_TAG}" \
--build-arg VERSION="${VERSION}" \
--build-arg COMMIT="${COMMIT}" \
--build-arg BUILD_DATE="${BUILD_DATE}" \
--build-arg GOPROXY="${GOPROXY:-https://proxy.golang.org,direct}" \
--build-arg GOSUMDB="${GOSUMDB:-sum.golang.org}" \
--build-arg GOPRIVATE="${GOPRIVATE:-}" \
.
echo "Starting services from local image..."
CLI_PROXY_IMAGE="${IMAGE_TAG}" CLI_PROXY_PULL_POLICY="never" docker compose up -d --remove-orphans --no-build --pull never
echo "Done."
echo "Use 'docker compose logs -f' to view logs."