| 132 | |
| 133 | |
| 134 | def main(): |
| 135 | parser = argparse.ArgumentParser( |
| 136 | description="Compile kite tool and upload to S3.") |
| 137 | parser.add_argument('--upload', action='store_true', help="upload to s3") |
| 138 | parser.add_argument('--overwrite', action='store_true', help="overwrite existing package") |
| 139 | args = parser.parse_args() |
| 140 | |
| 141 | if args.upload: |
| 142 | aws_key = os.environ['AWS_KEY'] |
| 143 | aws_secret = os.environ['AWS_SECRET'] |
| 144 | |
| 145 | workdir = tempfile.mkdtemp() |
| 146 | try: |
| 147 | tardir = os.path.join(workdir, "kite") # dir to be tarred |
| 148 | os.mkdir(tardir) |
| 149 | binpath = os.path.join(tardir, "kite") |
| 150 | cmd = "go build -o %s %s" % (binpath, "kite/main.go") |
| 151 | env = os.environ.copy() |
| 152 | env["GOARCH"] = "amd64" # we only build for 64-bit |
| 153 | env["CGO_ENABLED"] = "1" # cgo must be enabled for some functions to run correctly |
| 154 | |
| 155 | # Decide on platform (osx, linux, etc.) |
| 156 | if sys.platform.startswith("linux"): |
| 157 | env["GOOS"] = "linux" |
| 158 | platform = "linux" |
| 159 | elif sys.platform.startswith("darwin"): |
| 160 | env["GOOS"] = "darwin" |
| 161 | platform = "osx" |
| 162 | else: |
| 163 | print "%s platform is not supported" % sys.platform |
| 164 | sys.exit(1) |
| 165 | |
| 166 | # Compile kite tool source code |
| 167 | print "Building for platform: %s" % platform |
| 168 | try: |
| 169 | subprocess.check_call(cmd.split(), env=env) |
| 170 | except subprocess.CalledProcessError: |
| 171 | print "Cannot compile kite tool. Try manually." |
| 172 | sys.exit(1) |
| 173 | |
| 174 | # Get the version number from compiled binary |
| 175 | version = subprocess.check_output([binpath, "version"]).strip() |
| 176 | assert len(version.split(".")) == 3, "Please use 3-digits versioning" |
| 177 | print "Version:", version |
| 178 | |
| 179 | # Build platform specific package |
| 180 | build_function = globals()["build_%s" % platform] |
| 181 | package = build_function(binpath, version) |
| 182 | if not os.path.exists(package): |
| 183 | print "Build is unsuccessful." |
| 184 | sys.exit(1) |
| 185 | print "Generated package:", package |
| 186 | |
| 187 | # Upload to Amazon S3 |
| 188 | bucket = package_key = None |
| 189 | if args.upload: |
| 190 | print "Uploading to Amazon S3..." |
| 191 | s3_connection = boto.connect_s3(aws_key, aws_secret) |