Skip to content

Commit d467548

Browse files
committed
Modify update-website
Move into py folder
1 parent 15c2fa1 commit d467548

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
run: pip install boto3 PyYaml
3535

3636
- name: Run deployment script to deploy files to S# website
37-
run: python update-website.py
37+
run: python py/update-website.py
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import sys
99
import glob
1010

11+
SCRIPT_DIR = pathlib.Path(__file__).resolve().parent
12+
BASE_DIR = SCRIPT_DIR.parent # project root (website files live here)
13+
1114
# Set up region, domain name, bucket name, stack name, cloudformation file, and boto clients
1215
region = 'us-east-1'
1316
domain_name = 'derekmelder.com'
1417
stack_name = 'derekmelder-website-stack'
1518
bucket_name = 'www.' + domain_name
16-
cloudformation_file = 'website.yml'
19+
cloudformation_file = BASE_DIR / 'website.yml'
1720

1821
s3_client = boto3.client('s3', region_name=region)
1922
cloudformation_client = boto3.client('cloudformation', region_name=region)
@@ -23,6 +26,8 @@ class MyStr(str):
2326

2427
def upload_files(file_array):
2528
for file in file_array:
29+
file_path = pathlib.Path(file).resolve()
30+
s3_key = file_path.relative_to(BASE_DIR).as_posix()
2631
content_type = ''
2732
match MyStr(file):
2833
case '.doc':
@@ -31,13 +36,14 @@ def upload_files(file_array):
3136
content_type = 'application/pdf'
3237
case '.html':
3338
content_type = 'text/html'
34-
s3_client.upload_file(Filename=file, Key=file, Bucket=bucket_name, ExtraArgs={'ContentType': content_type})
39+
s3_client.upload_file(Filename=file, Key=s3_key, Bucket=bucket_name, ExtraArgs={'ContentType': content_type})
3540

3641
# Handle uploading files in directories and subdirectories
3742
def upload_files_from_dir(path):
38-
for subdir, dirs, files in os.walk(path):
43+
for subdir, dirs, files in os.walk(BASE_DIR / path):
3944
for file in files:
4045
full_file_path = os.path.join(subdir, file)
46+
full_file_path = pathlib.Path(subdir) / file
4147
full_file_path = pathlib.PureWindowsPath(full_file_path).as_posix()
4248
content_type = ''
4349
match MyStr(full_file_path):
@@ -143,6 +149,7 @@ def upload_files_from_dir(path):
143149
root_files = []
144150
for files in types:
145151
root_files.extend(glob.glob(files))
152+
root_files.extend(glob.glob(str(BASE_DIR / files)))
146153
upload_files(root_files)
147154

148155
# Upload files in subdirectories
@@ -154,4 +161,5 @@ def upload_files_from_dir(path):
154161
upload_files_from_dir('isotope')
155162
upload_files_from_dir('js')
156163
upload_files_from_dir('media')
164+
upload_files_from_dir('py')
157165
upload_files_from_dir('video')

0 commit comments

Comments
 (0)