forked from GoogleCloudPlatform/buildpacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build application from a srv directory in Go App Engine gomod buildpack
This fixes an incompatiblity with the appengine package which expects files to be compiled from srv for go.mod apps: https://github.com/golang/appengine/blob/553959209a20f3be281c16dd5be5c740a893978f/delay/delay.go#L136. All source code is moved from /workspace to <layer>/srv and `go build` is then invoked with the latter as the work directory. The resulting binary will correctly have /srv/ in the stored file paths. PiperOrigin-RevId: 327901991 Change-Id: Ic08452e67af3f6c20741e6661931cec717460930
- Loading branch information
1 parent
582453f
commit 6f91880
Showing
9 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module example.com/package | ||
|
||
go 1.11 | ||
|
||
require rsc.io/quote v1.5.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package main tests building source that has a go.mod file without gomod dependencies. | ||
// It also tests compatiblity with the golang/appengine package. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
|
||
"rsc.io/quote" | ||
) | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
if got, want := quote.Hello(), "Hello, world."; got != want { | ||
fmt.Fprintf(w, "FAIL: quote.Hello() = %s, want %s\n", got, want) | ||
return | ||
} | ||
|
||
// Check that the path at compile time includes /srv/. This is done for compatibility with the | ||
// appengine package, which requires it for historical reasons. See the go/appengine_gomod | ||
// buildpack. | ||
_, file, _, ok := runtime.Caller(0) | ||
if !ok { | ||
fmt.Fprintln(w, "FAIL: runtime.Caller(0) not ok") | ||
return | ||
} | ||
sep := string(filepath.Separator) | ||
srv := sep + "srv" + sep | ||
if !strings.Contains(file, srv) { | ||
fmt.Fprintf(w, "FAIL: caller file path %s does not contain %s\n", file, srv) | ||
return | ||
} | ||
fmt.Fprintln(w, "PASS") | ||
} | ||
|
||
func main() { | ||
http.HandleFunc("/", handler) | ||
http.ListenAndServe(":"+os.Getenv("PORT"), nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ go_binary( | |
deps = [ | ||
"//pkg/env", | ||
"//pkg/gcpbuildpack", | ||
"//pkg/golang", | ||
], | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters