Ubuntu12.04 VPSサーバ構築手順:CI環境構築 Playframework1.2アプリケーション構築

以下のエントリシリーズのうちの1つ:CI対象となるプロジェクトの作成について。まずはPlayframework1.2ベースのアプリから。

Play1.2実行環境構築

  • 公式サイトからアーカイブファイルを入手・解凍。
  • 環境変数『PLAY_HOME』及び『PATH』に関連する値を設定。
$ pwd
/Application
$ wget http://download.playframework.org/releases/play-1.2.5.zip
$ unzip play-1.2.5.zip
$ sudo vi /Users/XXX/.bash_profile
-----------------------------
##########################
# add Playframework env.
##########################
PLAY_HOME=/Applications/play-1.2.5
#PLAY_HOME=/Applications/play-2.0.4
export PLAY_HOME
export PATH=$PATH:$PLAY_HOME
-----------------------------
$ source /Users/XXX/.bash_profile
  • 導入確認(play -v)。
$ play -v
~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.5, http://www.playframework.org
~
~ Usage: play cmd [app_path] [--options]
~ 
~ with,  new      Create a new application
~        run      Run the application in the current shell
~        help     Show play help
~
~ Invalid command: -v
~
$ 
  • アプリケーション新規作成(play new アプリケーション名)
$ play new playfw12app
~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.5, http://www.playframework.org
~
~ The new application will be created in /Applications/eclipse4.2/workspace/playfw12app
~ What is the application name? [playfw12app] 
~
~ OK, the application is created.
~ Start it with : play run playfw12app
~ Have fun!
~
$ 
  • アプリケーション起動(play run アプリケーション名)
$ play run playfw12app/
~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.5, http://www.playframework.org
~
~ Ctrl+C to stop
~ 
CompilerOracle: exclude jregex/Pretokenizer.next
Listening for transport dt_socket at address: 8000
16:05:00,759 INFO  ~ Starting /Applications/eclipse4.2/workspace/playfw12app
16:05:01,614 WARN  ~ You're running Play! in DEV mode
16:05:01,761 INFO  ~ Listening for HTTP on port 9000 (Waiting a first request to start) ...
16:05:09,783 INFO  ~ Application 'playfw12app' is now started !
  • Eclipse対応等:以下コマンド実行後、Eclipseで取り込み〜起動確認等実施。
$ play deps playfw12app/
$ play ec playfw12app/
  • Eclipse起動
    • [インポート]→[既存プロジェクトをワークスペースへ]→上記play ecコマンドを実行したプロジェクトを指定し取り込み→リフレッシュ
  • EclipseのPlayプラグインは以下のファイルを所定箇所に配置し、再起動する事で有効となる。
    • 対象ファイル:/Applications/play-1.2.5/support/eclipse/org.playframework.playclipse_0.7.0.jar (PLAY_HOME配下の指定ファイル)
    • 配置場所:/Applications/eclipse4.2/dropins (Eclipse/dropins配下にコピー)

Play1.2テスト実行

『play auto-test』で実行が可能。

初期状態でテストしてみる。(play auto-test アプリケーション名)

$ play auto-test playfw12app/
~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.5, http://www.playframework.org
~ framework ID is test
~
~ Running in test mode
~ Ctrl+C to stop
~ 
~ Deleting /Applications/eclipse4.2/workspace/playfw12app/tmp
~
CompilerOracle: exclude jregex/Pretokenizer
.next
Listening for transport dt_socket at address: 8000
16:56:44,939 INFO  ~ Starting /Applications/eclipse4.2/workspace/playfw12app
16:56:46,000 WARN  ~ You're running Play! in DEV mode
~
~ Go to http://localhost:9000/@tests to run the tests
~
~ 4 tests to run:
~
~ AnotherPlayUnitTest...     PASSED     1s
~ BasicTest...               PASSED     0s
~ ApplicationTest...         PASSED     0s
~ Application...             PASSED     5s
~
~ All tests passed
~
$ 

テスト実行結果は test-result/ フォルダに生成される。

$ pwd
/Applications/eclipse4.2/workspace/playfw12app/test-result
$ 
$ ll
AnotherPlayUnitTest.class.passed.html
Application.test.html.passed.html
ApplicationTest.class.passed.html
BasicTest.class.passed.html
TEST-BasicTest.xml
TEST-AnotherPlayUnitTest.xml
TEST-ApplicationTest.xml	
application.log
result.passed
$ 
  • 結果を開いてみたところ。テスト実行後の連携については別途Jenkinsプラグイン関連のエントリにて。

Ubuntu12.04 VPSサーバ構築手順:CI環境構築 アプリケーションをMercurialリポジトリに登録(from Eclipse)

以下のエントリシリーズのうちの1つ:任意のプロジェクトをMercurialプラグインを介してBitbucketに登録するまでのメモ。

  • Eclipse上からMercurial連携及びプロジェクトをBitbucketにプッシュしていく。Eclipseを開きプロジェクトを右クリック→[チーム]→[プロジェクトの共用]→[Mercurial]を選択。
  • Mercurial管理対象とするプロジェクトのパスを指定。
  • プロジェクトのプッシュ。プロジェクトを右クリック→[チーム]→[プッシュ]を選択、プッシュ先のURL・ユーザ名・パスワードをそれぞれ入力し、[OK]押下。
  • 内容を確認し、[OK]押下。
  • 対象のBitbucketリポジトリにアクセスし、プッシュ内容を確認。

このエントリにはEclipseベースでのMercurial連携について書きましたが、IntelliJベースでのMercurial連携についても先日エントリにまとめました。以下エントリになりますのでこちらも良ければご参照ください。

Ubuntu12.04 VPSサーバ構築手順:CI環境構築 Jenkinsユーザのsudo処理有効化設定

以下のエントリシリーズのうちの1つ:Jenkinsで諸々の処理をお願いするにあたり、恐らく幾度と無く行わせる事になるであろう『sudo』絡みの処理及びその有効化設定について。


とある作業を試そうとしたらタイトルの問題にぶつかったのでメモ。

まずはJenkinsで適当なプロジェクトを作成、シェルでsudo実行するコマンドを設定してみる。

sudo echo 'Hello, Jenkins!'


  • ビルド実行。これはエラーになる。
Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/jenkins-sandbox/workspace
[workspace] $ /bin/sh -xe /tmp/hudson5043293891289983150.sh
+ sudo echo Hello, Jenkins!
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
Build step 'Execute shell' marked build as failure
Finished: FAILURE

$ sudo /usr/sbin/visudo
------------------------
# Defaults requiretty           # tty無しの場合sudoさせない
Defaults:jenkins !requiretty   # ユーザjenkinsはtty無しでsudo可能
jenkins ALL=(ALL) NOPASSWD:ALL # ユーザjenkinsはパスワード無しでsudo可能
  • Jenkinsで先程のタスクを実行してみる。今度は問題無く実行出来ました。
Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/jenkins-sandbox/workspace
[workspace] $ /bin/sh -xe /tmp/hudson1427784546581462640.sh
+ sudo echo Hello, Jenkins!
Hello, Jenkins!
Finished: SUCCESS


これで諸々の作業をJenkinsさんに存分にお任せ出来そうです。

参考:

今日のつぶやき 2013/01/27