Docker 使ã£ã¦ golang ã§æ¸ãããã¼ã«ã® cross platform build ããã
ã¾ã以ä¸ã®æ§ãªã·ã§ã«ã¹ã¯ãªãããç¨æããï¼
#!/bin/bash # ããã§ä¾åãã¦ããããã±ã¼ã¸ã go get ãã # ä¾ãã°ä»¥ä¸ã®æ§ãªæã # go get -v gopkg.in/yaml.v2 # go get -v gopkg.in/redis.v3 for GOOS in darwin linux; do for GOARCH in 386 amd64; do export GOOS export GOARCH go build -v -o bin/tool-$GOOS-$GOARCH main.go done done
darwin 㨠linux ã«ã¤ãã¦ï¼ãããã i386 㨠amd64 ã¢ã¼ããã¯ãã£åãã®ãã¤ããªãä½ããããªã¹ã¯ãªããï¼main.go ã¯ãã«ã対象ã®ãã¡ã¤ã«ï¼ææç©ã¯ã«ã¬ã³ããã£ã¬ã¯ããªã® bin 以ä¸ã«çæãããã®ã§ï¼ããããã mkdir ãã¦ããå¿ è¦ããã (å¾è¿°)ï¼
ãªãï¼GOOS
㨠GOARCH
ã export ãã¦ãããªãã¨ãã¾ãåããªãï¼ããã¥ã¡ã³ãã§ã¯ãããçç¥ããã¦ãã¦å°ãããã£ãï¼
ããã§ãã£ã¦ãã®ã¹ã¯ãªãããå¼ã³åºãï¼ä»¥ä¸ã¯ Makefile ã®ä¾ï¼
build: docker run --rm -v "$(PWD)":/go/src/github.com/moznion/tool -w /go/src/github.com/moznion/tool golang:1.6 bash build.sh
ããã§ã¯ docker hub ã§å
¬éããã¦ãã golang ã®ã¤ã¡ã¼ã¸ãå©ç¨ãã¦ããï¼
https://hub.docker.com/_/golang/
-v
ãªãã·ã§ã³ã使ã£ã¦ã«ã¬ã³ããã£ã¬ã¯ããªã« docker image å
ã® go path ãéã£ã¦ããç¶ãã¹ããã£ã¬ã¯ããªããã¦ã³ãããï¼
ã§ãã£ã¦ï¼-w
ãªãã·ã§ã³ã§ãã¦ã³ããããã£ã¬ã¯ããªãã¯ã¼ãã³ã°ãã£ã¬ã¯ããªã«è¨å®ãï¼ä¸è¨ã®ã·ã§ã«ã¹ã¯ãªããã image å
ã§å®è¡ããï¼
ã¨ï¼ã¯ã¼ãã³ã°ãã£ã¬ã¯ããªä»¥ä¸ã® bin ã«ææç©ãåãåºããï¼ã¯ã¼ãã³ã°ãã£ã¬ã¯ããªã¯ã«ã¬ã³ããã£ã¬ã¯ããªã«ãã¦ã³ãããã¦ããã®ã§ï¼ã¤ã¾ãææç©ã¯ã«ã¬ã³ããã£ã¬ã¯ããªä»¥ä¸ã® bin ã«åºåããã¦ãããã¼ã¨ãã寸æ³ï¼
ãªãï¼--rm
ãªãã·ã§ã³ãä»ãã¦ãããªãã¨å®è¡ãã度ã«ã´ã container ãã©ãã©ãæºã¾ã£ã¦ããã®ã§ã¤ããã»ããè¯ãï¼
Ref;
å®éã®ã³ã¼ãã¯ããã«æ¸ãã¦ããæãã®ãã¤
追è¨
cgo 使ããªãï¼ãªãã㤠go 1.5 以ä¸ã§ããã° make ã ãã§å®çµããã¨ã®ãã¨ï¼
Docker 使ã£ã¦ golang ã§æ¸ãããã¼ã«ã® cross platform build ããã - ãã®æã®å¹³ã¯å°»ãã¤ããããb.hatena.ne.jpå¥ã«dockerãã·ã§ã«ã¹ã¯ãªããããããªã㦠makeã ãã§å®çµããããªäºæï¼ã¢ã³ãµã¼ã½ã³ã°ãã¨ãã http://lestrrat.ldblog.jp/archives/48673706.html
2016/05/24 06:27
ãªãï¼gox åã³ goxc ã«ã¤ãã¦ã¯ go 1.4 以ä¸ã®ä¾¿å©ãã¼ã«ã¨ããç«ã¡ä½ç½®ã¨ã®ãã¨ï¼