0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

uv の GitHub ActionsでBuildする設定

Last updated at Posted at 2025-03-23

uv

Dockerfile

poetry などとほぼ変わらず commandは CMD ["uv", "run", "my_app"] とすればよい。

FROM python:3.12.3-slim

WORKDIR /app

# Install uv
RUN pip install uv

# Copy files needed for uv install
COPY pyproject.toml uv.lock ./

RUN uv sync --frozen

# Copy application files
COPY ./myapp ./myapp

ENV PORT=8080
EXPOSE 8080

CMD ["uv", "run", "gunicorn", "--bind", ":8080", "--workers", "1", "--threads", "8", "--timeout", "0", "myapp.main:create_app()"]

GitHub Actions

- name: Install a specific version of uv
  uses: astral-sh/setup-uv@v5
  with:
    version: "0.4.4"

その他

OSError: Readme file does not exist: README.md が出る

#11 ERROR: process "/bin/sh -c uv sync" did not complete successfully: exit code: 1
------
 > [stage-0 5/6] RUN --mount=type=cache,target=/tmp/.uv-cache,sharing=locked     uv sync:
2.028       line 1366, in validate_fields
2.028           getattr(self, attribute)
2.028         File
2.028       "/root/.cache/uv/builds-v0/.tmpUz8udH/lib/python3.12/site-packages/hatchling/metadata/core.py",
2.028       line 531, in readme
2.028           raise OSError(message)
2.028       OSError: Readme file does not exist: README.md
2.028 
2.028       hint: This usually indicates a problem with the package or the build
2.028       environment.
------
Dockerfile:17
--------------------
  16 |     # https://docs.astral.sh/uv/guides/integration/docker/#caching
  17 | >>> RUN --mount=type=cache,target=/tmp/.uv-cache,sharing=locked \
  18 | >>>     uv sync
  19 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c uv sync" did not complete successfully: exit code: 1

pyproject.tomlに readme = "README.md" などが書いてあって build時にないと起こるらしい。

対策としては、pyproject.tomlからreadmeを消す or Dockerfileで uv syncなどする前に COPY README.md ./ してあげるかどちらか。

error: failed to create directory /nonexistent/.cache/uv: Permission denied (os error 13) が出る

app用のuserがcache dirへのアクセスがないケースで起こるのでdir作成と権限を付与しておく

RUN addgroup --system --gid 1001 appgroup \
    && adduser --system --uid 1001 --gid 1001 --no-create-home appuser

RUN mkdir -p /app/.cache && chown -R 1001:1001 /app/.cache

ENV UV_CACHE_DIR=/app/.cache/uv

USER appuser
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?