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