klasocki commited on
Commit
775b8b4
1 Parent(s): f42ec01

Multi-stage build in Dockerfile, reduces size by 3GB, and runs tests

Browse files
Dockerfile CHANGED
@@ -1,8 +1,14 @@
1
- FROM python:3.10-slim
2
 
3
  WORKDIR /comma-fixer
 
 
 
 
4
 
5
  COPY requirements.txt .
 
 
6
  RUN pip install -r requirements.txt
7
 
8
  COPY src/baseline.py src/baseline.py
@@ -10,5 +16,20 @@ RUN python src/baseline.py # This pre-downloads models and tokenizers
10
 
11
  COPY . .
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  EXPOSE 8000
14
  CMD uvicorn "app:app" --port 8000 --host "0.0.0.0"
 
1
+ FROM python:3.10-slim as base
2
 
3
  WORKDIR /comma-fixer
4
+ ENV PYTHONUNBUFFERED=1
5
+
6
+ RUN python -m venv /venv
7
+ ENV PATH="/venv/bin:$PATH"
8
 
9
  COPY requirements.txt .
10
+ COPY test-requirements.txt .
11
+ RUN pip install --upgrade pip
12
  RUN pip install -r requirements.txt
13
 
14
  COPY src/baseline.py src/baseline.py
 
16
 
17
  COPY . .
18
 
19
+ FROM base as test
20
+
21
+ RUN pip install -r test-requirements.txt
22
+ WORKDIR src
23
+ RUN python -m pytest ../tests
24
+
25
+ FROM python:3.10-slim as deploy
26
+
27
+ WORKDIR /comma-fixer
28
+ COPY --from=base /comma-fixer /comma-fixer
29
+ COPY --from=base /venv /venv
30
+ # Copy pre-downloaded models and make sure we are using the env
31
+ COPY --from=base /root/.cache/huggingface/hub/ /root/.cache/huggingface/hub/
32
+ ENV PATH="/venv/bin:$PATH"
33
+
34
  EXPOSE 8000
35
  CMD uvicorn "app:app" --port 8000 --host "0.0.0.0"
README.txt CHANGED
@@ -1 +1,3 @@
1
- `docker log [id]` for logs from the container.
 
 
 
1
+ `docker log [id]` for logs from the container.
2
+
3
+ `docker build -t comma-fixer --target test .` for tests
__init__.py ADDED
File without changes
docker-compose.yml CHANGED
@@ -19,8 +19,10 @@ services:
19
  dockerfile: Dockerfile
20
  container_name: comma-fixer
21
  command: uvicorn --host 0.0.0.0 --port 8000 "app:app"
22
- volumes:
23
- - ./:/comma-fixer
 
 
24
  # networks:
25
  # my-network:
26
  # aliases:
 
19
  dockerfile: Dockerfile
20
  container_name: comma-fixer
21
  command: uvicorn --host 0.0.0.0 --port 8000 "app:app"
22
+ ports:
23
+ - "8000:8000"
24
+ # volumes:
25
+ # - ./:/comma-fixer
26
  # networks:
27
  # my-network:
28
  # aliases:
requirements.txt CHANGED
@@ -1,8 +1,6 @@
1
  fastapi==0.101.1
2
  gunicorn==21.2.0
3
  uvicorn==0.23.2
4
- pytest
5
- httpx
6
  torch==2.0.1
7
  transformers==4.31.0
8
 
 
1
  fastapi==0.101.1
2
  gunicorn==21.2.0
3
  uvicorn==0.23.2
 
 
4
  torch==2.0.1
5
  transformers==4.31.0
6
 
src/baseline.py CHANGED
@@ -33,7 +33,7 @@ def _fix_commas_based_on_pipeline_output(pipeline_json: list[dict], original_s:
33
  current_offset = _find_current_token(current_offset, i, pipeline_json, result)
34
  if _should_insert_comma(i, pipeline_json):
35
  result = result[:current_offset] + ',' + result[current_offset:]
36
- current_offset += 1
37
  return result
38
 
39
 
 
33
  current_offset = _find_current_token(current_offset, i, pipeline_json, result)
34
  if _should_insert_comma(i, pipeline_json):
35
  result = result[:current_offset] + ',' + result[current_offset:]
36
+ current_offset += 1
37
  return result
38
 
39
 
test-requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pytest
2
+ httpx