-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ImageOptions
to artifact builder.
#4467
Changes from all commits
6779319
8845485
7ec76c6
fa6b188
662652f
538d50b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
FROM golang:1.12 as builder | ||
|
||
COPY app.go . | ||
# Must use eval to handle GOGCFLAGS with spaces like `-gcflags='all=-N -l'` | ||
ARG GOGCFLAGS | ||
RUN eval go build "${GOGCFLAGS}" -o /app . | ||
ARG SKAFFOLD_GO_GCFLAGS | ||
ARG SKAFFOLD_LD_GCFLAGS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😅 🤦🏽♂️ |
||
# Must use eval to handle gcflags with spaces like `all=-N -l` | ||
RUN eval go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -ldflags="${SKAFFOLD_GO_LDFLAGS}" -o /app . | ||
|
||
FROM gcr.io/distroless/base | ||
# `skaffold debug` uses GOTRACEBACK as an indicator of the Go runtime | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||
/* | ||||||
Copyright 2019 The Skaffold Authors | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
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 buildpacks | ||||||
|
||||||
import "github.com/buildpacks/pack" | ||||||
|
||||||
var buildArgsForDebug = map[string]string{ | ||||||
"GOOGLE_GOGCFLAGS": "'all=-N -l'", // disable build optimization for Golang | ||||||
// TODO: Add for other languages | ||||||
} | ||||||
|
||||||
var buildArgsForDev = map[string]string{ | ||||||
"GOOGLE_GOLDFLAGS": "-w", // omit debug information in build output for Golang | ||||||
// TODO: Add for other languages | ||||||
} | ||||||
|
||||||
type BuildOptionsModifier func(*pack.BuildOptions) *pack.BuildOptions | ||||||
|
||||||
type BuildOptions struct { | ||||||
Tag string | ||||||
modifiers []BuildOptionsModifier | ||||||
} | ||||||
|
||||||
func (b *BuildOptions) AddModifier(m BuildOptionsModifier) *BuildOptions { | ||||||
b.modifiers = append(b.modifiers, m) | ||||||
return b | ||||||
} | ||||||
|
||||||
func (b *BuildOptions) ApplyModifiers(opts *pack.BuildOptions) *pack.BuildOptions { | ||||||
for _, modifier := range b.modifiers { | ||||||
opts = modifier(opts) | ||||||
} | ||||||
return opts | ||||||
} | ||||||
|
||||||
func OptimizeBuildForDebug(opts *pack.BuildOptions) *pack.BuildOptions { | ||||||
if opts == nil { | ||||||
opts = &pack.BuildOptions{} | ||||||
} | ||||||
|
||||||
if opts.Env == nil { | ||||||
opts.Env = make(map[string]string) | ||||||
} | ||||||
|
||||||
for k, v := range buildArgsForDebug { | ||||||
if _, exists := opts.Env[k]; !exists { | ||||||
opts.Env[k] = v | ||||||
} | ||||||
} | ||||||
return opts | ||||||
} | ||||||
|
||||||
func OptimizeBuildForDev(opts *pack.BuildOptions) *pack.BuildOptions { | ||||||
if opts == nil { | ||||||
opts = &pack.BuildOptions{} | ||||||
} | ||||||
|
||||||
if opts.Env == nil { | ||||||
opts.Env = make(map[string]string) | ||||||
} | ||||||
|
||||||
for k, v := range buildArgsForDev { | ||||||
if _, exists := opts.Env[k]; !exists { | ||||||
opts.Env[k] = v | ||||||
} | ||||||
} | ||||||
return opts | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import ( | |
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" | ||
|
@@ -40,7 +41,7 @@ var ( | |
artifactConfigFunction = artifactConfig | ||
) | ||
|
||
func getHashForArtifact(ctx context.Context, depLister DependencyLister, a *latest.Artifact, devMode bool) (string, error) { | ||
func getHashForArtifact(ctx context.Context, depLister DependencyLister, a *latest.Artifact, opts build.BuilderOptions, devMode bool) (string, error) { | ||
var inputs []string | ||
|
||
// Append the artifact's configuration | ||
|
@@ -89,6 +90,13 @@ func getHashForArtifact(ctx context.Context, depLister DependencyLister, a *late | |
inputs = append(inputs, evaluatedEnv...) | ||
} | ||
|
||
// add image options hash | ||
gsquared94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
h, err := opts.Hash() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, it would be nice if builders that have no change between |
||
if err != nil { | ||
return "", fmt.Errorf("evaluating build args: %w", err) | ||
} | ||
inputs = append(inputs, h) | ||
|
||
// get a key for the hashes | ||
hasher := sha256.New() | ||
enc := json.NewEncoder(hasher) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't die on this hill, but this is really supposed to be the most minimal possible example, so this is kind of straying from that. maybe these can go in another example for debug? I don't care too much though