Skip to content

Commit

Permalink
add basic docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
philtweir committed Feb 12, 2022
1 parent 03d10b6 commit 9621d08
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/test_data
/target
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
ff_fasttext/*.so
__pycache__
*.egg-info
/taxonomy.json
46 changes: 34 additions & 12 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
# https://docs.openfaas.com/reference/cicd/gitlab/

variables:
CONTAINER_TAG_IMAGE: $CI_REGISTRY_IMAGE:build-$CI_BUILD_REF_NAME
CONTAINER_IMAGE: $CI_REGISTRY_IMAGE:build-$CI_PIPELINE_ID
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
DOCKER_DRIVER: overlay
DOCKER_HOST: tcp://localhost:2375/


services:
- docker:18.09.7-dind

before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com

stages:
- test
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml
- build
- deploy

# Cache the templates and build-context to speed things up
cache:
key: ${CI_COMMIT_REF_SLUG} # i.e. master
paths:
- ./faas-cli
- ./template

# Build the whole stack using only the faas-cli
build:
script:
- docker build -f Dockerfile -t $CONTAINER_IMAGE .
- docker push $CONTAINER_IMAGE
- docker tag $CONTAINER_IMAGE $CONTAINER_TAG_IMAGE && docker push $CONTAINER_TAG_IMAGE
only:
- main
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM rust as rust_build

RUN mkdir -p /app/build/ff_fasttext
RUN mkdir -p /app/build/test_data
WORKDIR /app/build/test_data
RUN curl -L -O "http://www.sfs.uni-tuebingen.de/a3-public-data/finalfusion-fasttext/wiki/wiki.en.fifu"
WORKDIR /app/build

COPY Cargo.lock /app/build
COPY Cargo.toml /app/build

RUN apt-get update && apt-get install -y python3-pip liblapack-dev libatlas-base-dev

RUN RUSTFLAGS="-C link-args=-lcblas -llapack" cargo install finalfusion-utils --features=opq

COPY setup.py /app/build
COPY setup.cfg /app/build
COPY pyproject.toml /app/build
COPY poetry.lock /app/build
COPY requirements-dev.txt /app/build
COPY src /app/build/src
COPY ff_fasttext/__init__.py /app/build/ff_fasttext

WORKDIR /app/build

RUN pip install --no-cache-dir --upgrade -r requirements-dev.txt

RUN python3 setup.py develop

FROM python:3-bullseye

RUN mkdir -p /app/ff_fasttext

COPY --from=rust_build /app/build/ff_fasttext/_ff_fasttext.abi3.so /app/ff_fasttext
COPY --from=rust_build /app/build/test_data /app/test_data

RUN pip install poetry
WORKDIR /app

COPY setup.py /app
COPY setup.cfg /app
COPY pyproject.toml /app
COPY poetry.lock /app
COPY requirements-dev.txt /app
COPY ff_fasttext /app/ff_fasttext
# COPY taxonomy.json /app

WORKDIR /app

RUN poetry install

CMD ["poetry", "run", "uvicorn", "ff_fasttext.server:app", "--host", "0.0.0.0", "--port", "80"]
7 changes: 4 additions & 3 deletions ff_fasttext/server.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from fastapi import FastApi
import logging
from fastapi import FastAPI
from .extract import load

THRESHOLD = 0.4

def make_app(category_manager):
app = FastApi()
app = FastAPI()

@app.get('/categories')
def get_categories(query: str):
categories = category_manager.test(query.strip(), 'onyxcats')
return [
c for c in categories if c[1] > THRESHOLD
[float(c[0]), list(c[1])] for c in categories if c[0] > THRESHOLD
]

return app
Expand Down
2 changes: 0 additions & 2 deletions ff_fasttext/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import json

from .extract import append_discovered_terms_from_elasticsearch

def get_taxonomy():
with open('taxonomy.json', 'r') as f:
taxonomy = json.load(f)
Expand Down
107 changes: 44 additions & 63 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ sortedcontainers = "^2.4.0"
elasticsearch2 = "^2.5.1"
elasticsearch-dsl = "2"
click = "^8.0.3"
fastapi = "^0.73.0"
fastapi = "0.52"
pydantic = "^1.9.0"
uvicorn = "^0.17.4"
numpy = "^1.22.2"

[tool.poetry.scripts]
ff_fasttext_cli = "ff_fasttext.scripts.ff_fasttext:main"
Expand Down
10 changes: 0 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ impl FfModel {
success
}

fn embedding_similarities(
self_: PyRef<Self>,
x: PyReadonlyArrayDyn<f32>,
y: PyReadonlyArrayDyn<f32>
) -> f32 {
let py = self_.py();
let X = x.as_array();
X.sum() / (X.len() as f32)
}

fn eval(self_: PyRef<Self>, haystack: &str) -> PyResult<()> {
if let Some(embedding) = self_.embeddings.embedding(haystack) {
println!("{:#?}", embedding);
Expand Down

0 comments on commit 9621d08

Please sign in to comment.