|
2 | 2 | import os |
3 | 3 | import tarfile |
4 | 4 | import requests |
5 | | - |
6 | | -import boto3 |
7 | | -import json |
8 | | -from botocore.utils import fix_s3_host |
9 | | -from botocore.client import Config |
10 | | -from oauth2client.service_account import ServiceAccountCredentials |
11 | | -from gcloud.storage.client import Client |
12 | | -from azure.storage.blob import BlockBlobService |
| 5 | +import subprocess |
13 | 6 |
|
14 | 7 |
|
15 | 8 | DEBUG = os.environ.get('DEIS_DEBUG') in ('true', '1') |
@@ -38,63 +31,16 @@ def log(msg): |
38 | 31 |
|
39 | 32 |
|
40 | 33 | def download_file(tar_path): |
41 | | - if os.getenv('BUILDER_STORAGE') == "s3": |
42 | | - with open('/var/run/secrets/deis/objectstore/creds/accesskey', 'r') as access_file: |
43 | | - os.putenv('AWS_ACCESS_KEY_ID', access_file.read()) |
44 | | - with open('/var/run/secrets/deis/objectstore/creds/secretkey', 'r') as secret_file: |
45 | | - os.putenv('AWS_SECRET_ACCESS_KEY', secret_file.read()) |
46 | | - with open('/var/run/secrets/deis/objectstore/creds/region', 'r') as region_file: |
47 | | - os.putenv('AWS_DEFAULT_REGION', region_file.read()) |
48 | | - |
49 | | - bucket_name = "" |
50 | | - with open('/var/run/secrets/deis/objectstore/creds/builder-bucket', 'r') as bucket_file: |
51 | | - bucket_name = bucket_file.read() |
52 | | - |
53 | | - conn = boto3.resource('s3') |
54 | | - conn.Bucket(bucket_name).Object(tar_path).download_file('apptar') |
55 | | - |
56 | | - elif os.getenv('BUILDER_STORAGE') == "gcs": |
57 | | - bucket_name = "" |
58 | | - with open('/var/run/secrets/deis/objectstore/creds/builder-bucket', 'r') as bucket_file: |
59 | | - bucket_name = bucket_file.read() |
60 | | - scopes = ['https://www.googleapis.com/auth/devstorage.full_control'] |
61 | | - credentials = ServiceAccountCredentials.from_json_keyfile_name('/var/run/secrets/deis/objectstore/creds/key.json', scopes=scopes) |
62 | | - with open('/var/run/secrets/deis/objectstore/creds/key.json') as data_file: |
63 | | - data = json.load(data_file) |
64 | | - client = Client(credentials=credentials, project=data['project_id']) |
65 | | - client.get_bucket(bucket_name).get_blob(tar_path).download_to_filename("apptar") |
66 | | - |
67 | | - elif os.getenv('BUILDER_STORAGE') == "azure": |
68 | | - with open('/var/run/secrets/deis/objectstore/creds/accountname', 'r') as account_file: |
69 | | - accountname = account_file.read() |
70 | | - with open('/var/run/secrets/deis/objectstore/creds/accountkey', 'r') as key_file: |
71 | | - accountkey = key_file.read() |
72 | | - with open('/var/run/secrets/deis/objectstore/creds/builder-container', 'r') as container_file: |
73 | | - container_name = container_file.read() |
74 | | - block_blob_service = BlockBlobService(account_name=accountname, account_key=accountkey) |
75 | | - block_blob_service.get_blob_to_path(container_name, tar_path, 'apptar') |
76 | | - |
77 | | - else : |
78 | | - with open('/var/run/secrets/deis/objectstore/creds/accesskey', 'r') as access_file: |
79 | | - AWS_ACCESS_KEY_ID = access_file.read() |
80 | | - with open('/var/run/secrets/deis/objectstore/creds/secretkey', 'r') as secret_file: |
81 | | - AWS_SECRET_ACCESS_KEY = secret_file.read() |
82 | | - |
83 | | - AWS_DEFAULT_REGION = "us-east-1" |
84 | | - bucket_name = "git" |
85 | | - mHost = os.getenv('DEIS_MINIO_SERVICE_HOST') |
86 | | - mPort = os.getenv('DEIS_MINIO_SERVICE_PORT') |
87 | | - if mPort == "80" : |
88 | | - # If you add port 80 to the end of the endpoint_url, boto3 freaks out. |
89 | | - S3_URL = "http://"+mHost |
90 | | - else : |
91 | | - S3_URL="http://"+mHost+":"+mPort |
92 | | - |
93 | | - conn = boto3.resource('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY, region_name=AWS_DEFAULT_REGION, endpoint_url=S3_URL, config=Config(signature_version='s3v4')) |
94 | | - # stop boto3 from automatically changing the endpoint |
95 | | - conn.meta.client.meta.events.unregister('before-sign.s3', fix_s3_host) |
96 | | - |
97 | | - conn.Bucket(bucket_name).Object(tar_path).download_file('apptar') |
| 34 | + if os.getenv('BUILDER_STORAGE') == "minio": |
| 35 | + os.makedirs("/tmp/objectstore/minio") |
| 36 | + bucketFile = open('/tmp/objectstore/minio/builder-bucket', 'w') |
| 37 | + bucketFile.write('git') |
| 38 | + bucketFile.close() |
| 39 | + os.putenv('BUCKET_FILE', "/tmp/objectstore/minio/builder-bucket") |
| 40 | + elif os.getenv('BUILDER_STORAGE') in ["azure", "swift"]: |
| 41 | + os.putenv('CONTAINER_FILE', "/var/run/secrets/deis/objectstore/creds/builder-container") |
| 42 | + command = ["objstorage", "--storage-type="+os.getenv('BUILDER_STORAGE'), "download", tar_path, "apptar"] |
| 43 | + subprocess.check_call(command) |
98 | 44 |
|
99 | 45 | tar_path = os.getenv('TAR_PATH') |
100 | 46 | if tar_path: |
|
0 commit comments