1
- script_content = ''' #!/usr/bin/env python3
1
+ #!/usr/bin/env python3
2
2
"""
3
3
Deploy Flex Manual to S3
4
4
Replaces the deploy-flex-manual Makefile target with staging/production/sandbox support
10
10
import sys
11
11
from pathlib import Path
12
12
13
-
14
13
def run_command (cmd , check = True ):
15
14
"""Run a shell command and return the result"""
16
15
print (f"Running: { ' ' .join (cmd )} " )
@@ -21,46 +20,33 @@ def run_command(cmd, check=True):
21
20
print (result .stderr , file = sys .stderr )
22
21
return result
23
22
24
-
25
23
def deploy_flex_manual (environment , branch = None , aws_profile = None , flex_manual_prefix = "flex-manual" ):
26
24
"""Deploy flex manual to S3"""
27
-
28
25
# Environment-specific bucket configuration
29
26
buckets = {
30
27
"sandbox" : "sandbox.docs" , # Your current sandbox bucket
31
- "staging": "opentrons.staging.docs", # Replace with your staging bucket
32
- "production": "opentrons.production.docs" # Replace with your production bucket
28
+ "staging" : "opentrons.staging.docs" , # Replace with your staging bucket
29
+ "production" : "opentrons.production.docs" # Replace with your production bucket
33
30
}
34
-
35
31
if environment not in buckets :
36
32
print (f"Error: Environment must be one of { list (buckets .keys ())} " )
37
33
sys .exit (1 )
38
-
39
34
bucket = buckets [environment ]
40
-
41
35
# Default branch based on environment
42
36
if branch is None :
43
- if environment == "sandbox":
44
- branch = "edge"
45
- elif environment == "staging":
46
- branch = "edge"
47
- else: # production
48
- branch = "main"
49
-
37
+ branch = "edge"
50
38
# Check if we're in CI
51
39
is_ci = os .getenv ("CI" ) is not None
52
40
if is_ci :
53
41
print ("Running in CI environment" )
54
42
elif aws_profile is None :
55
43
print ("Warning: AWS_PROFILE not set. Make sure you have AWS credentials configured." )
56
-
57
44
# Verify source directory exists
58
45
source_dir = Path (flex_manual_prefix ) / "site"
59
46
if not source_dir .exists ():
60
47
print (f"Error: Source directory { source_dir } does not exist." )
61
48
print ("Make sure you've run 'make build-flex-manual' first." )
62
49
sys .exit (1 )
63
-
64
50
# Build S3 sync command
65
51
s3_path = f"s3://{ bucket } /{ branch } /{ flex_manual_prefix } /"
66
52
cmd = [
@@ -70,29 +56,23 @@ def deploy_flex_manual(environment, branch=None, aws_profile=None, flex_manual_p
70
56
"--delete" ,
71
57
"--acl" , "public-read"
72
58
]
73
-
74
59
# Add AWS profile if specified
75
60
if aws_profile :
76
61
cmd .extend (["--profile" , aws_profile ])
77
-
78
62
print (f"Deploying to { environment } environment:" )
79
63
print (f" Bucket: { bucket } " )
80
64
print (f" Branch: { branch } " )
81
65
print (f" S3 Path: { s3_path } " )
82
-
83
66
try :
84
67
run_command (cmd )
85
68
print (f"✅ Successfully deployed to { environment } !" )
86
-
87
69
# Print the URL where it's deployed
88
70
url = f"https://{ bucket } /{ branch } /{ flex_manual_prefix } /"
89
71
print (f"📍 Deployed to: { url } " )
90
-
91
72
except subprocess .CalledProcessError as e :
92
73
print (f"❌ Deployment failed with exit code { e .returncode } " )
93
74
sys .exit (1 )
94
75
95
-
96
76
def main ():
97
77
parser = argparse .ArgumentParser (description = "Deploy Flex Manual to S3" )
98
78
parser .add_argument (
@@ -102,7 +82,7 @@ def main():
102
82
)
103
83
parser .add_argument (
104
84
"--branch" ,
105
- help="Branch name (defaults to 'edge' for sandbox/staging, 'main' for production )"
85
+ help = "Branch name (defaults to 'edge')"
106
86
)
107
87
parser .add_argument (
108
88
"--aws-profile" ,
@@ -113,26 +93,14 @@ def main():
113
93
default = "flex-manual" ,
114
94
help = "Flex manual prefix directory (default: flex-manual)"
115
95
)
116
-
117
96
args = parser .parse_args ()
118
-
119
- # Use AWS_PROFILE env var if not specified
120
97
aws_profile = args .aws_profile or os .getenv ("AWS_PROFILE" )
121
-
122
98
deploy_flex_manual (
123
99
environment = args .environment ,
124
100
branch = args .branch ,
125
101
aws_profile = aws_profile ,
126
102
flex_manual_prefix = args .flex_manual_prefix
127
103
)
128
104
129
-
130
105
if __name__ == "__main__" :
131
- main()
132
- '''
133
-
134
- # Write the script to a file
135
- with open ('deploy_flex_manual.py' , 'w' ) as f :
136
- f .write (script_content )
137
-
138
- print ("Updated deploy_flex_manual.py with sandbox support" )
106
+ main ()
0 commit comments