generated from MITLibraries/python-cli-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd3a0c8
commit d85185a
Showing
9 changed files
with
514 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import logging | ||
import subprocess | ||
from typing import TYPE_CHECKING | ||
|
||
import boto3 | ||
from botocore.exceptions import ClientError | ||
|
||
if TYPE_CHECKING: | ||
from mypy_boto3_s3.client import S3Client | ||
|
||
from abdiff.config import Config | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
CONFIG = Config() | ||
|
||
|
||
def download_input_files(input_files: str): | ||
s3_client = boto3.client("s3") | ||
|
||
for input_file in input_files: | ||
if check_object_exists(CONFIG.TIMDEX_BUCKET, input_file, s3_client): | ||
continue | ||
|
||
logger.info(f"Downloading input file from {CONFIG.TIMDEX_BUCKET}: {input_file}") | ||
copy_command = ["aws", "s3", "cp", input_file, "-"] | ||
upload_command = [ | ||
"aws", | ||
"s3", | ||
"cp", | ||
"--endpoint-url", | ||
CONFIG.aws_endpoint_url, | ||
"--profile", | ||
"minio", | ||
"-", | ||
input_file, | ||
] | ||
|
||
try: | ||
copy_process = subprocess.run( | ||
args=copy_command, check=True, capture_output=True | ||
) | ||
subprocess.run( | ||
args=upload_command, | ||
check=True, | ||
input=copy_process.stdout, | ||
) | ||
except subprocess.CalledProcessError: | ||
logger.exception(f"Failed to download input file: {input_file}") | ||
|
||
|
||
def check_object_exists(bucket: str, input_file: str, s3_client: S3Client) -> bool: | ||
key = input_file.replace(f"s3://{bucket}/", "") | ||
try: | ||
s3_client.head_object(Bucket=bucket, Key=key) | ||
return True | ||
except ClientError as exception: | ||
if exception.response["Error"]["Code"] == "NoSuchKey": | ||
return False | ||
logger.exception(f"Cannot determine if object exists for key {key}.") | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Settings and configurations that are common for all containers | ||
x-minio-common: &minio-common | ||
image: quay.io/minio/minio:RELEASE.2024-10-29T16-01-48Z | ||
command: server --console-address ":9001" /mnt/data | ||
ports: | ||
- "9000:9000" # API port | ||
- "9001:9001" # Console port | ||
environment: | ||
MINIO_ROOT_USER: minioadmin | ||
MINIO_ROOT_PASSWORD: minioadmin | ||
healthcheck: | ||
test: ["CMD", "mc", "ready", "local"] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
services: | ||
minio: | ||
<<: *minio-common | ||
volumes: | ||
# TODO: env var for absolute path | ||
- ./data:/mnt/data | ||
|