Skip to content

Commit 6056232

Browse files
authored
Merge pull request #209 from freelawproject/uv
Move dependency management to uv, improve Docker setup
2 parents f02caed + 5962e4f commit 6056232

File tree

13 files changed

+1434
-74
lines changed

13 files changed

+1434
-74
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git
2+
.venv

.github/workflows/deploy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
if: (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020
- name: Login to Docker Hub
21-
uses: docker/login-action@v2
21+
uses: docker/login-action@v3
2222
with:
2323
username: ${{ secrets.DOCKERHUB_USERNAME }}
2424
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -30,12 +30,12 @@ jobs:
3030
needs: build
3131
runs-on: ubuntu-latest
3232
steps:
33-
- uses: actions/checkout@v3
33+
- uses: actions/checkout@v4
3434
- name: Set shortcode
3535
id: vars
3636
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
3737
- name: Configure AWS credentials
38-
uses: aws-actions/configure-aws-credentials@v1
38+
uses: aws-actions/configure-aws-credentials@v4
3939
with:
4040
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
4141
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
pre-commit:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2-beta
14-
- uses: actions/setup-python@v2
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v5
1515
with:
1616
python-version: "3.10"
17-
- uses: pre-commit/[email protected].0
17+
- uses: pre-commit/[email protected].1

.github/workflows/tests.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
python-version: ["3.10", "3.11", "3.12"]
1512
steps:
16-
- uses: actions/checkout@v2
17-
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v1
19-
with:
20-
python-version: ${{ matrix.python-version }}
13+
- uses: actions/checkout@v4
2114

2215
- name: Create the .env settings file
2316
run: cp .env.example .env.dev
@@ -27,7 +20,7 @@ jobs:
2720
echo 'DEBUG=on' >> .env.dev
2821
2922
- name: Build Image
30-
run: docker compose -f docker-compose.dev.yml up --build -d
23+
run: docker compose up --build -d
3124

3225
- name: Run tests
33-
run: docker exec mock_web_app python3 -m unittest doctor.tests
26+
run: docker compose exec doctor python -m unittest

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ target/
8181
profile_default/
8282
ipython_config.py
8383

84-
# pyenv
85-
.python-version
86-
8784
# pipenv
8885
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
8986
# However, in case of collaboration, if having platform-specific dependencies or dependencies

DEVELOPING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ application that calls to this service.
55

66
To build the microservice and start it up, run:
77

8-
docker compose -f docker-compose.dev.yml up --build -d
8+
docker compose up --build -d
99

1010
To see logs:
1111

12-
docker compose -f docker-compose.dev.yml logs -f
12+
docker compose logs -f
1313

1414
If you want to see debug logs, set `DEBUG` to `True` in `settings.py`.
1515

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ This returns the audio file as a file response.
333333

334334
## Testing
335335

336-
Testing is designed to be run with the `docker-compose.dev.yml` file. To see more about testing
336+
Testing is designed to be run with the `compose.yaml` file. To see more about testing
337337
checkout the DEVELOPING.md file.
338338

339339
## Sentry Logging

docker-compose.dev.yml renamed to compose.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,8 @@ services:
77
args:
88
options: --reload
99
image: freelawproject/doctor:latest
10-
11-
12-
13-
mock_web_app:
14-
container_name: mock_web_app
15-
image: freelawproject/doctor:latest
16-
depends_on:
17-
- doctor
1810
ports:
19-
- "5050:5050"
11+
- 5050:5050
2012
volumes:
2113
- .:/opt/app
2214
env_file:

docker/Dockerfile

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
11
# Note: Force M1 to emulate amd64
2-
FROM --platform=linux/amd64 python:3.10-slim
2+
FROM --platform=linux/amd64 python:3.10
33

4-
RUN apt-get update --option "Acquire::Retries=3" --quiet=2 && \
4+
# Install uv
5+
# https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
6+
COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /uvx /bin/
7+
8+
# Install apt dependencies
9+
# caching: https://docs.docker.com/build/cache/optimize/#use-cache-mounts
10+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
11+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
12+
apt-get update --option "Acquire::Retries=3" --quiet=2 && \
513
apt-get install -y --no-install-recommends apt-utils && \
6-
apt-get install -y python3-pip poppler-utils curl \
7-
libleptonica-dev tesseract-ocr libtesseract-dev \
8-
g++ libz-dev libjpeg-dev build-essential qpdf && \
14+
apt-get install -y \
15+
build-essential \
16+
curl \
17+
libjpeg-dev \
18+
libleptonica-dev \
19+
libtesseract-dev \
20+
libz-dev \
21+
poppler-utils \
22+
qpdf \
23+
tesseract-ocr \
24+
&& \
925
apt-get install \
1026
--option "Acquire::Retries=3" \
1127
--no-install-recommends \
1228
--assume-yes \
1329
--quiet=2 \
1430
`# Document extraction and OCR tools` \
15-
antiword docx2txt ghostscript libwpd-tools \
31+
antiword \
32+
docx2txt \
33+
ghostscript \
34+
libwpd-tools \
1635
`# Audio extraction/manipulation tools` \
17-
ffmpeg libmagic1 \
36+
ffmpeg \
37+
libmagic1 \
1838
`# Image & OCR tools` \
1939
imagemagick \
2040
`# Other dependencies` \
21-
libffi-dev libxml2-dev libxslt-dev
41+
libffi-dev \
42+
libxml2-dev \
43+
libxslt-dev
2244

2345
# set environment variables
2446
ENV PYTHONDONTWRITEBYTECODE=1 \
@@ -27,12 +49,19 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
2749
# faster overall performance
2850
OMP_THREAD_LIMIT=1
2951

30-
COPY requirements.txt .
31-
RUN pip install -r requirements.txt
52+
WORKDIR /code
53+
54+
# Install Python dependencies
55+
COPY pyproject.toml uv.lock .
56+
# https://docs.astral.sh/uv/guides/integration/docker/#caching
57+
ENV UV_COMPILE_BYTECODE=1 \
58+
UV_LINK_MODE=copy \
59+
UV_PROJECT_ENVIRONMENT=/venv \
60+
PATH="/venv/bin:$PATH"
61+
RUN --mount=type=cache,target=/root/.cache/uv \
62+
uv sync
3263

33-
COPY doctor /opt/app/doctor
34-
COPY manage.py /opt/app/
35-
WORKDIR /opt/app
64+
COPY . .
3665

3766
EXPOSE 5050
3867

pyproject.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,40 @@ name = "doctor"
33
version = "1"
44
description = "CourtListener doctor"
55
requires-python = ">=3.10"
6+
dependencies = [
7+
"certifi",
8+
"chardet>=3.0.4",
9+
"django>=3.2,<4",
10+
"django-environ>=0.8.1",
11+
"eyed3",
12+
"gunicorn==20.1",
13+
"idna==2.10",
14+
"img2pdf",
15+
"lxml>=4.5.2",
16+
"lxml-html-clean",
17+
"numpy>=1.19.1",
18+
"opencv-python>=4.2.0.32",
19+
"pandas>=1.1.1",
20+
"pdf2image>=1.7.1",
21+
"pdfplumber",
22+
"pillow>=8.0.1",
23+
"pkginfo==1.5.0.1",
24+
"pypdf2[crypto]",
25+
"pytesseract>=0.3.5",
26+
"python-magic",
27+
"reportlab",
28+
"requests>=2.25",
29+
"seal-rookery>=2.2.1",
30+
"sentry-sdk",
31+
"six>=1.15",
32+
"urllib3>=1.25.10",
33+
"x-ray==0.3.3",
34+
]
35+
36+
[dependency-groups]
37+
dev = [
38+
"ipython",
39+
]
640

741
[tool.ruff]
842
line-length = 79

0 commit comments

Comments
 (0)