概要 (Abstract)
werckerはプライベートレポジトリでも無料でCIできます.
On wercker, you can construct CI environments at no charge even for private repositories.
この記事ではwerckerでbitbucket.org
のプライベートなGoライブラリを使う方法を述べます.
This post explains how to use private Go libraries on bitbucket.org
on wercker.
問題 (Problem)
以下はあるGoプログラムのwercker.yml
の例です.
This is a sample of wercker.yml
of a Go program.
box: golang:1.5
build:
steps:
- setup-go-workspace
- script:
name: go build
code: |
go get -t ./...
go build ./...
そのGoレポジトリで,プライベートレポジトリのライブラリbitbucket.org/yourname/a-private-go-library
を使っていると次のエラーが出てしまいます.
You will have the following error, if you use the library on private repository bitbucket.org/yourname/a-private-go-library
in the Go program.
go build
Command cancelled due to error
package bitbucket.org/yourname/a-go-program: https://api.bitbucket.org/1.0/repositories/yourname/a-private-go-library: 403 FORBIDDEN
対策 (Solution)
-
werckerの管理画面でSSH鍵を作ります (Create a SSH key on wercker setting page)
-
bitbucket.org/yourname/a-private-go-library
の設定画面を開いて鍵を追加します (Add the key on the setting page forbitbucket.org/yourname/a-private-go-library
)
- ラベルの名前は何でも良いです (Any label name is OK.)
wercker.yml
を次のように修正します (Fixwercker.yml
in the following way)
box: golang:1.5
build:
steps:
- add-ssh-key:
keyname: FOO_KEY
host: bitbucket.org
- add-to-known_hosts:
hostname: bitbucket.org
fingerprint: 35:ee:d7:b8:ef:d7:79:e2:c6:43:9e:ab:40:6f:50:74
- setup-go-workspace
- script:
name: Clone private packages
code: |-
git clone git@bbitbucket.org/yourname/a-private-go-library.git $GOPATH/src/bitbucket.org/yourname/a-private-go-library
- script:
name: go build
code: |
go get -t ./...
go build ./...
これで終わりです
That's all !