LoginSignup
1
0

More than 5 years have passed since last update.

【Bitbucket Pipelines】Go 言語の依存パッケージ(vendor/)等を cache する

Posted at

pre-defined cache の中に golang のものは無かったので、自分で定義する必要がある。

以下は dep を使った例。

bitbucket-pipelines.yml
image: golang

pipelines:
  default:
    - step:
        caches:
          - gobin  # ※ dep 等もキャッシュしている
          - vendor # 依存パッケージのキャッシュ
        script:
          - IMPORT_PATH="${GOPATH}/src/bitbucket.org/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}"
          - mkdir -pv "${IMPORT_PATH}"
          - tar -cO --exclude-vcs --exclude=bitbucket-pipelines.yml . | tar -xv -C "${IMPORT_PATH}"
          - cd "${IMPORT_PATH}"
          - make setup
          - make

definitions:
  caches:
    gobin: "${GOPATH}/bin"
    vendor: "${GOPATH}/src/bitbucket.org/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/vendor"

※以下のような Makefile の想定

Makefile
DEP := ${GOPATH}/bin/dep

.PHONY: default setup build

default: build

setup: $(DEP)
    $(DEP) ensure -vendor-only

$(DEP):
    go get -u github.com/golang/dep/cmd/dep

build:
    go build

メモ

キャッシュを展開したあとに、同じ階層に tar でソースコードを展開しているのできちんとキャッシュが効くか不安だったが、問題無さそうだった。

参考

1
0
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
1
0