This commit is contained in:
ZhuJW
2026-04-22 13:35:40 +08:00
commit 26a7fdf6c0
40 changed files with 11602 additions and 0 deletions

47
build-docker-image.sh Normal file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
ENV_NAME="${1:-test}"
IMAGE_REPO="${2:-}"
CUSTOM_TAG="${3:-}"
DOCKERFILE="${SCRIPT_DIR}/Dockerfile"
if [[ "${IMAGE_REPO}" == *":"* ]]; then
echo "IMAGE_NAME should not include a tag. Pass the tag as the third argument." >&2
exit 1
fi
case "${ENV_NAME}" in
prod)
APP_PORT=5222
DEFAULT_IMAGE_REPO="fst-app-release"
;;
test)
APP_PORT=5228
DEFAULT_IMAGE_REPO="fst-app-test"
;;
*)
echo "ENV_NAME must be 'prod' or 'test' (got: ${ENV_NAME})." >&2
exit 1
;;
esac
if [[ -z "${IMAGE_REPO}" ]]; then
IMAGE_REPO="${DEFAULT_IMAGE_REPO}"
fi
if ! command -v docker >/dev/null 2>&1; then
echo "docker not found. Please install Docker first." >&2
exit 1
fi
BUILD_TIME=$(date +%Y%m%d%H%M)
TAG_SUFFIX="${CUSTOM_TAG:-${BUILD_TIME}}"
IMAGE_NAME="${IMAGE_REPO}:${TAG_SUFFIX}"
echo "Building image '${IMAGE_NAME}' with APP_PORT=${APP_PORT}"
docker build "${SCRIPT_DIR}" -f "${DOCKERFILE}" -t "${IMAGE_NAME}" --build-arg APP_PORT="${APP_PORT}"
echo "Build complete."
echo "Run example: docker run -d -p ${APP_PORT}:${APP_PORT} --name ${IMAGE_NAME} ${IMAGE_NAME}"