젠킨스 CI에서 레일즈+Postgres 테스트하기


젠킨스는 오픈소스 지속적 통합관리(Continuous Integration) 도구로 자바기반이다.

소스를 git이나 svn 같은 형상관리(CM : configuration management) 서버에 올리면, 그때마다 자동으로 테스트도 하고, 빌드도하고, 작업이 잘 끝났다고 알림도 주는 도구다.

자바기반이기 때문에 다른 언어로 개발된 애플리케이션을 젠킨스에서 테스트 하려면 따로 환경 설정이 필요하다. 이번엔 루비 온 레일즈로 만들어진 애플리케이션 테스트를위해 환경을 설정해 보았다.

레일즈 테스트용 젠킨스 도커 설정은 https://github.com/dorajistyle/jenkins-rails-postgres-docker 에서 볼 수 있다.

우선 아래 명령어로 소스를 다운 받는다.

git clone https://github.com/dorajistyle/jenkins-rails-postgres-docker.git


그리고 아래 명렁어로 도커 컨테이너를 빌드하면 젠킨스가 실행된다. docker-compose.yml에 나와있듯이 docker compose를 이용해서 postgres와 redis를 jenkins와 함께 실행하도록 하였다.

docker-compose up


젠킨스에서 레일즈를 테스트하기 위한 순서는 다음과 같다.

  1. 터미널에서 admin암호를 복사해서 젠킨스에 붙여 넣는다.
  2. 유저 정보를 입력해서 젠킨스를 시작한다.
  3. Multi-configuration 프로젝트를 만든다.
  4. Source Code Management 에서 git를 선택한다.
  5. 아래 url을 Repository URL 필드에 붙여넣는다.
    https://github.com/dorajistyle/rails-postgres-sample-for-jenkins

    만약 오픈소스가 아닌 프로젝트를 테스트 하려면, Credential을 추가해 줘야 한다.
    Add를 눌러 Username and password방식을 선택하고, username에는 github ID를 넣고 password에는 https://github.com/settings/tokens에서 생성한 토큰을 넣으면 된다.
  6. Build Environment에서 rbenv build wrapper체크박스를 선택한다.
    The Ruby version에는 2.3.1을 넣고,
    Preinstall gem list에는 bundler,rake,execjs를 넣는다.
  7. Add build step 샐랙트박스에서 Execute shell를 선택한다.
    Command필드에 아래 명령어를 붙여 넣는다.
    bash jenkins-test.sh
  8. 만약 빌드가 될 때 마다 슬랙으로 알림을 주고 싶다면, 플러그인을 설정해줘야 한다.
    우선 github 프로젝트의 설정에 젠킨스 플러그인을 추가해준다.
    Settings--> Webhooks&Services-->Service--> Add Services--> Choose "Jenkins (GitHub plugin)"
    에서 추가하고 아래 주소를 넣어준다.
    http:///github-webhook/
    https://.slack.com/apps/A0F7VRFKN-jenkins-ci 에서 Jenkins CI 앱 설정을 해준다.
    Post-build Actions의 Add post-build action 선택상자에서 Slack Notifications를 선택하고 환경 정보를 넣어준다.
    토큰은 슬랙 앱 설정에 나온 토큰을 넣어주면 된다.
  9. 설정을 저장하고 프로젝트의 사이드메뉴에서 Build Now를 클릭하여 테스트한다.

Docker compose로 띄운 
젠킨스에서 레일즈 테스트가 잘 돈다.

* rails 설정의 database.yml에는 docker-compose로 설정한 컨테이너 이름(예제 : dorajistyle-postgres)을 쓰고,
config.yml의 redis설정에도 마찬가지로 컨테이너 이름(예제 : dorajistyle-redis)를 써야 한다.


* git fetch 타임아웃 발생시 해결
Source Code Management > Git > Additional Behaviors > Advanced checkout behaviors / Advanced clone behaviors > Timeout (in minutes)



by


Tags : , , , , , , , ,

  • 재미있게 읽으셨나요?
    광고를 클릭해주시면,
    블로그 운영에 큰 도움이 됩니다!

귀찮은 일은 다 맡겨라. Grunt Javascript task runner.


특정 디렉토리 안에서 파일이 수정되면 컴파일을 해야 하는 상황이 생겼다.
글자 하나 바꿀 때마다 일일이 그런 수고를 하려니 여간 귀찮은 일이 아니다.
이런 때는 보통 bash 쉘 스크립트를 써 왔는데, os관계없이 어디서나 작동하고, 간편한 녀석을 찾다가 grunt(http://gruntjs.com)를 만나게 되었다. grunt는 프론트엔드 계통에선 꽤 이름을 날리는 녀석으로, 초반 웹 환경 구축을 도와주는 Yeoman(http://yeoman.io)의 한 부분이기도 하다. 요즘엔 grunt와 비슷한 gulp(http://gulpjs.com)이 성능 면에서 우수해서 인기가 좋은데, 여러 작업을 연달아서 할 때 pipe를 이용해서 I/O에 들어가는 시간을 줄이기 때문이란다. 그러나 나는 지금 연속적인 작업에 쓸 것도 아니고, grunt에서도 조만간(?) pipe를 지원할 예정이라고 하니, 커뮤니티가 활성화된 grunt를 쓰기로 했다.

grunt 설치

npm i grunt-cli -g

grunt를 실행할 해당 폴더에서 로컬 모듈 인스톨( 예 : static 폴더에서 실행시 static 폴더에 가서 인스톨)

npm install can-compile --save-dev
npm install grunt-shell --save-dev
npm install grunt-contrib-watch --save-dev
npm install time-grunt --save-dev


grunt 설정파일 예제 - Gruntfile.js

module.exports = function (grunt) {
    var static_path = '../static';

    // Project configuration.
    require('time-grunt')(grunt);
    grunt.initConfig({
//        pkg: grunt.file.readJSON('./package.json'),

    shell: {
      scsscompile:{ // scss컴파일은 외부 파이썬 스크립트를 이용해서 한다. 그래서 grunt-shell이 필요하다.
        command: 'python2 ../css.py '+static_path,
        options: {
            stdout: true
        }
      }
    },
    cancompile: { // mustache파일을 하나의 자바스크립트 파일로 합쳐주는 모듈
        dist: {
            src: [static_path+'/views/**/*.mustache'],
            out: static_path+'/js/views.build.js',
            wrapper: 'define(["can/view/mustache"], function(can) { {{{content}}} });'
        }
    },
    watch: { // grunt watch를 실행하면 해당되는 파일 변경사항이 생길 때 마다 스크립트를 자동으로 실행 한다.
      run_mustache: {
        files: [static_path+'/views/**/*.mustache'],
        tasks: ['cancompile']
      },
      run_scss: {
            files: [static_path+'/scss/**/*.scss'],
            tasks: ['shell:scsscompile']
      },
        options: { nospawn: true, livereload: true } // watch 성능이 향상된다.
    }
  });

//   grunt.registerTask('default', ['watch']); 로 설정하면, 파라미터 없이 grunt를 실행할 때 watch를 실행한다.
  grunt.registerTask('watch', ['watch']);
  grunt.registerTask('mustache', ['cancompile']);
  grunt.registerTask('scss', ['shell:scsscompile']);
  grunt.registerTask('static', ['cancompile','shell:scsscompile']);

  grunt.loadNpmTasks('can-compile');
  grunt.loadNpmTasks('grunt-shell');
  grunt.loadNpmTasks('grunt-contrib-watch');
};
이 간단한 설정 파일 하나로, 쓸만한 watcher가 만들어졌다. :D
앞으로도 귀찮은 작업을 떠넘길 때 종종 이용해야겠다.

문제 해결


npm이 sudo 권한 없이 설치되지 않을 때

http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` ~/node_modules
sudo chown -R `whoami` /usr/lib/node_modules


Grunt - Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. 에러가 발생할 때.

http://stackoverflow.com/questions/22285942/grunt-throw-recursive-process-nexttick-detected
grunt.registerTask('sass',['sass']); // 이런식으로 작업 이름과 등록 이름이 같을 때 문제가 발생한다.
grunt.registerTask('styles',['sass']); // 이런식으로 이름을 바꿔준다.

유용한 링크

http://gruntjs.com/
http://gulpjs.com
http://jaysoo.ca/2014/01/27/gruntjs-vs-gulpjs/
http://yeoman.io/blog/performance-optimization.html



by


Tags : , , , , , , ,

  • 재미있게 읽으셨나요?
    광고를 클릭해주시면,
    블로그 운영에 큰 도움이 됩니다!