Skip to content

Commit

Permalink
Added in deployment options to various CDNs.
Browse files Browse the repository at this point in the history
  • Loading branch information
etianen committed Jul 10, 2011
1 parent d06f673 commit 52658c2
Show file tree
Hide file tree
Showing 21 changed files with 859 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@
*.pyo
Thumbs.db
build
www
74 changes: 58 additions & 16 deletions bin/build.py
Expand Up @@ -6,8 +6,8 @@
html file and the minified html5media builds.
"""

import os, shutil, subprocess, re

import os, shutil, subprocess

API_VERSION = "1.1.4"

Expand All @@ -19,9 +19,21 @@

LIB_ROOT = os.path.join(PROJECT_ROOT, "lib")

MEDIA_ROOT = os.path.join(SRC_ROOT, "media")

BUILD_ROOT = os.path.join(PROJECT_ROOT, "build")

HTML5MEDIA_BUILD_ROOT = os.path.join(BUILD_ROOT, API_VERSION)
MEDIA_BUILD_ROOT = os.path.join(BUILD_ROOT, "media")

API_BUILD_ROOT = os.path.join(BUILD_ROOT, "api")

CDN_ROOT = os.path.join(PROJECT_ROOT, "cdn")

CDN_BUILD_ROOT = os.path.join(CDN_ROOT, API_VERSION)

CDN_APP_YAML = os.path.join(CDN_ROOT, "app.yaml")

HTML_ROOT = os.path.join(PROJECT_ROOT, "www")


def compile(filenames, outfile):
Expand All @@ -33,9 +45,10 @@ def compile(filenames, outfile):


def copy_html(filename, outfile):
"""Copies the given HTML file, substituting in the current API build version."""
"""Copies the given html file, substituting in the production deploy roots."""
with open(filename, "r", encoding="utf-8") as handle:
html = handle.read().replace("{{API_VERSION}}", API_VERSION)
html = handle.read()
html = html.replace("media/", "http://media.html5media.info/").replace("api/", "http://api.html5media.info/{}/".format(API_VERSION))
with open(outfile, "w", encoding="utf-8") as handle:
handle.write(html)

Expand All @@ -46,31 +59,60 @@ def main():
shutil.rmtree(BUILD_ROOT)
# Create the build root.
os.mkdir(BUILD_ROOT)
os.mkdir(HTML5MEDIA_BUILD_ROOT)
os.mkdir(API_BUILD_ROOT)
# Create the compiled js files.
print("Compiling javascript...")
compile((os.path.join(LIB_ROOT, "flowplayer", "flowplayer.js"),
os.path.join(LIB_ROOT, "domready", "domready.js"),
os.path.join(SRC_ROOT, "api", "html5media.js"),),
os.path.join(HTML5MEDIA_BUILD_ROOT, "html5media.min.js"))
os.path.join(API_BUILD_ROOT, "html5media.min.js"))
# Copy over the Flowplayer resources.
print("Copying SWF files...")
shutil.copy(os.path.join(LIB_ROOT, "flowplayer", "flowplayer.swf"),
os.path.join(HTML5MEDIA_BUILD_ROOT, "flowplayer.swf"))
os.path.join(API_BUILD_ROOT, "flowplayer.swf"))
shutil.copy(os.path.join(LIB_ROOT, "flowplayer", "flowplayer.controls.swf"),
os.path.join(HTML5MEDIA_BUILD_ROOT, "flowplayer.controls.swf"))
os.path.join(API_BUILD_ROOT, "flowplayer.controls.swf"))
shutil.copy(os.path.join(LIB_ROOT, "flowplayer.audio", "flowplayer.audio.swf"),
os.path.join(HTML5MEDIA_BUILD_ROOT, "flowplayer.audio.swf"))
os.path.join(API_BUILD_ROOT, "flowplayer.audio.swf"))
# Copy over the license and readme files.
print("Copying readme files...")
shutil.copy(os.path.join(PROJECT_ROOT, "LICENSE"),
os.path.join(HTML5MEDIA_BUILD_ROOT, "LICENSE"))
os.path.join(API_BUILD_ROOT, "LICENSE"))
shutil.copy(os.path.join(PROJECT_ROOT, "README.markdown"),
os.path.join(BUILD_ROOT, "README"))
# Copy over the demo page.
shutil.copytree(os.path.join(SRC_ROOT, "demo"),
os.path.join(BUILD_ROOT, "demo"))
copy_html(os.path.join(SRC_ROOT, "index.html"),
os.path.join(BUILD_ROOT, "index.html"))
copy_html(os.path.join(SRC_ROOT, "test.html"),
os.path.join(BUILD_ROOT, "test.html"))
print("Copying media files...")
shutil.copytree(os.path.join(MEDIA_ROOT),
os.path.join(MEDIA_BUILD_ROOT))
shutil.copyfile(os.path.join(SRC_ROOT, "index.html"),
os.path.join(BUILD_ROOT, "index.html"))
shutil.copyfile(os.path.join(SRC_ROOT, "test.html"),
os.path.join(BUILD_ROOT, "test.html"))
# Add the built api files to the CDN.
print("Updating the CDN...")
if os.path.exists(CDN_BUILD_ROOT):
shutil.rmtree(CDN_BUILD_ROOT)
shutil.copytree(API_BUILD_ROOT,
os.path.join(CDN_BUILD_ROOT, API_VERSION))
# Update the CDN version number.
with open(CDN_APP_YAML, "r", encoding="utf-8") as handle:
app_yaml = handle.read()
app_yaml = re.sub("^version: .+$",
"version: {}".format(API_VERSION.replace(".", "-")),
app_yaml, 0, re.MULTILINE)
with open(CDN_APP_YAML, "w", encoding="utf-8") as handle:
handle.write(app_yaml)
# Create the demo page.
print("Creating the demo page...")
if os.path.exists(HTML_ROOT):
shutil.rmtree(HTML_ROOT)
os.mkdir(HTML_ROOT)
copy_html(os.path.join(BUILD_ROOT, "index.html"),
os.path.join(HTML_ROOT, "index.html"))
copy_html(os.path.join(BUILD_ROOT, "test.html"),
os.path.join(HTML_ROOT, "test.html"))
# Compile complete!
print("Compile complete!")


if __name__ == "__main__":
Expand Down
35 changes: 35 additions & 0 deletions bin/deploy.py
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""
Deploy script for the html5media project.
This needs to be run after the build to push the new version of the app onto the relevant CDNs.
"""

import subprocess, os

from build import MEDIA_BUILD_ROOT, API_BUILD_ROOT, HTML_ROOT, CDN_ROOT


MEDIA_DEPLOY_ROOT = os.environ["HTML5MEDIA_MEDIA_DEPLOY_ROOT"]

HTML_DEPLOY_ROOT = os.environ["HTML5MEDIA_HTML_DEPLOY_ROOT"]

CDN_EMAIL = os.environ["HTML5MEDIA_CDN_EMAIL"]

CDN_PASSWORD = os.environ["HTML5MEDIA_CDN_PASSWORD"]


def main():
# Upload the media files.
print("Uploading media files...")
subprocess.call("rsync -r --exclude=.DS_Store {}/ {}".format(MEDIA_BUILD_ROOT, MEDIA_DEPLOY_ROOT), shell=True)
# Uploading the HTML files.
print("Uploading html files...")
subprocess.call("rsync -r {}/*.html {}".format(HTML_ROOT, HTML_DEPLOY_ROOT), shell=True)
# Deploy the CDN.
print("Deploying CDN...")
subprocess.call("echo {} | appcfg.py update {} --email={} --passin".format(CDN_PASSWORD, CDN_ROOT, CDN_EMAIL), shell=True)


if __name__ == "__main__":
main()

0 comments on commit 52658c2

Please sign in to comment.