-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload.py
executable file
·65 lines (56 loc) · 1.42 KB
/
upload.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import os
import boto3
import sys
session = boto3.session.Session()
#############
# Functions #
#############
# If the upload cannot even be run just fail the job
def core_fail(message):
print(message)
sys.exit(1)
#############
# Variables #
#############
global region
global bucket
region = 'us-east-1'
bucket = 'ci-tests.linuxserver.io'
# Make sure all needed env variables are set
def check_env():
try:
global S3_key
global S3_secret
global file_name
global destination
global mimetype
mimetype = os.environ["MIMETYPE"]
destination = os.environ["DESTINATION"]
file_name = os.environ["FILE_NAME"]
S3_key = os.environ["ACCESS_KEY"]
S3_secret = os.environ["SECRET_KEY"]
except KeyError as error:
core_fail(str(error) + ' is not set in ENV')
# Upload blob to DO Spaces
def blob_upload():
print('Uploading File')
spaces = session.client(
's3',
region_name=region,
aws_access_key_id=S3_key,
aws_secret_access_key=S3_secret)
# File upload
try:
spaces.upload_file(
'/mnt/' + file_name,
bucket,
destination,
ExtraArgs={'ContentType': mimetype, 'ACL': "public-read"})
except Exception as error:
core_fail('Upload Error ' + str(error))
##############
# Main Logic #
##############
check_env()
blob_upload()