docker-uv-image-builds

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Docker Image Builds for Python Services

Python服务的Docker镜像构建

Image naming

镜像命名

Images follow the pattern:
mitodl/<service-name>
The service name should match the application or code location name used elsewhere in configuration (Helm values, Pulumi stacks, Concourse pipelines).
镜像遵循以下格式:
mitodl/<service-name>
服务名称应与配置(Helm值、Pulumi栈、Concourse流水线)中其他地方使用的应用或代码位置名称一致。

Image tags

镜像标签

Tag images with the git short ref (7-character SHA):
bash
GIT_TAG=$(git rev-parse --short HEAD)
docker build -t mitodl/${SERVICE_NAME}:${GIT_TAG} .
Do not use
latest
as a production tag.
使用git短引用(7个字符的SHA)为镜像打标签:
bash
GIT_TAG=$(git rev-parse --short HEAD)
docker build -t mitodl/${SERVICE_NAME}:${GIT_TAG} .
不要将
latest
用作生产环境标签。

Python environment inside the image

镜像内的Python环境

Use a relocatable virtual environment so the venv works after Docker layer assembly:
dockerfile
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv venv --relocatable /app/.venv && \
    uv sync --frozen --no-dev
使用可重定位的虚拟环境,确保虚拟环境在Docker层组装后仍能正常工作:
dockerfile
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv venv --relocatable /app/.venv && \
    uv sync --frozen --no-dev

Shared libraries

共享库

Install shared internal libraries (e.g.
ol-orchestrate-lib
) as build-time dependencies — do not mount them as Docker volumes at runtime. Add them to
pyproject.toml
and let
uv sync
install them during the image build.
将内部共享库(如
ol-orchestrate-lib
)作为构建时依赖安装——不要在运行时将它们挂载为Docker卷。将其添加到
pyproject.toml
中,让
uv sync
在镜像构建期间安装它们。

Build context &
.dockerignore

构建上下文与
.dockerignore

Exclude development artifacts:
.venv/
__pycache__/
*.pyc
.git/
排除开发产物:
.venv/
__pycache__/
*.pyc
.git/

Concourse CI integration

Concourse CI集成

Concourse pipelines use
paths:
filters on git resources to trigger image rebuilds only when relevant files change. When adding a new service, add its path to the corresponding pipeline's git resource
paths
list.
Concourse流水线使用git资源上的
paths:
过滤器,仅在相关文件变更时触发镜像重建。添加新服务时,需将其路径添加到对应流水线的git资源
paths
列表中。