LoginSignup
7
6

More than 5 years have passed since last update.

werckerでプライベートなGoライブラリを使う方法 (How to use private Go libraries on wercker)

Last updated at Posted at 2016-03-02

概要 (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.

wercker.yml
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.

:x: 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)

  1. werckerの管理画面でSSH鍵を作ります (Create a SSH key on wercker setting page)

    • 鍵の名前は何でも良いです (Any key name is OK.)
    • 以下ではFOO_KEYと名前をつけました (Sample: FOO_KEY) 0.png
  2. Public keyをコピーします (Copy the public key)
    0-2.png

  3. bitbucket.org/yourname/a-private-go-libraryの設定画面を開いて鍵を追加します (Add the key on the setting page for bitbucket.org/yourname/a-private-go-library)
    1.png

    • ラベルの名前は何でも良いです (Any label name is OK.)
  4. wercker.ymlを次のように修正します (Fix wercker.yml in the following way)

wercker.yml
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 !

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6