-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy paths3
executable file
·46 lines (37 loc) · 1.05 KB
/
s3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- mode:python; -*-
""" Script for storing build results
"""
from pathlib import Path
import boto3
import click
import os
import sys
import json
import operator
import mimetypes
session = boto3.Session(profile_name="default", region_name="us-east-1")
s3 = session.client("s3")
@click.group()
def cli():
pass
@cli.command()
@click.option("--bucket", required=True, help="s3 bucket to use", default="jenkaas")
@click.argument("src")
@click.argument("dst")
def cp(bucket, src, dst):
""" pushes files to s3
"""
job_id = os.environ.get("JOB_ID", None)
if not job_id:
click.echo(" job id not found, exiting")
sys.exit(1)
if not Path(src).exists():
click.echo(f" {src} file not found, exiting.")
sys.exit(1)
click.echo(f"Uploading {src} to s3://{bucket}/{job_id}/{dst}")
context_type = mimetypes.guess_type(src)[0]
if not context_type:
context_type = 'text/plain'
s3.upload_file(src, bucket, f"{job_id}/{dst}", ExtraArgs={'ContentType': context_type})
if __name__ == "__main__":
cli()