docker-uv-image-builds
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDocker 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 as a production tag.
latest使用git短引用(7个字符的SHA)为镜像打标签:
bash
GIT_TAG=$(git rev-parse --short HEAD)
docker build -t mitodl/${SERVICE_NAME}:${GIT_TAG} .不要将用作生产环境标签。
latestPython 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-devShared libraries
共享库
Install shared internal libraries (e.g. ) as build-time
dependencies — do not mount them as Docker volumes at runtime. Add them to
and let install them during the image build.
ol-orchestrate-libpyproject.tomluv sync将内部共享库(如)作为构建时依赖安装——不要在运行时将它们挂载为Docker卷。将其添加到中,让在镜像构建期间安装它们。
ol-orchestrate-libpyproject.tomluv syncBuild context & .dockerignore
.dockerignore构建上下文与.dockerignore
.dockerignoreExclude development artifacts:
.venv/
__pycache__/
*.pyc
.git/排除开发产物:
.venv/
__pycache__/
*.pyc
.git/Concourse CI integration
Concourse CI集成
Concourse pipelines use 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 list.
paths:pathsConcourse流水线使用git资源上的过滤器,仅在相关文件变更时触发镜像重建。添加新服务时,需将其路径添加到对应流水线的git资源列表中。
paths:paths