在我的Python应用程序中,我使用guardrails-ai中的Detect_pii和provenance_embeddings lib。它按预期工作。
现在我创建了一个 Docker 文件,并编写了一个 github 操作工作流程来构建 Docker 映像并将其推送到容器注册表。 在安装 detector_pii 和provenance_embeddings 期间构建 docker 映像时,我遇到了几个问题,发现这是因为 numpy 版本。现在安装正确,映像已构建,但映像未推送到容器注册表。我收到以下错误当图像被写入图层时。
#16 preparing build cache for export
#16 writing layer sha256:081a3493c0e761c11da41712a3b88b1fe8be04136a1dcb26c8f44c4b2433633e done
#16 writing layer sha256:0b61b7b259eb3d2247ad58d1a46d5db155a8db279900e911a6cd824168cc53e4
#16 writing layer sha256:0b61b7b259eb3d2247ad58d1a46d5db155a8db279900e911a6cd824168cc53e4 0.2s done
#16 writing layer sha256:3c5caa9a28e74de53b117107558107449522110aa9a695f26328c4cccf95b48a
#16 writing layer sha256:3c5caa9a28e74de53b117107558107449522110aa9a695f26328c4cccf95b48a done
#16 writing layer sha256:40d734479f1486a126c248a001290d9d4fcb6c6f2018c508a91125938bf3404c 0.0s done
#16 writing layer sha256:99ab3df87e74d15b2c7da222bbac7c0cdc0a3858579982e9f4de3840bac84134
#16 preparing build cache for export 38.3s done
#16 writing layer sha256:99ab3df87e74d15b2c7da222bbac7c0cdc0a3858579982e9f4de3840bac84134 38.0s done
#16 ERROR: error writing layer blob: failed to copy: failed to send write: write /tmp/.buildx-cache/ingest/44eca930b84e16fa67395824aedec982c33ef3311b274e4f983910dbfc7fb179/data: no space left on device: unknown
------
> exporting cache to client directory:
------
WARNING: local cache import at /tmp/.buildx-cache not found due to err: could not read /tmp/.buildx-cache/index.json: open /tmp/.buildx-cache/index.json: no such file or directory
ERROR: failed to solve: error writing layer blob: failed to copy: failed to send write: write /tmp/.buildx-cache/ingest/44eca930b84e16fa67395824aedec982c33ef3311b274e4f983910dbfc7fb179/data: no space left on device: unknown
Error: buildx failed with: ERROR: failed to solve: error writing layer blob: failed to copy: failed to send write: write /tmp/.buildx-cache/ingest/44eca930b84e16fa67395824aedec982c33ef3311b274e4f983910dbfc7fb179/data: no space left on device: unknown
我正在使用的 Docker 文件
# Stage 1: Builder stage
FROM python:3.11-slim AS builder
WORKDIR /app
# Copy requirements file
COPY requirements.txt ./
# Install build dependencies and Python dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
libffi-dev \
git && \
pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
guardrails hub install hub://guardrails/detect_pii && \
guardrails hub install hub://guardrails/provenance_embeddings && \
apt-get purge -y build-essential git && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /root/.cache
# Stage 2: Runtime stage
FROM python:3.11-slim AS runtime
WORKDIR /app
# Copy Python dependencies and binaries from the builder stage
COPY --from=builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/
# Copy project files
COPY . .
# Set environment variables
ENV APP_USER=myuser
ENV HOME=/home/${APP_USER}
ENV PYTHONPATH=/app
# Install gunicorn
RUN pip install --no-cache-dir gunicorn
# Expose port 8080
EXPOSE 8080
# Command to run Gunicorn
CMD ["gunicorn", "guniconfig:app", "-b", "0.0.0.0:8080", "--workers", "4", "--threads", "4"]
我应该在 docker 或我的 github 操作工作流程 yaml 中进行哪些更改?
GitHub Action 工作流程 yaml:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set Docker Buildx environment
run: |
mkdir -p $GITHUB_WORKSPACE/tmp-cache
export DOCKER_BUILDKIT=1
docker buildx create --use
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: your-image:latest
cache-from: type=local,src=$GITHUB_WORKSPACE/tmp-cache
cache-to: type=local,dest=$GITHUB_WORKSPACE/tmp-cache,mode=max
这会将 Docker 缓存配置到特定目录,以避免空间不足。