Skip to content

Commit

Permalink
Dockerのベースイメージをuvで提供しているものに変更する
Browse files Browse the repository at this point in the history
  • Loading branch information
massongit committed Feb 18, 2025
1 parent dfc435d commit 3730723
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/pr-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
token: ${{steps.generate_token.outputs.token}}
- name: Get uv version
id: get_uv_version
if: github.event_name != 'pull_request' || github.event.action != 'closed'
run: echo "uv_version=$(sed -e 's/uv==//g' requirements.txt)" >> "$GITHUB_OUTPUT"
- if: github.event_name != 'pull_request' || github.event.action != 'closed'
run: bash "${GITHUB_WORKSPACE}/scripts/pr_format/pr_format/update_uv_version.sh"
env:
HEAD_REF: ${{github.head_ref}}
- name: Set up uv
uses: astral-sh/setup-uv@4db96194c378173c656ce18a155ffc14a9fc4355 # v5.2.2
if: github.event_name != 'pull_request' || github.event.action != 'closed'
with:
version: ${{steps.get_uv_version.outputs.uv_version}}
enable-cache: true
- name: Install dependencies
if: github.event_name != 'pull_request' || github.event.action != 'closed'
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/pr-test-hato-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: "recursive"
- name: Get uv version
id: get_uv_version
run: echo "uv_version=$(sed -e 's/uv==//g' requirements.txt)" >> "$GITHUB_OUTPUT"
- name: Set up uv
uses: astral-sh/setup-uv@4db96194c378173c656ce18a155ffc14a9fc4355 # v5.2.2
with:
version: ${{steps.get_uv_version.outputs.uv_version}}
enable-cache: true
- name: Install dependencies
run: bash "${GITHUB_WORKSPACE}/scripts/uv_install.sh"
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ jobs:
with:
submodules: "recursive"
fetch-depth: 0
- name: Get uv version
id: get_uv_version
run: echo "uv_version=$(sed -e 's/uv==//g' requirements.txt)" >> "$GITHUB_OUTPUT"
- name: Set up uv
uses: astral-sh/setup-uv@4db96194c378173c656ce18a155ffc14a9fc4355 # v5.2.2
with:
version: ${{steps.get_uv_version.outputs.uv_version}}
enable-cache: true
- name: Install uv
run: bash "${GITHUB_WORKSPACE}/scripts/uv_install.sh"
Expand Down
22 changes: 9 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.13.2-slim@sha256:ae9f9ac89467077ed1efefb6d9042132d28134ba201b2820227d46c9effd3174 AS base
FROM ghcr.io/astral-sh/uv:0.6.1-python3.13-bookworm-slim AS base

# バージョン情報に表示する commit hash を埋め込む
FROM base AS commit-hash
Expand All @@ -17,26 +17,24 @@ ENV ENV="${ENV}"
WORKDIR /usr/src/app

COPY .npmrc .npmrc
COPY requirements.txt requirements.txt
COPY package.json package.json
COPY package-lock.json package-lock.json

# 必要なパッケージ
# * git, gcc, libc6-dev: Pythonライブラリのインストールの際に必要
# * git: Pythonライブラリのインストールの際に必要
# * curl: ヘルスチェックの際に必要
# * libopencv-dev, libgl1-mesa-dev, libglib2.0-0: OpenCV
# * gnupg: Node.jsのインストールの際に必要
# * nodejs: textlintを使用する際に必要
RUN apt-get update && \
apt-get install -y --no-install-recommends git gcc libc6-dev libopencv-dev libgl1-mesa-dev libglib2.0-0 curl gnupg && \
apt-get install -y --no-install-recommends git libopencv-dev libgl1-mesa-dev libglib2.0-0 curl gnupg && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && \
apt-get install -y --no-install-recommends nodejs && \
pip install -r requirements.txt --no-cache-dir && \
npm install && \
apt-get remove -y gcc libc6-dev gnupg && \
apt-get remove -y gnupg && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists ~/.cache /tmp/* /root/.npm /usr/src/app/node_modules/re2/.github/actions/*/Dockerfile && \
Expand All @@ -58,18 +56,16 @@ RUN if [ "${ENV}" = 'dev' ]; then \

USER root

RUN pip uninstall -y uv virtualenv && \
apt-get remove -y git && \
RUN apt-get remove -y git && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists ~/.cache /tmp
rm -rf /var/lib/apt/lists ~/.cache /tmp/*

USER nonroot

ENV PATH="/usr/src/app/.venv/bin:$PATH"

# Matplotlib用のフォントキャッシュ生成
RUN python -c 'import matplotlib.pyplot'
RUN echo 'import matplotlib.pyplot' | uv run - && \
rm -rf /tmp/*

COPY *.py ./
COPY library library
Expand All @@ -81,4 +77,4 @@ COPY --from=commit-hash slackbot_settings.py slackbot_settings.py

ENV GIT_PYTHON_REFRESH=quiet
ENV NODE_OPTIONS="--max-old-space-size=512"
CMD ["python", "entrypoint.py"]
CMD ["uv", "run", "entrypoint.py"]
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies = [ "python-dotenv==1.0.1", "requests==2.32.3", "Pillow>=7.1.2", "o
dev = [ "autopep8==2.3.2", "requests-mock==1.12.1", "pylint==3.3.4", "sqlfluff==3.3.1", "mypy==1.15.0", "flake8==7.1.2", "isort==6.0.0", "pre-commit==4.1.0", "importlib-metadata==8.6.1", "toml==0.10.2", "types-toml==0.10.8.20240310", "pyink==24.10.0",]

[tool.uv]
required-version = "0.6.1"

[[tool.uv.index]]
name = "pypi"
url = "https://pypi.org/simple"
Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

8 changes: 8 additions & 0 deletions scripts/pr_format/pr_format/update_uv_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

cp .env.example .env
export TAG_NAME="${HEAD_REF//\//-}"
docker compose pull
DOCKER_CMD="uv version | sed -e 's/uv \([0-9.]*\)/\1/g'"
uv_version=$(docker compose run hato-bot sh -c "${DOCKER_CMD}")
sed -i -e "s/required-version = .*/required-version = \"$uv_version\"/g" pyproject.toml

0 comments on commit 3730723

Please sign in to comment.