Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
87 lines (82 loc) · 2.41 KB
/
Copy pathdocker-compose.yml
File metadata and controls
87 lines (82 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# One command, no manual steps:
#
# docker compose up
#
# It brings up a moto server standing in for S3, seeds it with a real spaCy model
# (the API is useless without a model in the bucket), then starts the API against
# it. The API code is what runs on Lambda; only S3_ENDPOINT_URL differs.
name: nlp-aws-lambda-hosting
# moto accepts any credentials; these only stop boto3 from looking for real ones.
x-s3-env: &s3-env
AWS_ACCESS_KEY_ID: testing
AWS_SECRET_ACCESS_KEY: testing
AWS_DEFAULT_REGION: us-east-1
S3_ENDPOINT_URL: http://s3:5000
S3_BUCKET: nlp-lambda-models
S3_PREFIX: models
SPACY_MODEL: en_core_web_sm-3.8.0
services:
# Stands in for S3. Buckets live in memory for the life of this container;
# every `docker compose up` re-runs the seed job.
s3:
image: motoserver/moto:5.2.5
ports:
- "8321:5000"
healthcheck:
test:
- CMD
- python
- -c
- import urllib.request; urllib.request.urlopen('http://127.0.0.1:5000/moto-api/')
interval: 5s
timeout: 3s
retries: 20
start_period: 5s
# Runs once: creates the bucket and uploads the model the API will fetch.
seed:
build: .
environment:
<<: *s3-env
MODEL_CACHE_DIR: /tmp/models
entrypoint:
- /bin/sh
- -c
- |
set -e
python - <<'PY'
import os, boto3, botocore
s3 = boto3.client("s3", endpoint_url=os.environ["S3_ENDPOINT_URL"])
bucket = os.environ["S3_BUCKET"]
try:
s3.head_bucket(Bucket=bucket)
print(f"bucket {bucket} already exists")
except botocore.exceptions.ClientError:
s3.create_bucket(Bucket=bucket)
print(f"created bucket {bucket}")
PY
python -m nlp_lambda.cli upload --dest /tmp/models
depends_on:
s3:
condition: service_healthy
restart: "no"
api:
build: .
environment:
<<: *s3-env
MODEL_SOURCE: s3
MODEL_CACHE_DIR: /tmp/models
MAX_TEXT_CHARS: "100000"
MAX_BATCH_SIZE: "32"
LOG_LEVEL: INFO
ports:
- "8320:8320"
depends_on:
s3:
condition: service_healthy
seed:
condition: service_completed_successfully
# /tmp is a tmpfs here for the same reason it is ephemeral on Lambda: the
# model cache must be rebuildable from the bucket, never something you back up.
tmpfs:
- /tmp:size=512m
restart: unless-stopped