Commit a9352021 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

build: 优化 Docker 构建流程并配置 pip 镜像源

parent b6be6b23
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -59,7 +59,10 @@ build:
	if [ -d "../external/csst-dag" ]; then echo "  [OK]   csst-dag"; else echo "  [MISS] csst-dag"; fi;
	if [ -d "../external/csst-dags" ]; then echo "  [OK]   csst-dags"; else echo "  [MISS] csst-dags"; fi;
	@if [ ! -f $(REQ_FILE) ]; then echo "Error: $(REQ_FILE) not found"; exit 1; fi
	@total=$$(grep -v '^#' $(REQ_FILE) | grep -v '^$$' | wc -l); \
	@set -e; \
	cleanup() { rm -rf ./api_gateway/csst-dfs-client ./api_gateway/ccds ./external/js9 >/dev/null 2>&1 || true; }; \
	trap cleanup EXIT; \
	total=$$(grep -v '^#' $(REQ_FILE) | grep -v '^$$' | wc -l); \
	total_imgs=$$(($$total+$(CUSTOM_IMAGE_COUNT))); \
	echo "Pulling, retagging and building all $${total_imgs} images..."; \
	count=1; \
@@ -71,10 +74,10 @@ build:
			echo "[$${count}/$${total_imgs}] Processing $${img} -> $${target} (Skipping pull, already exists)..."; \
		else \
			echo "[$${count}/$${total_imgs}] Processing $${img} -> $${target}..."; \
			(docker pull $${img} > /dev/null 2>&1 || true); \
			docker pull $${img} > /dev/null 2>&1; \
		fi; \
		if [ "$${img}" != "$${target}" ]; then \
			(docker tag $${img} $${target} > /dev/null 2>&1 || true); \
			docker tag $${img} $${target} > /dev/null 2>&1; \
		fi; \
		count=$$((count+1)); \
	done; \
@@ -90,8 +93,6 @@ build:
				rsync -a --delete --exclude ".git" --exclude "__pycache__" ../external/ccds/ ./api_gateway/ccds/; \
		fi; \
	docker build -q -t $(TARGET_API_GATEWAY) ./api_gateway; \
	rm -rf ./api_gateway/csst-dfs-client; \
	rm -rf ./api_gateway/ccds; \
	echo "[$$(($$total+3))/$${total_imgs}] Building Task Portal Image ($(TARGET_TASK_PORTAL)) with BUILD_NUMBER=$(BUILD_NUMBER)..."; \
	docker build -q --build-arg VITE_BUILD_NUMBER=$(BUILD_NUMBER) --build-arg VITE_BUILD_TIME="$(shell date '+%Y-%m-%d %H:%M:%S')" -t $(TARGET_TASK_PORTAL) ./frontend_vue; \
	if [ "$(SKIP_JS9)" != "1" ]; then \
@@ -101,13 +102,13 @@ build:
				rsync -a --delete --exclude ".git" --exclude "__pycache__" ../external/js9/ ./external/js9/; \
		fi; \
		docker build -q -t $(TARGET_JS9) -f ./js9_service/Dockerfile .; \
		rm -rf ./external/js9; \
	fi; \
	echo "All $${total_imgs} images prepared successfully."

push:
	@if [ -z "$(HARBOR_PROJECT)" ]; then echo "Error: HARBOR_PROJECT is empty. Please specify a registry prefix to push. Example: make push HARBOR_PROJECT=csu-harbor.csst.nao:10443/csst/"; exit 1; fi
	@total=$$(grep -v '^#' $(REQ_FILE) | grep -v '^$$' | wc -l); \
	@set -e; \
	total=$$(grep -v '^#' $(REQ_FILE) | grep -v '^$$' | wc -l); \
	total_imgs=$$(($$total+$(CUSTOM_IMAGE_COUNT))); \
	echo "Pushing all $${total_imgs} images to $(HARBOR_PROJECT)..."; \
	count=1; \
+8 −2
Original line number Diff line number Diff line
@@ -2,8 +2,15 @@ FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
ARG PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn
ARG PIP_DEFAULT_TIMEOUT=120
ARG PIP_RETRIES=5
ENV PIP_INDEX_URL=${PIP_INDEX_URL}
ENV PIP_TRUSTED_HOST=${PIP_TRUSTED_HOST}
ENV PIP_DEFAULT_TIMEOUT=${PIP_DEFAULT_TIMEOUT}
ENV PIP_RETRIES=${PIP_RETRIES}

# Install dependencies, including local csst-dfs-client if it exists
COPY csst-dfs-client /app/csst-dfs-client/
COPY ccds /app/ccds/
RUN pip install --no-cache-dir -r requirements.txt && \
@@ -12,7 +19,6 @@ RUN if [ -f "/app/ccds/setup.py" ] || [ -f "/app/ccds/pyproject.toml" ]; then pi

COPY . .

# 暴露网关端口
EXPOSE 38000

CMD ["python", "-u", "main.py"]
+0 −1
Original line number Diff line number Diff line