Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile for GCP CloudRun FeatureServer #1887

Merged
merged 3 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions sdk/python/feast/infra/feature_servers/gcp_cloudrun/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM python:3.9-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME

# Copy app handler code
COPY sdk/python/feast/infra/feature_servers/gcp_cloudrun/app.py ./app.py

# Copy necessary parts of the Feast codebase
COPY sdk/python ./sdk/python
COPY protos ./protos
COPY README.md ./README.md

# Install production dependencies.
RUN pip install --no-cache-dir \
-e 'sdk/python[gcp,redis]' \
-r ./sdk/python/feast/infra/feature_servers/gcp_cloudrun/requirements.txt

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn -k uvicorn.workers.UvicornWorker --bind :$PORT --workers 1 --threads 8 --timeout 0 app:app
24 changes: 24 additions & 0 deletions sdk/python/feast/infra/feature_servers/gcp_cloudrun/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import base64
import os
import tempfile
from pathlib import Path

from feast import FeatureStore
from feast.constants import FEATURE_STORE_YAML_ENV_NAME
from feast.feature_server import get_app

# Load RepoConfig
config_base64 = os.environ[FEATURE_STORE_YAML_ENV_NAME]
config_bytes = base64.b64decode(config_base64)

# Create a new unique directory for writing feature_store.yaml
repo_path = Path(tempfile.mkdtemp())

with open(repo_path / "feature_store.yaml", "wb") as f:
f.write(config_bytes)

# Initialize the feature store
store = FeatureStore(repo_path=str(repo_path.resolve()))

# Create the FastAPI app
app = get_app(store)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the only diff between this and the aws lambda app the fact that that one uses mangum?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe that is the only difference in the app.py file.

20 changes: 20 additions & 0 deletions sdk/python/feast/infra/feature_servers/gcp_cloudrun/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pydantic import StrictBool
from pydantic.typing import Literal

from feast.repo_config import FeastConfigBaseModel


class GcpCloudRunFeatureServerConfig(FeastConfigBaseModel):
"""Feature server config for GCP CloudRun."""

type: Literal["gcp_cloudrun"] = "gcp_cloudrun"
"""Feature server type selector."""

enabled: StrictBool = False
"""Whether the feature server should be launched."""

public: StrictBool = True
"""Whether the endpoint should be publicly accessible."""
Comment on lines +13 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used anywhere?

Copy link
Member Author

@judahrand judahrand Oct 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume so? They are defined as the required configuration parameters in the AWS Lambda RFC. I assume we'd want to follow the same interface?

image


auth: Literal["none", "api-key"] = "none"
"""Authentication method for the endpoint."""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gunicorn
1 change: 1 addition & 0 deletions sdk/python/feast/repo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

FEATURE_SERVER_CONFIG_CLASS_FOR_TYPE = {
"aws_lambda": "feast.infra.feature_servers.aws_lambda.config.AwsLambdaFeatureServerConfig",
"gcp_cloudrun": "feast.infra.feature_servers.gcp_cloudrun.config.GcpCloudRunFeatureServerConfig",
}


Expand Down