资源说明:Responds to a git post-receive hook installed in BitBucket to notify a Heroku app that files were changed, and then updates an S3 bucket with the modified files.
# AwsUpdate # Responds to a git post-receive hook installed in BitBucket to notify a Heroku app that files were changed, and then updates an S3 bucket with the modified files. `AwsUpdate` runs under Play 2 and requires Java 7. This project is sponsored by [Micronautics Research Corporation](http://www.micronauticsresearch.com/) ## To Build ## This project uses the [AwsS3](https://github.com/mslinn/AwsS3/) library. `AwsS3` requires Java 7, therefore `AwsUpdate` also requires Play 2 to run under Java 7. For all OSes, you need to define a Java system property before you can run `AwsUpdate` locally. Edit the last line of your script that runs Play so that a new system property called `com.amazonaws.sdk.disableCertChecking` is defined. The line should look something like this: java -Dcom.amazonaws.sdk.disableCertChecking=true \ -Dsbt.ivy.home=$dir/repository \ -Dplay.home=$dir/framework \ -Dsbt.boot.properties=$dir/framework/sbt/play.boot.properties \ -jar $dir/framework/sbt/sbt-launch.jar "$@" Also make a similar change in `$PLAY_HOME/framework/build`: java ${DEBUG_PARAM} \ -Dcom.amazonaws.sdk.disableCertChecking=true \ -Xms512M -Xmx1536M -Xss1M \ -XX:+CMSClassUnloadingEnabled \ -XX:MaxPermSize=384M -Dfile.encoding=UTF8 \ -Dplay.version="${PLAY_VERSION}" \ -Dsbt.ivy.home=`dirname $0`/../repository \ -Dplay.home=`dirname $0` \ -Dsbt.boot.properties=`dirname $0`/sbt/sbt.boot.properties \ -jar `dirname $0`/sbt/sbt-launch.jar "$@" For Windows, make similar changes to `%PLAY_HOME%\play.bat` and `%PLAY_HOME%\framework\build.bat`. Run the Play app like this: cd AwsUpdate play To debug locally: play debug run To debug on Heroku, [read this](http://mikeslinn.blogspot.com/2012/09/debugging-jvm-programs-on-heroku.html). The `enableHerokuDebugging` and `disableHerokuDebugging` scripts are helpful. ## To Run ## A custom `Procfile` is provided in the application root that defines the Java system variable `com.amazonaws.sdk.disableCertChecking`, which configures the HttpClient SSL factory so the AWS SSL certificate is accepted. heroku create # create your app and take note of the autogenerated name git clone git@github.com:mslinn/AwsUpdate.git git remote add heroku git@heroku.com:cheeky-monkey-666.git # use your Heroku app name here You are encouraged to copy `conf/sample.AwsCredentials.properties` to `conf/AwsCredentials.properties`, and edit that file to reflect your AWS credentials. Define two environment variables to hold your AWS access key and your AWS secret key: source conf/AwsCredentials.properties heroku config:add accessKey=$accessKey secretKey=$secretKey If you want to access a private repository on BitBucket, define two more environment variables to hold basic authentication credentials. `conf/sample.BBCredentials.properties` should be copied to `conf/BBCredentials.properties` and edited to include your BitBucket credentials. source conf/BBCredentials.properties heroku config:add bbUserId=$userid bbPassword=$password Check that the environment variables are properly set: $ heroku config === cheeky-monkey-666 Config Vars accessKey: asdfasdf bbPassword: asfdasdf. bbUserId: asfasdf secretKey: asfdasdf Deploy the project to Heroku: git push heroku master The [web app](http://cheeky-monkey-666.herokuapp.com) should now be up and running on Heroku. Open it in your browser with: heroku open ## Git Post-Receive Service Hooks ## A Play route is dedicated to receiving updates from each remote git service. The associated controller performs the following: 1. Accepts a POST in JSON format from the remote git service describing the commit. 2. Verifies the POST to be a result of a valid commit. 3. Reads each of the committed files and store into a temporary directory. 4. Pushes new or modified content files to AWS S3, or deleted files if required. ## To Configure Repositories ## A post-receive hook must be installed on each repository that you wish to be serviced by `AwsUpdate`. For BitBucket: 1. Select the __Admin__ menu item from the repository page on `BitBucket.org`. 1. Click on the __Services__ side menu. 1. From the __Select a Service...__ pull-down menu, select __POST__ and click __Add service__. 1. Enter the URL of your instance of `AwsUpdate` on Heroku. For example: ````http://cheeky-monkey-666.herokuapp.com/bb/accept```` 1. Click on __Save settings__. ## Developer Information ## ### BitBucket POST Service ### The `acceptBB` Play 2 controller is the post-receive handler. Each time files are pushed to BitBucket, a POST can originate from the repo and can go a designated URL. For the details on the services included with Bitbucket, check out [BitBucket services](https://confluence.atlassian.com/display/BITBUCKET/Managing+bitbucket+Services). This Heroku app works with the [POST service](https://confluence.atlassian.com/display/BITBUCKET/Setting+Up+the+bitbucket+POST+Service). ### GitHub WebHook URLs Hook ### A Play 2 controller for GitHub has not yet been written. The GitHub WebHook URLs(0) service is what we need. Go to Admin / Service Hooks and pick the first entry, then enter the URL to POST to. The service description says: "We'll hit these URLs with POST requests when you push to us, passing along information about the push. More information can be found in the [Post-Receive Guide](http://help.github.com/post-receive-hooks/). The Public IP addresses for these hooks are: 207.97.227.253, 50.57.128.197, 108.171.174.178." FYI, GitHub's [service hooks](https://github.com/mslinn/HerokuTomcatAwsS3/admin/hooks) are open source, written in Ruby. They include user-written hooks into the public list. Docs are [here](https://github.com/github/github-services). ### Testing ### Forward a port to your dev machine, and define a test repo such as [awsupdatetest](https://bitbucket.org/mslinn/awsupdatetest). In your test repo, define a POST service that points to this Play app, running on your dev machine. For example: http://blah.no-ip.info:9000/bb/accept You can define multiple POST services, so that several machines can debug at the same time. This bash script makes a test commit for your convenience: #!/bin/bash # poke: a script for testing AwsUpdate post-receive hooks cd $aws/awsupdatetest date>test.html; git add -A .; git commit -m "testing"; git push
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。