Commit 5106f041 authored by neelkamath's avatar neelkamath

Fix Docker builds

parent 96af1f80
...@@ -5,13 +5,13 @@ RUN pip install --no-cache-dir -r requirements.txt ...@@ -5,13 +5,13 @@ RUN pip install --no-cache-dir -r requirements.txt
ARG SPACY_MODEL ARG SPACY_MODEL
ENV PYTHONBUFFERED=1 SENSE2VEC=0 SPACY_MODEL=$SPACY_MODEL ENV PYTHONBUFFERED=1 SENSE2VEC=0 SPACY_MODEL=$SPACY_MODEL
RUN python -m spacy download $SPACY_MODEL RUN python -m spacy download $SPACY_MODEL
COPY src/main.py . COPY src/main.py src/main.py
EXPOSE 8000 EXPOSE 8000
HEALTHCHECK --timeout=2s --start-period=2s --retries=1 \ HEALTHCHECK --timeout=2s --start-period=2s --retries=1 \
CMD curl -f http://localhost:8000/health_check CMD curl -f http://localhost:8000/health_check
RUN useradd user RUN useradd user
USER user USER user
CMD ["uvicorn", "main:app", "--host", "0.0.0.0"] CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0"]
FROM base FROM base
ENV SENSE2VEC 1 ENV SENSE2VEC 1
......
#!/usr/bin/env sh #!/usr/bin/env sh
# Builds and uploads every image (e.g., neelkamath/spacy-server:2-en_core_web_sm-sense2vec) to Docker Hub. # Builds and uploads every image (e.g., neelkamath/spacy-server:2-en_core_web_sm-sense2vec) to Docker Hub.
# Builds and deploys an image. Pass the version, spaCy model, and whether to delete the pushed images as arguments.
deploy () {
base_tag="$DOCKER_HUB_USER"/spacy-server:"$1"-"$2"
sense2vec_tag="$base_tag"-sense2vec
docker build --target base --build-arg SPACY_MODEL="$2" -t "$base_tag" -f docker/Dockerfile .
docker build --build-arg SPACY_MODEL="$2" -t "$sense2vec_tag" -f docker/Dockerfile .
docker push "$base_tag"
docker push "$sense2vec_tag"
if [ "$3" = 1 ]
then
docker rmi "$base_tag" "$sense2vec_tag"
fi
}
# Get the HTTP API version. # Get the HTTP API version.
version=$(grep version docs/openapi.yaml -m 1) version=$(grep version docs/openapi.yaml -m 1)
version=${version#*: } version=${version#*: }
...@@ -10,13 +23,12 @@ version=$(echo "$version" | cut -d "'" -f 2) ...@@ -10,13 +23,12 @@ version=$(echo "$version" | cut -d "'" -f 2)
# Log in. # Log in.
echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USER" --password-stdin https://index.docker.io/v1/ echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USER" --password-stdin https://index.docker.io/v1/
# Build and upload the images. # Build and upload images. We prevent the device (e.g., CI runner) from running out of space and crashing by deleting
while IFS='' read -r spacy_model || [ -n "$spacy_model" ]; do # images after they've been pushed. We don't delete the first image so that subsequent builds can use its cache.
base_tag="$DOCKER_HUB_USER"/spacy-server:"$version"-"$spacy_model" deploy "$version" "$(head -n 1 scripts/models.txt)" 0 # Don't delete the first image.
sense2vec_tag="$base_tag"-sense2vec {
docker build --target base --build-arg SPACY_MODEL="$spacy_model" -t "$base_tag" -f docker/Dockerfile . read -r # Skip the first line because we've already deployed it.
docker build --build-arg SPACY_MODEL="$spacy_model" -t "$sense2vec_tag" -f docker/Dockerfile . while IFS='' read -r spacy_model || [ -n "$spacy_model" ]; do
docker push "$base_tag" deploy "$version" "$spacy_model" 1
docker push "$sense2vec_tag" done
docker rmi "$base_tag" "$sense2vec_tag" # Prevent the device (e.g., CI runner) from running out of space and crashing. }<scripts/models.txt
done <scripts/models.txt \ No newline at end of file
#!/usr/bin/env sh #!/usr/bin/env sh
# Sets up the development environment. # Sets up the development environment.
python -m venv venv python -m venv venv
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment