티스토리 뷰

Paas 클라우드 서비스 Heroku 시작하기.



클라우드서비스가 대중적이지 않던 시절에는 SE나 개발자가 인프라를 구축하고 운영해야 했으나, 요즘과 같이 다양한 클라우드 인프라를 이용할 수 있는 시대에는 개발자가 가장 잘 할 수 있는 어플리케이션 개발에 집중하고, 가장 심플하게 인프라를 이용할 수 있는 클라우드 서비스 사용이 개발의 핵심 요소로 자리 잡았다고 볼 수 있다.  AWS, GAE, Asure, Heroku 등등 국내 통신사, 호스팅 업체도 클라우드서비스 상품을 출시 하므로 점점 대중화에 힘쓰고 있는 것을 볼 수 있다. 

Paas 서비스 중에서도 설치,배포가 심플한 Heroku에 대해 알아보았다.

Heroku는 Ruby부터 Java, Python, PHP, GO, Scala, Node.js, Clojure등 여러 플랫폼을 제공하고 있으며, 설치 배포가 다른 클라우드 플랫폼들에 비해 쉽다.


Deploy Spring Boot Application on Heroku.

개발환경

OS : OSX El Capitan

java : 1.8

Spring Boot : 1.4.0

Redis

MySQL

Heroku Toolbelt : 3.43.2


1. Sign-up

https://www.heroku.com/pricing 접속 후 Sign-up For Free

[그림 1] Sign up For Free


2. 계정 등록 및 E-mail 인증

계정 등록 후 E-mail 인증 및 Password를 설정하면 로그인이 가능하다.

[그림 2-1] 계정 등록 및 플랫폼 선택


[그림 2-2] 계정 등록 및 플랫폼 선택


[그림 3-1] 인증메일을 통한 사용자 인증



[그림 3-2] 인증메일을 통한 사용자 인증


3. Heroku Tool 설치

https://toolbelt.heroku.com/ 접속 후 Toolbelt Installer를 다운로드 받는다.

[그림4] Heroku Tool belt 설치


설치 확인

$ heroku --version

heroku-cli: Installing CLI... 19.39MB/19.39MB

heroku-toolbelt/3.43.2 (x86_64-darwin10.8.0) ruby/1.9.3

heroku-cli/5.1.6-151ac67 (darwin-amd64) go1.6.2

You have no installed plugins.



4. Deploy 절차 수행

Gradle과 maven기준이 다르기 때문에 주의해야한다.  (Gradle 기준으로 작성되었다.)


- Procfile 작성

web: java $JAVA_OPTS -Dserver.port=$PORT -jar app.jar


- system.properties 작성

java.runtime.version=1.8


- build.gradle 추가

task stage(type: Copy, dependsOn: [clean, build]) {

  from jar.archivePath

  into project.rootDir

  rename {

    'app.jar'

  }

}

stage.mustRunAfter(clean)


clean << {

  project.file('app.jar').delete()

}


- heroku login

$ heroku login

Enter your Heroku credentials.

Email: globalrocksea@gmail.com

Password (typing will be hidden): 

Logged in as globalrocksea@gmail.com


- git 셋팅

heroku는 GIT을 이용하여 배포되기 때문에 git사용법을 미리 숙지하여 사용하도록 한다.

$ git config --global user.email "globalrocksea@gmail.com"

$ git config --global user.name "rocksea"

$ git init

$ git add -A

$ git commit -m "first commit" -a


- heroku create

heroku application을 생성한다.

$ heroku create

Creating app... ⬢ obscure-thicket-xxxxx

https://obscure-thicket-xxxxx.herokuapp.com/ | https://git.heroku.com/obscure-thicket-xxxxx.git


- DBMS AddOn 설치

PostgreSQL을 사용할 경우

$ heroku addons:create heroku-postgresql


MySQL을 사용할 경우 (현재 MySQL을 사용하므로 이 부분을 진행

$ heroku addons:create cleardb:ignite


설치 시 아래와 같은 메세지가 출력 되는 경우가 있는데, 결제 카드 등록이 안되어있는 경우이니 당황하지 말고 

https://dashboard.heroku.com/account/billing  페이지에서 등록하도록 한다.

 !    Please verify your account to install this add-on plan (please enter a credit card) For more information, see https://devcenter.heroku.com/categories/billing Verify now at https://heroku.com/verify 


- DB config 확인

$ heroku config

=== obscure-xxxxxx Config Vars

DATABASE_URL: postgres://xxxxxx:xxxxxxx@....


- Redis AddOn 설치

$ heroku addons:create rediscloud:30


$ heroku config | grep REDIS

=== obscure-xxxxxx Config Vars

REDISCLOUD_URL:       redis://xxxx:xxxxx@pub-redis-15612.us-east-1-2.2.ec2.garantiadata.com


전체 addons 내역 확인

$ heroku addons


Add-on                                       Plan       Price

───────────────────────────────────────────  ─────────  ─────

cleardb (cleardb-rugged-93865)               ignite     free

 └─ as CLEARDB_DATABASE


heroku-postgresql (postgresql-curved-93379)  hobby-dev  free

 └─ as DATABASE


rediscloud (rediscloud-horizontal-52863)     30         free

 └─ as REDISCLOUD


The table above shows add-ons and the attachments to the current app (obscure-xxxxxx) or other apps.


5. Deploy

Heroku에 배포시 git push를 통해 수행 한다.  Push를 하면 자동으로 빌드를 시작한다.

$ git push heroku master

remote:        2016-05-09 07:57:36.177  INFO 328 --- [       Thread-7] o.s.w.c.s.GenericWebApplicationContext   : Closing org.springframework.web.context.support.GenericWebApplicationContext@53c47fe: startup date [Mon May 09 07:57:07 UTC 2016]; root of context hierarchy

remote:        :check

remote:        :build

remote:        :stage

remote:        

remote:        BUILD SUCCESSFUL

remote:        

remote:        Total time: 1 mins 2.36 secs

remote: -----> Discovering process types

remote:        Procfile declares types -> web

remote: 

remote: -----> Compressing...

remote:        Done: 117.5M

remote: -----> Launching...

remote:        Released v7

remote:        https://xxxxx.herokuapp.com/ deployed to Heroku

remote: 

remote: Verifying deploy... done.

To https://git.heroku.com/xxxxx.git

 * [new branch]      heroku -> master


TIP 1. 빌드 실패 또는 소스 수정 없이 재 빌드 시 

$ git commit --allow-empty -m "empty commit"

$ git push heroku master


TIP 2. 수동 빌드 팩 설정 시 ( Gradle )

$ heroku create --buildpack https://github.com/heroku/heroku-buildpack-gradle.git


6. Open Browser

$ heroku open


$ heroku logs --tail

[그림 5] heroku 브라우저 접속 테스트

댓글