|
| 1 | +# This script is used for syncing parts of the rustup dist server |
| 2 | +# between the dev environment (dev-static.rlo), the local machine, and |
| 3 | +# the prod environment (static.rlo). It's used during the deployment process. |
| 4 | +# |
| 5 | +# It does only a few things: |
| 6 | +# |
| 7 | +# * Sync dev bins to local host: |
| 8 | +# python sync-dist.py dev-to-local |
| 9 | +# |
| 10 | +# * Sync local bins to dev archives |
| 11 | +# python sync-dist.py local-to-dev-archives 0.2.0 |
| 12 | +# |
| 13 | +# * Sync local bins to prod |
| 14 | +# python sync-dist.py local-to-prod |
| 15 | +# |
| 16 | +# * Sync local bins to prod archives |
| 17 | +# python sync-dist.py local-to-prod-archives 0.2.0 |
| 18 | + |
| 19 | +import sys |
| 20 | +import os |
| 21 | +import subprocess |
| 22 | +import shutil |
| 23 | + |
| 24 | +def usage(): |
| 25 | + print ("usage: sync-dist dev-to-local [--live-run]\n" |
| 26 | + " sync-dist local-to-dev-archives $version [--live-run]\n" |
| 27 | + " sync-dist local-to-prod-archives $version [--live-run]\n" |
| 28 | + " sync-dist local-to-prod [--live-run]\n") |
| 29 | + sys.exit(1) |
| 30 | + |
| 31 | +command = None |
| 32 | +archive_version = None |
| 33 | +live_run = False |
| 34 | + |
| 35 | +if len(sys.argv) < 2: |
| 36 | + usage() |
| 37 | + |
| 38 | +command = sys.argv[1] |
| 39 | + |
| 40 | +if not command in ["dev-to-local", |
| 41 | + "local-to-dev-archives", |
| 42 | + "local-to-prod-archives", |
| 43 | + "local-to-prod"]: |
| 44 | + usage() |
| 45 | + |
| 46 | +if "archives" in command: |
| 47 | + if len(sys.argv) < 3: |
| 48 | + usage() |
| 49 | + archive_version = sys.argv[2] |
| 50 | + |
| 51 | +if "--live-run" in sys.argv: |
| 52 | + live_run = True |
| 53 | + |
| 54 | +dev_s3_bucket = "dev-static-rust-lang-org" |
| 55 | +prod_s3_bucket = "static-rust-lang-org" |
| 56 | + |
| 57 | +s3_bucket = dev_s3_bucket |
| 58 | +if "prod" in command: |
| 59 | + s3_bucket = prod_s3_bucket |
| 60 | + |
| 61 | +print "s3 bucket: " + s3_bucket |
| 62 | +print "command: " + command |
| 63 | +print "archive version: " + str(archive_version) |
| 64 | + |
| 65 | +# First, deal with the binaries |
| 66 | + |
| 67 | +s3cmd = None |
| 68 | +if command == "dev-to-local": |
| 69 | + if os.path.exists("local-rustup/dist"): |
| 70 | + shutil.rmtree("local-rustup/dist") |
| 71 | + os.makedirs("local-rustup/dist") |
| 72 | + s3cmd = "s3cmd sync s3://{}/rustup/dist/ ./local-rustup/dist/".format(s3_bucket) |
| 73 | +elif command == "local-to-dev-archives" \ |
| 74 | + or command == "local-to-prod-archives": |
| 75 | + s3cmd = "s3cmd sync ./local-rustup/dist/ s3://{}/rustup/archive/{}/".format(s3_bucket, archive_version) |
| 76 | +elif command == "local-to-prod": |
| 77 | + s3cmd = "s3cmd sync ./local-rustup/dist/ s3://{}/rustup/dist/".format(s3_bucket) |
| 78 | +else: |
| 79 | + sys.exit(1) |
| 80 | + |
| 81 | +print "s3 command: {}".format(s3cmd) |
| 82 | +print |
| 83 | + |
| 84 | +def run_s3cmd(command): |
| 85 | + s3cmd = command.split(" ") |
| 86 | + |
| 87 | + if not live_run: |
| 88 | + s3cmd += ["--dry-run"] |
| 89 | + |
| 90 | + # These are old installer names for compatibility. They don't need to |
| 91 | + # be touched ever again. |
| 92 | + s3cmd += ["--exclude=*rustup-setup*"] |
| 93 | + |
| 94 | + subprocess.check_call(s3cmd) |
| 95 | + |
| 96 | +run_s3cmd(s3cmd) |
| 97 | + |
| 98 | +# Next deal with the rustup-init.sh script and website |
| 99 | + |
| 100 | +if command == "dev-to-local": |
| 101 | + if os.path.exists("local-rustup/rustup-init.sh"): |
| 102 | + os.remove("local-rustup/rustup-init.sh") |
| 103 | + run_s3cmd("s3cmd get s3://{}/rustup/rustup-init.sh ./local-rustup/rustup-init.sh" |
| 104 | + .format(s3_bucket)) |
| 105 | + if os.path.exists("local-rustup/www"): |
| 106 | + shutil.rmtree("local-rustup/www") |
| 107 | + os.makedirs("local-rustup/www") |
| 108 | + run_s3cmd("s3cmd sync s3://{}/rustup/www/ ./local-rustup/www/" |
| 109 | + .format(s3_bucket)) |
| 110 | + |
| 111 | +if command == "local-to-prod": |
| 112 | + run_s3cmd("s3cmd put ./local-rustup/rustup-init.sh s3://{}/rustup/rustup-init.sh" |
| 113 | + .format(s3_bucket)) |
| 114 | + run_s3cmd("s3cmd sync ./local-rustup/www/ s3://{}/rustup/www/" |
| 115 | + .format(s3_bucket)) |
0 commit comments