8

Làm cách nào để thiết lập các ứng dụng Play và (tùy chỉnh) Phát mô-đun trong hệ thống CI sao cho khi xây dựng mô-đun tốt lưu trữ và/hoặc triển khai chúng vào một kho lưu trữ từ xa và các ứng dụng sử dụng các tạo phẩm trong kho lưu trữ đó?Cách sử dụng Play với các mô-đun tùy chỉnh và tích hợp liên tục

Giải pháp cũng sẽ hoạt động tốt cho nhà phát triển đang làm việc tại địa phương.

Tôi đang sử dụng Jenkins và gặp sự cố bất cứ cách nào tôi cố gắng thực hiện việc này.

Trước khi tôi giải thích tất cả các vấn đề tôi gặp phải, tôi sẽ chờ đợi, bởi vì nó mất thời gian và có thể một người khác có thể cung cấp cách họ thực hiện.

Trả lời

6

Tôi có thiết lập trong jenkins hoạt động tốt từ dev đến sản xuất.

Đầu tiên đây là cấu hình trong dependencies.yml cho kho mô-đun tùy chỉnh

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 -> * 

Với các nhà phát triển này và Jenkins tìm kiếm đầu tiên trong kho cùng để xem nếu một module có mặt và nếu không, đã đến kho lưu trữ nexus để tải xuống phần tạo tác.

Để xây dựng mô-đun của tôi trong Jenkins tôi sử dụng một kịch bản tùy chỉnh sh như thế này

#!/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 

Với kịch bản này, bạn có thể đẩy mô-đun của bạn để mối quan hệ trên mỗi Jenkins xây dựng. Đây không phải là những gì tôi làm. Tôi sử dụng mô-đun phát hành jenkins để đẩy nó chỉ khi tôi xây dựng một bản phát hành. Đối với bản phát hành, tôi có một tập lệnh đặc biệt

#!/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" 

Tập lệnh này đặt thẻ vào kho svn của chúng tôi, đẩy mô-đun vào mối quan hệ và cập nhật tệp dependencies.yml.

Với jenkins này có thể xây dựng một ứng dụng phụ thuộc vào phiên bản địa phương của mô-đun trong khi nó không được phát hành và sau đó có thể xây dựng ứng dụng bằng cách tải xuống mô-đun artifcat từ kho nexus. Điều tương tự đối với nhà phát triển

+1

Tôi nghĩ rằng kỹ thuật này sẽ tạo sự khác biệt trong thiết lập của tôi; Tôi chưa có thời gian để thử nó, đó là lý do tại sao tôi chưa chấp nhận nó. Câu hỏi tiếp theo: cấu hình repo localModules của bạn không giống như nó sẽ khớp với một thiết lập Jenkins điển hình, nơi không gian làm việc xây dựng không nằm trong các thư mục liền kề. Tôi là một chút bối rối như từ nơi Jenkins của bạn xây dựng lấy phụ thuộc cho dev (như trái ngược với phát hành) phiên bản. – Ladlestein

+1

Trong jenkins, tôi chỉ có một vùng làm việc và tất cả các thư mục mô-đun của tôi nằm liền kề như trong dev. Nếu không, bạn phải xuất bản vật phẩm của bạn trong nexus mỗi khi bạn xây dựng một mô-đun, với một số loại phiên bản chụp nhanh sẽ tẻ nhạt hơn để thiết lập và sử dụng –

2

Tôi đã viết Play nhỏ này! lệnh mà về cơ bản nó làm điều tương tự, nhưng tích hợp độc đáo vào 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 '~ ' 
Các vấn đề liên quan