|
5 | 5 | from tempfile import TemporaryFile |
6 | 6 | from urllib.parse import urlparse |
7 | 7 |
|
| 8 | +from colorama import Fore, Style |
| 9 | + |
| 10 | +import feast |
| 11 | +from feast.constants import AWS_LAMBDA_FEATURE_SERVER_IMAGE |
8 | 12 | from feast.errors import S3RegistryBucketForbiddenAccess, S3RegistryBucketNotExist |
9 | 13 | from feast.infra.passthrough_provider import PassthroughProvider |
10 | 14 | from feast.protos.feast.core.Registry_pb2 import Registry as RegistryProto |
|
13 | 17 |
|
14 | 18 |
|
15 | 19 | class AwsProvider(PassthroughProvider): |
16 | | - """ |
17 | | - This class only exists for backwards compatibility. |
18 | | - """ |
| 20 | + def _upload_docker_image(self) -> None: |
| 21 | + import base64 |
| 22 | + |
| 23 | + try: |
| 24 | + import boto3 |
| 25 | + except ImportError as e: |
| 26 | + from feast.errors import FeastExtrasDependencyImportError |
| 27 | + |
| 28 | + raise FeastExtrasDependencyImportError("aws", str(e)) |
| 29 | + |
| 30 | + try: |
| 31 | + import docker |
| 32 | + from docker.errors import APIError |
| 33 | + except ImportError as e: |
| 34 | + from feast.errors import FeastExtrasDependencyImportError |
19 | 35 |
|
20 | | - pass |
| 36 | + raise FeastExtrasDependencyImportError("docker", str(e)) |
| 37 | + |
| 38 | + try: |
| 39 | + docker_client = docker.from_env() |
| 40 | + except APIError: |
| 41 | + from feast.errors import DockerDaemonNotRunning |
| 42 | + |
| 43 | + raise DockerDaemonNotRunning() |
| 44 | + |
| 45 | + print( |
| 46 | + f"Pulling remote image {Style.BRIGHT + Fore.GREEN}{AWS_LAMBDA_FEATURE_SERVER_IMAGE}{Style.RESET_ALL}:" |
| 47 | + ) |
| 48 | + docker_client.images.pull(AWS_LAMBDA_FEATURE_SERVER_IMAGE) |
| 49 | + |
| 50 | + version = ".".join(feast.__version__.split(".")[:3]) |
| 51 | + repository_name = f"feast-python-server-{version}" |
| 52 | + ecr_client = boto3.client("ecr") |
| 53 | + try: |
| 54 | + print( |
| 55 | + f"Creating remote ECR repository {Style.BRIGHT + Fore.GREEN}{repository_name}{Style.RESET_ALL}:" |
| 56 | + ) |
| 57 | + response = ecr_client.create_repository(repositoryName=repository_name) |
| 58 | + repository_uri = response["repository"]["repositoryUri"] |
| 59 | + except ecr_client.exceptions.RepositoryAlreadyExistsException: |
| 60 | + response = ecr_client.describe_repositories( |
| 61 | + repositoryNames=[repository_name] |
| 62 | + ) |
| 63 | + repository_uri = response["repositories"][0]["repositoryUri"] |
| 64 | + |
| 65 | + auth_token = ecr_client.get_authorization_token()["authorizationData"][0][ |
| 66 | + "authorizationToken" |
| 67 | + ] |
| 68 | + username, password = base64.b64decode(auth_token).decode("utf-8").split(":") |
| 69 | + |
| 70 | + ecr_address = repository_uri.split("/")[0] |
| 71 | + docker_client.login(username=username, password=password, registry=ecr_address) |
| 72 | + |
| 73 | + image = docker_client.images.get(AWS_LAMBDA_FEATURE_SERVER_IMAGE) |
| 74 | + image_remote_name = f"{repository_uri}:{version}" |
| 75 | + print( |
| 76 | + f"Pushing local image to remote {Style.BRIGHT + Fore.GREEN}{image_remote_name}{Style.RESET_ALL}:" |
| 77 | + ) |
| 78 | + image.tag(image_remote_name) |
| 79 | + docker_client.api.push(repository_uri, tag=version) |
21 | 80 |
|
22 | 81 |
|
23 | 82 | class S3RegistryStore(RegistryStore): |
|
0 commit comments