Andy Fusniak
Andy Fusniak

Reputation: 1638

How to pass -ldflags to GAE build?

I have an HTTP service written in Go. Inside main.go I have a global version string.

package main

var version string

Locally, I build using -ldflags "-X main.version=$VERSION where $VERSION is determined by the shell environment, like so:

VERSION=v0.16.0 go build ./cmd/app -ldflags "-X main.version=$VERSION

I've recently decided to trial Google App Engine and started with a basic YAML file:

runtime: go111

handlers:
- url: /.*
  script: auto

What can I set in the YAML file in order to instruct GAE to build with the equivalent ldflags to bake in my version string?

I should also mention I use go modules with GO111MODULE=on locally when building.

Upvotes: 1

Views: 177

Answers (1)

avivl
avivl

Reputation: 401

You can't do it with you app.yaml file. However, you can use Cloud build to build and deploy your app to App Engine. In your cloudbuild.yaml you can add a line to the build step

args: ['build', '-a', '-installsuffix', 'cgo', '-ldflags', '''-w''', '-o', 'main', './main.go']

Upvotes: 0

Related Questions