LoginSignup
4
0

More than 3 years have passed since last update.

Cloud FunctionsにGoのコードをdeployしようとしたら嵌ったこと

Last updated at Posted at 2019-06-06

CloudFunctionsにデプロイする

以下のようなディレクトリ構成下において、operategcloud functions deploy --runtime go111を実行するとエラーが吐かれる。

C:.
│  go.mod
│  go.sum
│  main.go
│
└─ operator
         operate.go
         utils.go

以下がエラー内容。どうやらパッケージが見つからないらしい。

Deploying function (may take a while - up to 2 minutes)...failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: /tmp/sgb/gopath/src/serverlessapp/vendor/o
perator/main.go:5:2 cannot find package "github.com/deckarep/golang-set" in any of:
/tmp/sgb/gopath/src/serverlessapp/vendor/github.com/deckarep/golang-set (vendor tree)
/go/src/github.com/deckarep/golang-set (from $GOROOT)
/tmp/sgb/gopath/src/github.com/deckarep/golang-set (from $GOPATH)
/tmp/sgb/gopath/src/serverlessapp/vendor/operator/utils.go:4:2: cannot find package "golang.org/x/net/context" in any
of:/tmp/sgb/gopath/src/serverlessapp/vendor/golang.org/x/net/context (vendor tree)
/go/src/golang.org/x/net/context (from $GOROOT)
/tmp/sgb/gopath/src/golang.org/x/net/context (from $GOPATH)
...(以下略)

対応策

go.modのあるディレクトリでgcloud functions deployを実行する。
カレントディレクトリからでないとデフォルトでは見つけてくれない。

デプロイする関数のあるコードだけ指定

--sourceでソースコードの場所を指定してあげると、ソースコードとgo.modが別の場所にあってもデプロイできそう。

公式ドキュメントでも指摘されていた。

  • Note that if you do not specify the --source flag:
    • Current directory will be used for new function deployments.

参考

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