herokuã§èªä½buildpackãä½ã£ãæã«å¾ãç¥è¦
è¿½è¨ 2017/11/29
ãã®è¨äºãæ¸ããæç¹ã§ç¡ãã£ããããªæ°ããããã§ãããä»ã¯Herokuã§Dockerãåãã¾ããç¡æã§ããã°ãããã ãã¨ãã°ãã®ããã¸ã§ã¯ãã¯å®å ¨ã«Dockerã§runtimeå®ç¾©ãã¦Herokuã«ãã¹ããã¦ããã¾ãã
以ä¸åæ
ãã¤ã¦ããâãæ¸ããã¨ãããã¾ãHerokuã¯ç¶æ³ãå¤ãã£ã¦ã¦ã
ä»ã§ã¯ãbuildpackã£ã¦ããããããªãã°ã¤ã³ã¹ã¿ã³ã¹ã®åæåã¹ã¯ãªããã¿ãããªã®ãå®ç¾©ã§ããã£ã½ããããã§ä¾åããããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ï¼ã«ç¸å½ãããã¨ï¼ãå¯è½ã£ã½ãã
ä»åã®æçµç®æ¨ã¯ãGoãåãã¦ããªããã¤tesseract-ocrã®C++ã®ãã¤ããªã¨ããããã¡ã¤ã«ãããç°å¢ãã¤ããããªã®ã ããã©ãã¾ãã¯ãããã ãªherokuã®buildpackãèªä½ãã¦ã¿ããã¨ãããã¨ã«ãªãã¾ããã
ã´ã¼ã«
- Herokuã§Goã®ã¢ããªã±ã¼ã·ã§ã³ãåã
- èªä½buildpackã«ããã¦å®ç¾©ããç°å¢å¤æ°ã«Goã®ã¢ããªã±ã¼ã·ã§ã³ãã¢ã¯ã»ã¹ã§ãã
tl;dr
- [heroku/go] ä¾åããã±ã¼ã¸ã¯Godepsãªã©ã§ç®¡çããã¦ããå¿ è¦ããã
- [heroku] app.jsonã¯ã©ããã
Deploy to Heroku
ãã¿ã³ãªã©ã®æã«å¿ è¦ãªã®ã§ãã£ã¦ãheroku createã¨pushã§ã¯ç¨ããããªã- ãããã£ã¦ãheroku createã§buildpackãæ¤è¨¼ããã«ã¯å¥é
heroku buildpacks:add
ãªã©ãç¨ããå¿ è¦ããã
- ãããã£ã¦ãheroku createã§buildpackãæ¤è¨¼ããã«ã¯å¥é
- [heroku-buildpack] buildpacksã®ãã©ã¼ãããã¯ã
detect
,compile
,release
ã®3段éï¼ç©ççã«ã¯ãã¡ã¤ã«ï¼ãæºããã¦ããã°ããdetect
ã¯exit 0
compile
ã¯åºåã«å¶éã¯ç¡ãrelease
ã¯validãªyamlå½¢å¼ã®åºåãæ¨æºåºåã«åãå¿ è¦ããã
- [heroku-buildpack] buildpackã®detect/compile/releaseã¯ãããã®ã®ãç°å¢å¤æ°ãåãã¹ã¯ãªããã¯
.profile.d/*.sh
ã§ãããcompileãªã©ã§.profile.d/foo.sh
ã«export
ãªã©ãæ¸ãè¾¼ãã§ããå¿ è¦ããã
ã¾ãç°¡åãªGoã®ãµã¼ãã¢ããªã±ã¼ã·ã§ã³ãä½ã
package main import ( "net/http" "os" m "github.com/otiai10/marmoset" ) func main() { router := m.NewRouter() router.GET("/", func(w http.ResponseWriter, req *http.Request) { m.RenderJSON(w, http.StatusOK, m.P{ "message": "Hello!", "FOO": os.Getenv("FOO"), // ããã«buildpackã§å®ç¾©ããç°å¢å¤æ°åºããã㪠"BAR": os.Getenv("BAR"), }) }) // ã¢ããªã±ã¼ã·ã§ã³ã®ãã¼ãã¯herokuããç°å¢å¤æ°"PORT"ã¨ãã¦ä¸ãããã port := os.Getenv("PORT") http.ListenAndServe(":"+port, router) }
ã§ãããã¸ã§ã¯ãã®ã«ã¼ããã£ã¬ã¯ããªã§ãã£ã¦godep save
ãä¸çºãã¡ã¦ã以ä¸ã®ãããªæ§æã«ãã¾ãã
heroku-simple-app-go âââ Godeps â  âââ Godeps.json â  âââ Readme âââ Procfile âââ main.go âââ vendor âââ github.com âââ 以ä¸å²æ
ãã®ç¶æ ã§ã
% heroku create % git push heroku master % heroku open
ã¨ããã¨ããã®Goã®ã¢ããªã±ã¼ã·ã§ã³ãåãã¦ãããã¨ã確èªã§ããã
èªä½buildpackãã¤ãã
buildpackãé ç½®ããã¬ãã¸ããªã¯ãã¨ãããã以ä¸ã®æ§ãªæ§æã«ãªã£ã¦ããã°ååã
.
âââ bin
  âââ detect
  âââ compile
  âââ release
# permissionã¯ãã¹ã¦755
detect
#!/usr/bin/env bash echo "This is detect of empty buildpatck." # exit 0 ããã°detectã¯æåå¤å® exit 0
compile
#!/usr/bin/env bash echo "-----> [Bla Bla Bla Bla]" # .profile.d以ä¸ã«.shãã¡ã¤ã«ãä½ã£ã¦ããã mkdir -p $1/.profile.d ENVVARS=$1/.profile.d/build-env.sh # exportãªã©ã®ã¹ã¯ãªããã¯.profile.d以ä¸ã® # ãã®.shãã¡ã¤ã«ã«è¨è¿°ããã¦ããå¿ è¦ããã echo "export FOO=\"Hey, this variable is set by buildpack!!\"" >> $ENVVARS
release
#!/usr/bin/env bash cat <<EOF config_vars: BAR: "This is bar" EOF # ããã§BARãexportã§ãã¦ãã®ããªã¼ã¨æã£ãã # ä¸ã®ä¸ãããªã«çããªãããã
ã§ãããã®
ã¢ããªã±ã¼ã·ã§ã³ãããã®buildpackã使ãããã«ãã
1. ä»ããheroku createããå ´å
heroku create
ã«--buildpack
ãä¸ããã°ãã
% heroku create --buidpack https://github.com/otiai10/heroku-buildpack-tesseract-devel.git
2. ãã§ã«heroku createãã¦ããå ´å
heroku buildpacks:add
ã¨ããã®ããã
% heroku buildpacks:add https://github.com/otiai10/heroku-buildpack-tesseract-devel.git
3. "Deploy to Heroku"ãã¿ã³ã§ä½¿ãããå ´å â ãã
app.json
ã«buildpacks
ã£ã¦ãããã£ã¼ã«ãããã
{ ...nameã¨ãããããã®æ¸ã..., "buildpacks": [ { "url": "https://github.com/otiai10/heroku-buildpack-tesseract-devel.git" } ] }
ãããæ¸ãã¨ã
ããæ¼ããæã®ãã³ãã¬ã¼ãã«ãã®buildpackã使ãããã«æå®ããããã¨ã«ãªãã
Deployãã¦ã¿ã
ãããã¤ã®ãã°ã
-----> This is detect of empty buildpatck. app detected -----> This is empty build pack /tmp/build_f6ebcf6d3e5e0e1a26460e09fcd1ca7a /app/tmp/cache /tmp/d20161104-61-gu6qsi export FOO="Hey, this variable is set by buildpack!!" -----> Go app detected -----> Checking Godeps/Godeps.json file. -----> Using go1.7.3 !! Installing package '.' (default) !! !! -----> Running: go install -v -tags heroku . github.com/otiai10/heroku-simple-app/vendor/github.com/otiai10/marmoset github.com/otiai10/heroku-simple-app -----> Discovering process types Procfile declares types -> web -----> Compressing... Done: 2.6M -----> Launching... Released v4 https://test-foobar.herokuapp.com/ deployed to Heroku
ã§è¯ãæãã«åãã¦ããheroku open
ãã¦ã¿ãã¨
èªä½ã®buildpackãã¢ããªã±ã¼ã·ã§ã³ã®ãã«ãã®åã§å®è¡ããã¦ãããbuildpackã«ãã£ã¦å®£è¨ãããç°å¢å¤æ°ãã¢ããªã±ã¼ã·ã§ã³ã§åç §ã§ãã¦ãããã¨ã確èªã§ããã
éæ
- 次åã¯ãbuildpackã§C++ã®ã©ã¤ãã©ãªã¨ããããã¡ã¤ã«ãé ç½®ããã¢ããªã±ã¼ã·ã§ã³ãããããåç §ããã
DRYãªåå¿é²ã¨ãã¦
- ä½è : ç¸æ¾¤æ©,arton,é³¥äºéª,ç¹ç°æ¬å
- åºç社/ã¡ã¼ã«ã¼: KADOKAWA/ã¢ã¹ãã¼ã»ã¡ãã£ã¢ã¯ã¼ã¯ã¹
- çºå£²æ¥: 2014/09/19
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (3件) ãè¦ã
Herokuã§ã¯ãããRailsããã°ã©ãã³ã°å ¥é
- ä½è : æç°æ´¥è¶ä¹,ç¸æ¾¤æ©
- åºç社/ã¡ã¼ã«ã¼: ã½ãããã³ã¯ã¯ãªã¨ã¤ãã£ã
- çºå£²æ¥: 2013/03/15
- ã¡ãã£ã¢: 大åæ¬
- ã¯ãªãã¯: 7å
- ãã®ååãå«ãããã° (4件) ãè¦ã
- ä½è : Neil Middleton,Richard Schneeman
- åºç社/ã¡ã¼ã«ã¼: Oreilly & Associates Inc
- çºå£²æ¥: 2013/11/24
- ã¡ãã£ã¢: ãã¼ãã¼ããã¯
- ã¯ãªãã¯: 2å
- ãã®ååãå«ãããã°ãè¦ã