Skip to content
This repository was archived by the owner on Jun 29, 2021. It is now read-only.

Commit 9e5ce71

Browse files
author
Keerthan Mala
committed
feat(swift):Add support for swift object storage
1 parent fc7d11b commit 9e5ce71

2 files changed

Lines changed: 15 additions & 66 deletions

File tree

rootfs/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN apt-get update \
1313
python-dev \
1414
--no-install-recommends \
1515
&& curl -sSL https://bootstrap.pypa.io/get-pip.py | python - pip==8.1.1 \
16-
&& pip install --disable-pip-version-check --no-cache-dir boto3==1.2.6 gcloud==0.11.0 azure-storage==0.30.0 docker-py==1.7.2 \
16+
&& pip install --disable-pip-version-check --no-cache-dir docker-py==1.7.2 \
1717
&& apt-get remove -y --auto-remove --purge \
1818
gcc \
1919
libffi-dev \
@@ -23,6 +23,9 @@ RUN apt-get update \
2323
&& apt-get clean \
2424
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/man /usr/share/doc
2525

26+
ADD https://storage.googleapis.com/object-storage-cli/bb8e054/objstorage-bb8e054-linux-amd64 /bin/objstorage
27+
RUN chmod +x /bin/objstorage
28+
2629
COPY . /
2730

2831
CMD ["python", "/deploy.py"]

rootfs/deploy.py

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
import os
33
import tarfile
44
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
136

147

158
DEBUG = os.environ.get('DEIS_DEBUG') in ('true', '1')
@@ -38,63 +31,16 @@ def log(msg):
3831

3932

4033
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)
9844

9945
tar_path = os.getenv('TAR_PATH')
10046
if tar_path:

0 commit comments

Comments
 (0)