[GS] Heroku 시작하기

웹 서비스 히로쿠에 배포하기

Heroku Git

Install the Heroku CLI Download and install the Heroku CLI.

If you haven’t already, log in to your Heroku account and follow the prompts to create a new SSH public key.

$ heroku login

Create a new Git repository Initialize a git repository in a new or existing directory

$ cd my-project/
$ git init
$ heroku git:remote -a hello-yeopoong

Clone the repository Use Git to clone hello-yeopoong’s source code to your local machine.

$ heroku git:clone -a hello-yeopoong

Existing Git repository For existing repositories, simply add the heroku remote

$ heroku git:remote -a hello-yeopoong

Hello World

server.go

package main

import (
	"fmt"
	"os"
	"net/http"
)

func main() {
	server := http.Server{
		Addr: ":" + os.Getenv("PORT"),//
	}
	http.HandleFunc("/", handlePost)
	server.ListenAndServe()
}

func handlePost(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello Worlds, %s!", r.URL.Path[1:])
}

웹 서비스의 의존성 설정

$ go get github.com/tools/godep
$ godep save

Godeps/Godeps.json

{
	"ImportPath": "hello-world",
	"GoVersion": "go1.10",
	"GodepVersion": "v80",
	"Deps": []
}

프로파일 정의

실행할 파일이나 메인 함수를 설명

Profile

web: hello-world 

빌드 및 배포

$ heroku create
or 
$ heroku create <app-name>

Deploy your application Commit your code to the repository and deploy it to Heroku using Git.

$ git add .
$ git commit -am "make it better"
$ git push heroku master

Real-time tail

$ heroku logs --tail
https://hello-yeopoong.herokuapp.com/test

Hello Worlds, test!

Reference

  • 슬러그(Slug)
    • 격리된, 가벼운 가상화 Unix 컨테이너라는 의미의 용어이며 히로쿠 다이노스(Heroku dynos)에서 실행됨
  • Go 웹 프로그래밍





© 2017. by yeopoong.github.io

Powered by yeopoong