8

我如何設置構建Play中的應用和(自定義)在CI系統播放模塊,因此,當一個模塊的構建是好的,構建安裝在本地模塊文物存儲庫和/或將它們部署到遠程存儲庫,並且這些應用程序使用該存儲庫中的工件?如何使用自定義模塊,播放和持續集成

該解決方案還應該誰的工作在本地開發工作。

我使用詹金斯和麻煩盡我嘗試這樣做運行。

我闡述一下我遇到的所有問題之前,我會等待,因爲它是費力的,也許別人可以提供他們是如何做到這一點。

回答

6

我在詹金斯的設置,從開發能很好地生產。

首先這裏是在dependencies.yml自定義模塊庫中的配置

repositories: 
    - modules: 
     type: chain 
     using: 
      - localModules: 
       type: local 
       descriptor: "${application.path}/../[module]/conf/dependencies.yml" 
       artifact: "${application.path}/../[module]" 
      - repoModules: 
       type: http 
       artifact: "http://mynexus/nexus/content/repositories/releases/com/myorg/[module]/[revision]/[module]-[revision].zip" 
     contains: 
      - com.myorg -> * 

有了這個開發商和詹金斯首先搜索同一個檔案庫,看是否有模塊存在,如果沒有,得nexus存儲庫下載工件。

建立我在詹金斯模塊我使用自定義sh腳本這樣

#!/bin/bash 
APPLICATION="myModule" 
PLAY_PATH="/usr/local/play" 
set –xe 

$PLAY_PATH/play deps --sync 
$PLAY_PATH/play build-module --require 1.2.3 
VERSION=`grep self conf/dependencies.yml | sed "s/.*$APPLICATION //"` 
echo "Sending $APPLICATION-$VERSION.zip to nexus repository" 
curl --request POST --user user:passwd http://mynexus/nexus/content/repositories/releases/com/myorg/$APPLICATION/$VERSION/$APPLICATION-$VERSION.zip -F "[email protected]/$APPLICATION-$VERSION.zip" --verbose 

有了這個腳本,你可以和你的模塊推到關係上的每個詹金斯建設。這並不是我所做的。我使用jenkins發佈模塊來推它,只有當我建立一個版本。對於釋放我有一個特殊的腳本

#!/bin/bash 
APPLICATION="myModule" 
PLAY_PATH="/usr/local/play" 
set –xe 

if [ -z "$RELEASE_VERSION" ] 
then 
    echo "Parameter RELEASE_VERSION is mandatory" 
    exit 1 
fi 
if [ -z "$DEVELOPMENT_VERSION" ] 
then 
    echo "Parameter DEVELOPMENT_VERSION is mandatory" 
    exit 1 
fi 
echo "Release version : $RELEASE_VERSION" 
echo "Development version : $DEVELOPMENT_VERSION" 
VERSION=`grep self conf/dependencies.yml | sed "s/.*$APPLICATION //"` 
if [ "$RELEASE_VERSION" != "$VERSION" ] 
then 
    echo "Release version $RELEASE_VERSION and play version $VERSION in dependencies.yml does not match : release failed" 
    exit 1 
fi 
REVISION=`svnversion .` 
echo "Tag svn repository in revision $REVISION with version $VERSION" 
svn copy -m "Version $VERSION" -r $REVISION http://mysvn/myRepo/$APPLICATION/trunk/ http://mysvn/myRepo/$APPLICATION/tags/$VERSION 
echo "svn tag applied" 
echo "Sending $APPLICATION-$VERSION.zip to nexus repository" 
curl --request POST --user user:passwd http://mynexus/nexus/content/repositories/releases/com/myorg/$APPLICATION/$VERSION/$APPLICATION-$VERSION.zip -F "[email protected]/$APPLICATION-$VERSION.zip" --verbose 
echo "$APPLICATION-$VERSION.zip sent to nexus repository" 
echo "Update module to version $DEVELOPMENT_VERSION" 
sed -i "s/self\(.*\)$VERSION/self\1$DEVELOPMENT_VERSION/g" conf/dependencies.yml 
svn commit -m "Version $DEVELOPMENT_VERSION" conf/dependencies.yml 
svn update 
echo "Version $DEVELOPMENT_VERSION créée" 

這個腳本把標籤在我們的svn庫,推模塊Nexus和更新dependencies.yml文件。

有了這個詹金斯可以建立依賴於模塊的本地版本,同時它不被釋放,之後可以通過從關係信息庫下載模塊artifcat構建應用程序的應用程序。這對開發者來說是一樣的

+1

我覺得這個技術將會使我的設置的差異;我還沒有時間嘗試它,這就是爲什麼我還沒有接受它。後續問題:您的localModules repo配置看起來不像典型的Jenkins設置,其中構建工作區不在相鄰的目錄中。我有點困惑,從你Jenkins構建的位置檢索dev(相對於發佈)版本的依賴關係。 – Ladlestein

+1

在jenkins中,我只有一個工作空間,所有的模塊目錄都是相鄰的,因爲它在開發中。如果沒有,那麼每次構建模塊時都必須在nexus中發佈您的artefact,並使用某種類型的快照版本控制,這會對設置和使用更加繁瑣 –

2

我寫了這個小玩!命令,基本上它做同樣的事情,但很好地集成到Play!

http://www.playframework.org/community/snippets/25

from play.utils import * 
from poster.encode import multipart_encode 
from poster.streaminghttp import register_openers 
import urllib 
import urllib2 
import yaml 

COMMANDS = ['nexus-commit',] 

HELP = { 
    'nexus-commit': 'push built module to nexus' 
} 

def execute(**kargs): 
    app = kargs.get("app") 
    args = kargs.get("args") 
    play_env = kargs.get("env") 

    print '~ ' 
    print '~ Commiting to nexus server' 
    print '~ ' 

    app.check() 
    nexus = app.readConf('nexus.server.url') 
    user = app.readConf('nexus.server.user') 
    password = app.readConf('nexus.server.password') 

    if nexus: 
     print '~ Found nexus repository : %s' % nexus 
    else: 
     print '~ No nexus server configured' 
     print '~ Set up the following on your application.conf:' 
     print '~ nexus.server.url' 
     print '~ nexus.server.user' 
     print '~ nexus.server.password' 
     sys.exit(0) 

    #Getting module version from dependencies file 
    deps_file = os.path.join(app.path, 'conf', 'dependencies.yml') 
    if os.path.exists(deps_file): 
     f = open(deps_file) 
     deps = yaml.load(f.read()) 
     #Is this a Play~ module? 
     if "self" in deps: 
      d = deps["self"].split(" ") 
      module_version = d.pop() 
      app_name = d.pop() 
     else: 
      app_name = app.name() 
      print '~ This is not a Play module' 
      module_version = app.readConf('application.version') 
      if not module_version: 
       print '~ ' 
       print '~ No application.version found in application.conf file' 
       print '~ ' 
       module_version = raw_input('~ Provide version number to be pushed to Nexus:') 
     f.close 

    if module_version: 
     print '~ Module version : %s' % module_version 
     print '~ ' 
    else: 
     print '~ No module version configured.' 
     print '~ Configure your dependencies file properly' 
     sys.exit(0) 

    dist_dir = os.path.join(app.path, 'dist') 

    #Only interested on .zip files 
    for root, dirs, files in os.walk(dist_dir): 
     files = [ fi for fi in files if fi.endswith(".zip") ] 

    #Loop over all found files 
    if len(files) >0: 
     for file in files: 
      if "-a" in args: 
       #We won't ask the user if he wants to commit 
       resp = "Y" 
      else: 
       resp = raw_input('~ Do you want to post %s to nexus? (Y/N) ' % file) 
      if resp == 'Y': 
       url = '%s/%s/%s-SNAPSHOT/%s-%s-SNAPSHOT.zip' % (nexus, app_name, module_version, app_name, module_version) 
       print '~ ' 
       print '~ Sending %s to %s' % (file, url) 

       try: 
        data = open(os.path.join(dist_dir, file), 'rb') 
       except: 
        print '~ Error: could not open file %s for reading' % file 
        continue 

       openers = register_openers() 
       #post data to Nexus using configured credentials 
       passman = urllib2.HTTPPasswordMgrWithDefaultRealm() 
       passman.add_password(None, url, user, password) 
       authhandler = urllib2.HTTPBasicAuthHandler(passman) 
       openers.add_handler(authhandler) 
       openers.add_handler(urllib2.HTTPHandler(debuglevel=1)) 
       datagen, headers = multipart_encode({"file": data}) 
       request = urllib2.Request(url, datagen, headers) 

       try: 
        print urllib2.urlopen(request).read() 
        print '~ File correctly sent' 
       except urllib2.HTTPError, err: 
        print '~ Error: Nexus replied with -- %s' % err 

      else: 
       print '~ ' 
       print '~ Skiping %s' % file 
    else: 
     print '~ ' 
     print '~ No module build found.' 
     print '~ Try "play build-module" command first' 
     print '~ '