gitでphpアプリをbeanstalkにdeployしてみた
先日BeanstalkのPHP&gitでのdeploy対応が発表されたので、まずは普通の使い方を試してみた。
次にレポジトリの初期化と、AWSのレポジトリセットアップを行う。
~/work $ mkdir php5 ~/work $ cd php5 ~/work/php5 $ git init Initialized empty Git repository in /Users/motomats/work/php5/.git/ ~/work/php5 $ AWSDevTools-RepositorySetup.sh ~/work/php5 $ git aws.config AWS Access Key: ACCESSKEY AWS Secret Key: SECRETKEY AWS Region [default to us-east-1]: AWS Host [default to git.elasticbeanstalk.us-east-1.amazonaws.com]: AWS Elastic Beanstalk Application: php5 AWS Elastic Beanstalk Environment: php5test
モックアップを用意します
~/work/php5 $ cat > index.php <?php echo "Hello Beanstalk!\n"; ?> ~/work/php5 $ php index.php Hello World!
コミットしてプッシュしてみます
~/work/php5 $ git add . ~/work/php5 $ git commit -m "1st commit" [master (root-commit) 0a9046b] 1st commit 1 files changed, 3 insertions(+), 0 deletions(-) create mode 100644 index.php ~/work/php5 $ git aws.push Counting objects: 3, done. Writing objects: 100% (3/3), 235 bytes, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: error: Unable to deploy application version: No Environment found for EnvironmentName = 'php5test'. remote: To https://ACCESSKEY:SIGNATURE@git.elasticbeanstalk.us-east-1.amazonaws.com/repos/70687035/php5 + c984ea1...0a9046b HEAD -> master (forced update)
おっと、まだphp5testというEnvironmentは存在しないので、deployに失敗してしまいました。AWS Management Consoleから作成してみましょう。
動作確認
動きました!
~/work/php5 $ curl http://php5test.elasticbeanstalk.com/ Hello Benastalk!
コンテンツ更新
コンテンツを更新してみましょう。「!」が1つじゃ足りないぞ、というわけで足してみました。
~/work/php5 $ git diff diff --git a/index.php b/index.php index bdad05b..59128c1 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,3 @@ <?php -echo "Hello Beanstalk!\n"; +echo "Hello Beanstalk!!!!\n"; ?> ~/work/php5 $ git commit -am 'we are excited!!!!' [master 71d6bba] we are excited!!!! 1 files changed, 1 insertions(+), 1 deletions(-) ~/work/php5 $ git aws.push Counting objects: 5, done. Writing objects: 100% (3/3), 279 bytes, done. Total 3 (delta 0), reused 0 (delta 0) remote: To https://ACCESSKEY:SIGNATURE@git.elasticbeanstalk.us-east-1.amazonaws.com/repos/70687035/php5test 67d2592..71d6bba HEAD -> master ~/work/php5 $ curl http://php5test.elasticbeanstalk.com Hello Beanstalk!!!!
おわりに
非常に楽にコンテンツが更新できていいですね。是非お試しください。