Skip to content

Commit 00c2ef5

Browse files
authored
Merge pull request #343 from 4dn-dcic/vpc
Vpc
2 parents d32a1f3 + 3813ff0 commit 00c2ef5

File tree

13 files changed

+196
-158
lines changed

13 files changed

+196
-158
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# virtualenv bin directory
2+
*/bin/
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[odc]

awsf3-docker/Dockerfile

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RUN apt update -y && apt upgrade -y && apt install -y \
3838
nodejs
3939

4040
RUN ln -s /usr/bin/python3.8 /usr/bin/python
41-
RUN ln -s /usr/bin/pip3 /usr/bin/pip
41+
#RUN ln -s /usr/bin/pip3 /usr/bin/pip
4242

4343
WORKDIR /usr/local/bin
4444

@@ -51,23 +51,21 @@ RUN apt-get update -y \
5151
&& apt-get install -y docker-ce
5252

5353
# singularity
54-
RUN wget https://golang.org/dl/go1.15.3.linux-amd64.tar.gz && \
55-
tar -xzf go1.15.3.linux-amd64.tar.gz && \
56-
rm go1.15.3.linux-amd64.tar.gz
57-
RUN export SINGULARITY_VERSION=3.3.0 && \
54+
RUN wget https://golang.org/dl/go1.16.6.linux-amd64.tar.gz && \
55+
tar -xzf go1.16.6.linux-amd64.tar.gz && \
56+
rm go1.16.6.linux-amd64.tar.gz
57+
RUN export SINGULARITY_VERSION=3.8.1 && \
5858
export PATH=/usr/local/bin/go/bin/:$PATH && \
59-
wget https://github.com/sylabs/singularity/releases/download/v${SINGULARITY_VERSION}/singularity-${SINGULARITY_VERSION}.tar.gz && \
60-
tar -xzf singularity-${SINGULARITY_VERSION}.tar.gz && \
61-
rm singularity-${SINGULARITY_VERSION}.tar.gz && \
62-
cd singularity && \
59+
wget https://github.com/sylabs/singularity/releases/download/v${SINGULARITY_VERSION}/singularity-ce-${SINGULARITY_VERSION}.tar.gz && \
60+
tar -xzf singularity-ce-${SINGULARITY_VERSION}.tar.gz && \
61+
rm singularity-ce-${SINGULARITY_VERSION}.tar.gz && \
62+
cd singularity-ce-${SINGULARITY_VERSION} && \
6363
./mconfig && \
6464
make -C ./builddir && \
6565
make -C ./builddir install && \
6666
cd .. && \
6767
rm -rf go && \
68-
mv singularity/singularity singularity2 && \
69-
rm -rf singularity && \
70-
mv singularity2 singularity
68+
rm -rf singularity-ce-${SINGULARITY_VERSION}
7169

7270
# goofys
7371
# RUN curl -O -L http://bit.ly/goofys-latest && chmod +x goofys-latest # latest is not latest

awsf3/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def args(self):
4444
'help': "execution metadata file (output json of cwltool / cromwell)"},
4545
{'flag': ["-m", "--md5file"], 'help': "text file storing md5 values for output files"},
4646
{'flag': ["-o", "--output-json"], 'help': "output postrun json file"},
47-
{'flag': ["-L", "--language"], 'help': "language", 'default': "cwl_v1"}],
47+
{'flag': ["-L", "--language"], 'help': "language", 'default': "cwl_v1"},
48+
{'flag': ["-u", "--endpoint-url"], 'help': "s3 vpc endpoint url"}],
4849
'upload_postrun_json':
4950
[{'flag': ["-i", "--input-json"], 'help': "input postrun json file to upload to s3"}],
5051
'update_postrun_json_final':
@@ -66,8 +67,8 @@ def update_postrun_json_init(input_json, output_json):
6667
utils.update_postrun_json_init(input_json, output_json)
6768

6869

69-
def update_postrun_json_upload_output(input_json, execution_metadata_file, md5file, output_json, language):
70-
utils.update_postrun_json_upload_output(input_json, execution_metadata_file, md5file, output_json, language)
70+
def update_postrun_json_upload_output(input_json, execution_metadata_file, md5file, output_json, language, endpoint_url):
71+
utils.update_postrun_json_upload_output(input_json, execution_metadata_file, md5file, output_json, language, endpoint_url=endpoint_url)
7172

7273

7374
def upload_postrun_json(input_json):

awsf3/target.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,15 @@ def unzip_source(self):
111111
yield {'name': content_file_name, 'content': z.open(content_file_name).read()}
112112
yield None
113113

114-
def upload_to_s3(self, encrypt_s3_upload=False):
114+
def upload_to_s3(self, encrypt_s3_upload=False, endpoint_url=None):
115115
"""upload target to s3, source can be either a file or a directory."""
116116
if not self.is_valid:
117117
raise Exception('Upload Error: source / dest must be specified first')
118118
if not self.s3:
119-
self.s3 = boto3.client('s3')
119+
if endpoint_url:
120+
self.s3 = boto3.client('s3', endpoint_url=endpoint_url)
121+
else:
122+
self.s3 = boto3.client('s3')
120123
err_msg = "failed to upload output file %s to %s. %s"
121124
upload_extra_args = {}
122125
if encrypt_s3_upload:

awsf3/utils.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def determine_key_type(bucket, key, profile):
123123
# The file itself may be a prefix of another file (e.v. abc.vcf.gz vs abc.vcf.gz.tbi)
124124
# but it doesn't matter.
125125
else:
126-
return 'File'
126+
return 'File'
127127
else:
128128
# data_file is a folder
129129
return 'Folder'
@@ -217,7 +217,7 @@ def download_workflow():
217217
return
218218
local_wfdir = os.environ.get('LOCAL_WFDIR')
219219
subprocess.call(['mkdir', '-p', local_wfdir])
220-
220+
221221
if language in ['wdl', 'wdl_v1', 'wdl_draft2']:
222222
main_wf = os.environ.get('MAIN_WDL', '')
223223
wf_files = os.environ.get('WDL_FILES', '')
@@ -239,10 +239,10 @@ def download_workflow():
239239
wf_files = [wf_files]
240240
wf_files.append(main_wf)
241241
wf_url = wf_url.rstrip('/')
242-
242+
243243
print("main workflow file: %s" % main_wf)
244244
print("workflow files: " + str(wf_files))
245-
245+
246246
s3 = boto3.client('s3')
247247
for wf_file in wf_files:
248248
target = "%s/%s" % (local_wfdir, wf_file)
@@ -262,7 +262,7 @@ def download_workflow():
262262
targetdir = re.sub('[^/]+$', '', target)
263263
subprocess.call(["mkdir", "-p", targetdir])
264264
s3.download_file(Bucket=bucket_name, Key=key, Filename=target)
265-
265+
266266

267267
def read_md5file(md5file):
268268
with open(md5file, 'r') as md5_f:
@@ -340,7 +340,7 @@ def update_postrun_json_init(json_old, json_new):
340340

341341

342342
def update_postrun_json_upload_output(json_old, execution_metadata_file, md5file, json_new,
343-
language='cwl_v1', strict=True, upload=True):
343+
language='cwl_v1', strict=True, upload=True, endpoint_url=None):
344344
"""Update postrun json with output files.
345345
if strict is set false, it does not check execution metadata is required for cwl/wdl."""
346346
# read old json file and prepare postrunjson skeleton
@@ -362,18 +362,18 @@ def update_postrun_json_upload_output(json_old, execution_metadata_file, md5file
362362

363363
# upload output to S3 (this also updates postrun json)
364364
if upload:
365-
upload_output(prj)
365+
upload_output(prj, endpoint_url=endpoint_url)
366366

367367
# write to new json file
368368
write_postrun_json(json_new, prj)
369369

370370

371-
def upload_output(prj):
371+
def upload_output(prj, endpoint_url=None):
372372
# parsing output_target and uploading output files to output target
373-
upload_to_output_target(prj.Job.Output, prj.config.encrypt_s3_upload)
373+
upload_to_output_target(prj.Job.Output, prj.config.encrypt_s3_upload, endpoint_url=endpoint_url)
374374

375375

376-
def upload_to_output_target(prj_out, encrypt_s3_upload=False):
376+
def upload_to_output_target(prj_out, encrypt_s3_upload=False, endpoint_url=None):
377377
# parsing output_target and uploading output files to output target
378378
output_bucket = prj_out.output_bucket_directory
379379
output_argnames = prj_out.output_files.keys()
@@ -388,7 +388,7 @@ def upload_to_output_target(prj_out, encrypt_s3_upload=False):
388388
target.parse_custom_target(k, output_target[k])
389389
if target.is_valid:
390390
print("Target is valid. Uploading..")
391-
target.upload_to_s3(encrypt_s3_upload=encrypt_s3_upload)
391+
target.upload_to_s3(encrypt_s3_upload=encrypt_s3_upload, endpoint_url=endpoint_url)
392392
else:
393393
raise Exception("Invalid target %s -> %s: failed to upload" % k, output_target[k])
394394
else:
@@ -397,17 +397,17 @@ def upload_to_output_target(prj_out, encrypt_s3_upload=False):
397397
target.parse_cwl_target(k, output_target.get(k, ''), prj_out.output_files)
398398
if target.is_valid:
399399
print("Target is valid. Uploading..")
400-
target.upload_to_s3(encrypt_s3_upload=encrypt_s3_upload)
400+
target.upload_to_s3(encrypt_s3_upload=encrypt_s3_upload, endpoint_url=endpoint_url)
401401
prj_out.output_files[k].add_target(target.dest)
402-
402+
403403
# upload secondary files
404404
secondary_output_files = prj_out.output_files[k].secondaryFiles
405405
if secondary_output_files:
406406
stlist = SecondaryTargetList(output_bucket)
407407
stlist.parse_target_values(prj_out.secondary_output_target.get(k, []))
408408
stlist.reorder_by_source([sf.path for sf in secondary_output_files])
409409
for st in stlist.secondary_targets:
410-
st.upload_to_s3(encrypt_s3_upload=encrypt_s3_upload)
410+
st.upload_to_s3(encrypt_s3_upload=encrypt_s3_upload, endpoint_url=endpoint_url)
411411
for i, sf in enumerate(secondary_output_files):
412412
sf.add_target(stlist.secondary_targets[i].dest)
413413
else:
@@ -424,9 +424,9 @@ def update_postrun_json_final(json_old, json_new, logfile=None):
424424
"""Update postrun json with status, time stamps, parsed commands,
425425
input/tmp/output sizes"""
426426
prj = read_postrun_json(json_old)
427-
427+
428428
postrun_json_final(prj, logfile=logfile)
429-
429+
430430
# write to new json file
431431
write_postrun_json(json_new, prj)
432432

tibanna/__main__.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ def args(self):
274274
'action': "store_true",
275275
'help': "Do not delete public access block from buckets" +
276276
"(this way postrunjson and metrics reports will not be public)"},
277+
{'flag': ["-t", "--subnets"],
278+
'nargs': '+',
279+
'help': "subnet IDs"},
280+
{'flag': ["-r", "--security-groups"],
281+
'nargs': '+',
282+
'help': "security groups"},
277283
{'flag': ["-q", "--quiet"],
278284
'action': "store_true",
279285
'help': "minimize standard output from deployment"}],
@@ -286,6 +292,12 @@ def args(self):
286292
{'flag': ["-g", "--usergroup"],
287293
'default': '',
288294
'help': "Tibanna usergroup for the AWS Lambda function"},
295+
{'flag': ["-t", "--subnets"],
296+
'nargs': '+',
297+
'help': "subnet IDs"},
298+
{'flag': ["-r", "--security-groups"],
299+
'nargs': '+',
300+
'help': "security groups"},
289301
{'flag': ["-q", "--quiet"],
290302
'action': "store_true",
291303
'help': "minimize standard output from deployment"}],
@@ -368,11 +380,12 @@ def args(self):
368380
}
369381

370382

371-
def deploy_core(name, suffix=None, usergroup='', quiet=False):
383+
def deploy_core(name, suffix=None, usergroup='', quiet=False, subnets=None, security_groups=None):
372384
"""
373385
New method of deploying packaged lambdas (BETA)
374386
"""
375-
API().deploy_core(name=name, suffix=suffix, usergroup=usergroup, quiet=quiet)
387+
API().deploy_core(name=name, suffix=suffix, usergroup=usergroup, subnets=subnets,
388+
security_groups=security_groups, quiet=quiet)
376389

377390

378391
def run_workflow(input_json, sfn=TIBANNA_DEFAULT_STEP_FUNCTION_NAME, jobid='', do_not_open_browser=False, sleep=3):
@@ -396,11 +409,12 @@ def setup_tibanna_env(buckets='', usergroup_tag='default', no_randomize=False,
396409

397410
def deploy_unicorn(suffix=None, no_setup=False, buckets='',
398411
no_setenv=False, usergroup='', do_not_delete_public_access_block=False,
399-
deploy_costupdater=False, quiet=False):
412+
deploy_costupdater=False, subnets=None, security_groups=None, quiet=False):
400413
"""deploy tibanna unicorn to AWS cloud"""
401414
API().deploy_unicorn(suffix=suffix, no_setup=no_setup, buckets=buckets, no_setenv=no_setenv,
402415
usergroup=usergroup, do_not_delete_public_access_block=do_not_delete_public_access_block,
403-
deploy_costupdater=deploy_costupdater, quiet=quiet)
416+
deploy_costupdater=deploy_costupdater, subnets=subnets, security_groups=security_groups,
417+
quiet=quiet)
404418

405419

406420
def add_user(user, usergroup):

tibanna/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Version information."""
22

33
# The following line *must* be the last in the module, exactly as formatted:
4-
__version__ = "1.3.1"
4+
__version__ = "1.4.1"

0 commit comments

Comments
 (0)