Skip to content

Commit

Permalink
[Resolves #71] Add trimpath arg to gobuild (#102)
Browse files Browse the repository at this point in the history
* Add trimpath arg to gobuild

* Add build constraints for trimpath usage

* Reduce duplications across go versions

* Change trimpath fn-files for better names

* Attempt to apply with minikube on Travis

* Attempt to apply with KinD on Travis

* Install kind thru curl to not affect build
  • Loading branch information
stanleynguyen authored and jonjohnsonjr committed Nov 1, 2019
1 parent a6277d0 commit be4e1ff
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
22 changes: 17 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
sudo: false
sudo: required

dist: trusty

services:
- docker

language:
- go

go:
- "1.12"
- "1.13"
- '1.12'
- '1.13'

git:
depth: 1

install: true
install: true # skipping the default go dependencies install step

before_script:
# Download and install kubectl
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Download and install KinD
- curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.5.1/kind-$(uname)-amd64 && chmod +x ./kind && sudo mv kind /usr/local/bin/
# Create a new Kubernetes cluster using KinD
- kind create cluster
- export KUBECONFIG=$(kind get kubeconfig-path)

script:
# Verify that all source files are correctly formatted.
- find . -name "*.go" | grep -v vendor/ | xargs gofmt -d -e -l

- go clean -i
- go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...

- bash integration_test.sh
# TODO: Set up coverage.
#after_success:
# - bash <(curl -s https://codecov.io/bash)
2 changes: 2 additions & 0 deletions integration_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go install ./cmd/ko
ko apply -f ./cmd/ko/test -L
3 changes: 2 additions & 1 deletion pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ func build(ip string, platform v1.Platform, disableOptimizations bool) (string,
}
file := filepath.Join(tmpDir, "out")

args := make([]string, 0, 6)
args := make([]string, 0, 7)
args = append(args, "build")
if disableOptimizations {
// Disable optimizations (-N) and inlining (-l).
args = append(args, "-gcflags", "all=-N -l")
}
args = append(args, "-o", file)
args = addGo113TrimPathFlag(args)
args = append(args, ip)
cmd := exec.Command("go", args...)

Expand Down
22 changes: 22 additions & 0 deletions pkg/build/trimpath_113.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 Google LLC All Rights Reserved.
//
// 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.
//
// house flag adding function for go1.13 and later version with -trimpath available
// +build go1.13

package build

func addGo113TrimPathFlag(args []string) []string {
return append(args, "-trimpath")
}
22 changes: 22 additions & 0 deletions pkg/build/trimpath_pre113.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 Google LLC All Rights Reserved.
//
// 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.
//
// house placeholder function for go1.12 and earlier version without -trimpath
// +build !go1.13

package build

func addGo113TrimPathFlag(args []string) []string {
return args
}

0 comments on commit be4e1ff

Please sign in to comment.