Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

mega's Blog

heroku에 go application 배포하기 본문

카테고리 없음

heroku에 go application 배포하기

megadev 2016. 10. 11. 15:47


Heroku에 go언어로 작성된 app을 배포해 보자.


먼저 소스를 준비하자.

여기서는 /home/truelsy/workspace_go/chatserver에 준비가 되어있다고 가정한다. 


godep 패키지를 설치한다.

go get -u github.com/tools/godep


Heroku에 배포할 애플리케이션 디렉토리로 이동하여 dependency를 설정한다.

cd /home/truelsy/workspace_go/chatserver
godep save ./...


Procfile을 작성한다.

Procfile은 Heroku가 맨 처음 실행하는 명령어를 지정하는데, 보통 애플리케이션을 기동하기 위한 명령어를 기술한다.

작성한 Procfile을 보면, “web:” 이라고 기술하였는데, 배포하고자 하는 애플리케이션이 웹 애플리케이션임을 정의한다.

web 타입의 애플리케이션만 Heroku의 내부 HTTP 로드밸런서에 연결이 되서 웹 요청을 받을 수 있다.

다음으로 “chatserver” 라고 실행파일 이름을 지정하였다.

echo "web: chatserver" > Procfile


여기까지 되었으면 일단 배포 준비는 완료 되었다.



Heroku내에 앱을 만든다.

heroku create go-chatserver


앱은 아래 명령으로 삭제 할 수 있다

heroku destroy go-chatserver


앱이 작성되었으므로 이제 코드를 배포해야 하는데, Heroku는 git을 이용한다.

git init .
git add *
git commit -m 'init'
heroku git:remote -a go-chatserver
git push heroku master


git push를 완료하면 아래와 같은 메시지와 함께 앱이 실행된다.

Counting objects: 142, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (132/132), done.
Writing objects: 100% (142/142), 3.46 MiB | 300.00 KiB/s, done.
Total 142 (delta 9), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Go app detected
remote: -----> Checking Godeps/Godeps.json file.
remote: -----> Installing go1.6.3... done
remote: -----> Running: go install -v -tags heroku ./... 
remote: IAPServer/test/mega/chatserver_ws/msg
remote: IAPServer/test/mega/chatserver_ws/vendor/github.com/golang/protobuf/proto
remote: IAPServer/test/mega/chatserver_ws/vendor/gopkg.in/go-playground/validator.v8
remote: IAPServer/test/mega/chatserver_ws/vendor/gopkg.in/yaml.v2
remote: IAPServer/test/mega/chatserver_ws/vendor/github.com/gin-gonic/gin/binding
remote: IAPServer/test/mega/chatserver_ws/vendor/github.com/manucorporat/sse
remote: IAPServer/test/mega/chatserver_ws/vendor/golang.org/x/net/context
remote: IAPServer/test/mega/chatserver_ws/vendor/github.com/gorilla/websocket
remote: IAPServer/test/mega/chatserver_ws/vendor/github.com/gin-gonic/gin/render
remote: IAPServer/test/mega/chatserver_ws/vendor/github.com/gin-gonic/gin
remote: IAPServer/test/mega/chatserver_ws
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 6.6M
remote: -----> Launching...
remote:        Released v3
remote:        https://go-chatserver-websocket.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy.... done.
To https://git.heroku.com/go-chatserver-websocket.git
 * [new branch]      master -> master


로그 모니터링은 아래 명령어를 이용한다.

heroku logs --tail


앱 실행은 아래 명령어를 이용한다.

heroku ps:scale web=1


앱 중지는 아래 명령어를 이용한다.

heroku ps:scale web=0


Heroku앱의 URL은 http://app이름.herokuapp.com 이다.

여기서 만든 예제는 chatserver라는 앱 이름을 사용했기 때문에,

https://chatserver.herokuapp.com/ 가 접속 URL이 된다

Comments