OhhhThatVarun
OhhhThatVarun

Reputation: 4321

errors parsing go.mod How to deploy go app on App Engine with Cloud build?

So I have this Go app which is running fine on the localhost but I want to host on the google cloud and the cloud is already setup. The whole dir tree looks like this.

gocode
---bin
---pkg
---src
  ---cloud.google.com
  ---github.com
  ...
  ---appname
    ---auth
    ---database
    ...
    ---main.go
    ---app.yaml
    ---cloudbuild.yaml
    ---go.mod

Here is the app.yaml

runtime: go112
api_version: go1

handlers:
- url: /.*
  script: _go_app

Here is the cloudbuild.yaml

steps:

- name: 'golang'
  args: ['go', 'build', '.']
  env: ['GO111MODULE=on']

- name: 'gcr.io/cloud-builders/go'
  args: ['get', '-d', 'appname']
  env: ['GOPATH=/gopath/','MODE=dev']
  volumes:
  - name: 'go'
    path: '/gopath'

- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy']
  env: ['GOPATH=/gopath/','MODE=dev']
  volumes:
  - name: 'go'
    path: '/gopath'

Here is the go.mod

module github.com/Raj-Varun/appname-API/

require github.com/spf13/viper

When I'm running gcloud builds submit --config cloudbuild.yaml . I'm getting this error

tarting Step #0
Step #0: Pulling image: golang
Step #0: Using default tag: latest
Step #0: latest: Pulling from library/golang
Step #0: Digest: sha256:a50a9364e9170ab5f5b03389ed33b9271b4a7b6bbb0ab41c4035adb3078927bc
Step #0: Status: Downloaded newer image for golang:latest
Step #0: docker.io/library/golang:latest
Step #0: go: errors parsing go.mod:
Step #0: /workspace/go.mod:3: usage: require module/path v1.2.3
Finished Step #0
ERROR
ERROR: build step 0 "golang" failed: exit status 1

Upvotes: 0

Views: 9409

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 75775

As explained in the error message, the require package path must have this format require module/path v1.2.3

In your go.mod, you have this:

require github.com/spf13/viper

You have the module/path but you don't have the version!

Go the the viper github project and take the release version that you want. For example

require github.com/spf13/viper v1.4.0

You can also try to perform a go mod tidy for automatically building and cleaning your go.mod file

Upvotes: 3

Related Questions