Skip to content
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

model: fast build fields to dockerInfo.buildDetails [ch1136] #888

Merged
merged 5 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/dockercompose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (s Service) ToManifest(dcConfigPath string) (manifest model.Manifest,

if s.DfPath == "" {
// DC service may not have Dockerfile -- e.g. may be just an image that we pull and run.
// So, don't parse a non-existent Dockerfile for mount info.
return m, nil, nil
}

Expand All @@ -179,7 +180,9 @@ func (s Service) ToManifest(dcConfigPath string) (manifest model.Manifest,
return model.Manifest{}, nil, err
}

m.Mounts = mounts
dcInfo.Mounts = mounts
m = m.WithDeployInfo(dcInfo)

return m, []string{s.DfPath}, nil
}

Expand Down
29 changes: 13 additions & 16 deletions internal/engine/build_and_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestGKEDeploy(t *testing.T) {
f := newBDFixture(t, k8s.EnvGKE)
defer f.TearDown()

_, err := f.bd.BuildAndDeploy(f.ctx, SanchoManifest, store.BuildStateClean)
_, err := f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), store.BuildStateClean)
if err != nil {
t.Fatal(err)
}
Expand All @@ -62,7 +62,7 @@ func TestDockerForMacDeploy(t *testing.T) {
f := newBDFixture(t, k8s.EnvDockerDesktop)
defer f.TearDown()

_, err := f.bd.BuildAndDeploy(f.ctx, SanchoManifest, store.BuildStateClean)
_, err := f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), store.BuildStateClean)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -92,15 +92,15 @@ func TestNamespaceGKE(t *testing.T) {
assert.Equal(t, "", string(f.sCli.Namespace))
assert.Equal(t, "", string(f.k8s.LastPodQueryNamespace))

result, err := f.bd.BuildAndDeploy(f.ctx, SanchoManifest, store.BuildStateClean)
result, err := f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), store.BuildStateClean)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, "sancho-ns", string(result.Namespace))

bs := store.NewBuildState(result, nil).WithDeployInfo(f.deployInfo())
result, err = f.bd.BuildAndDeploy(f.ctx, SanchoManifest, bs)
result, err = f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), bs)
if err != nil {
t.Fatal(err)
}
Expand All @@ -114,7 +114,7 @@ func TestContainerBuildLocal(t *testing.T) {
defer f.TearDown()

bs := store.NewBuildState(alreadyBuilt, nil).WithDeployInfo(f.deployInfo())
result, err := f.bd.BuildAndDeploy(f.ctx, SanchoManifest, bs)
result, err := f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), bs)
if err != nil {
t.Fatal(err)
}
Expand All @@ -141,7 +141,7 @@ func TestContainerBuildSynclet(t *testing.T) {
defer f.TearDown()

bs := store.NewBuildState(alreadyBuilt, nil).WithDeployInfo(f.deployInfo())
result, err := f.bd.BuildAndDeploy(f.ctx, SanchoManifest, bs)
result, err := f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), bs)
if err != nil {
t.Fatal(err)
}
Expand All @@ -167,7 +167,7 @@ func TestIncrementalBuildFailure(t *testing.T) {

bs := store.NewBuildState(alreadyBuilt, nil).WithDeployInfo(f.deployInfo())
f.docker.ExecErrorToThrow = docker.ExitError{ExitCode: 1}
_, err := f.bd.BuildAndDeploy(ctx, SanchoManifest, bs)
_, err := f.bd.BuildAndDeploy(ctx, NewSanchoFastBuildManifest(f), bs)
msg := "Command failed with exit code: 1"
if err == nil || !strings.Contains(err.Error(), msg) {
t.Fatalf("Expected error message %q, actual: %v", msg, err)
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestFallBackToImageDeploy(t *testing.T) {
f.docker.ExecErrorToThrow = errors.New("some random error")

bs := store.NewBuildState(alreadyBuilt, nil).WithDeployInfo(f.deployInfo())
_, err := f.bd.BuildAndDeploy(f.ctx, SanchoManifest, bs)
_, err := f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), bs)
if err != nil {
t.Fatal(err)
}
Expand All @@ -213,7 +213,7 @@ func TestNoFallbackForDontFallBackError(t *testing.T) {
f.docker.ExecErrorToThrow = DontFallBackErrorf("i'm melllting")

bs := store.NewBuildState(alreadyBuilt, nil).WithDeployInfo(f.deployInfo())
_, err := f.bd.BuildAndDeploy(f.ctx, SanchoManifest, bs)
_, err := f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), bs)
if err == nil {
t.Errorf("Expected this error to fail fallback tester and propogate back up")
}
Expand All @@ -232,8 +232,7 @@ func TestIncrementalBuildTwice(t *testing.T) {
defer f.TearDown()
ctx := output.CtxForTest()

manifest := NewSanchoManifest()
manifest.Mounts[0].LocalPath = f.Path()
manifest := NewSanchoFastBuildManifest(f)
aPath := filepath.Join(f.Path(), "a.txt")
bPath := filepath.Join(f.Path(), "b.txt")
f.WriteFile("a.txt", "a")
Expand Down Expand Up @@ -284,8 +283,7 @@ func TestIncrementalBuildTwiceDeadPod(t *testing.T) {
defer f.TearDown()
ctx := output.CtxForTest()

manifest := NewSanchoManifest()
manifest.Mounts[0].LocalPath = f.Path()
manifest := NewSanchoFastBuildManifest(f)
aPath := filepath.Join(f.Path(), "a.txt")
bPath := filepath.Join(f.Path(), "b.txt")
f.WriteFile("a.txt", "a")
Expand Down Expand Up @@ -361,7 +359,7 @@ func TestBaDForgetsImages(t *testing.T) {
f.k8s.SetPodsWithImageResp(pod1)

bs := store.NewBuildState(alreadyBuilt, nil).WithDeployInfo(f.deployInfo())
_, err := f.bd.BuildAndDeploy(f.ctx, SanchoManifest, bs)
_, err := f.bd.BuildAndDeploy(f.ctx, NewSanchoFastBuildManifest(f), bs)
if err != nil {
t.Fatal(err)
}
Expand All @@ -376,8 +374,7 @@ func TestIgnoredFiles(t *testing.T) {
defer f.TearDown()
ctx := output.CtxForTest()

manifest := NewSanchoManifest()
manifest.Mounts[0].LocalPath = f.Path()
manifest := NewSanchoFastBuildManifest(f)

manifest = manifest.WithRepos([]model.LocalGithubRepo{
model.LocalGithubRepo{
Expand Down
73 changes: 41 additions & 32 deletions internal/engine/image_build_and_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,41 +124,48 @@ func (ibd *ImageBuildAndDeployer) build(ctx context.Context, manifest model.Mani

go ibd.maybeCreateCacheFrom(ctx, ref, state, manifest, cacheRef)

} else if !state.HasImage() || ibd.updateMode == UpdateModeNaive {
// No existing image to build off of, need to build from scratch
ps.StartPipelineStep(ctx, "Building from scratch: [%s]", name)
defer ps.EndPipelineStep(ctx)
} else if fbInfo := manifest.FastBuildInfo(); !fbInfo.Empty() {
if !state.HasImage() || ibd.updateMode == UpdateModeNaive {
// No existing image to build off of, need to build from scratch
ps.StartPipelineStep(ctx, "Building from scratch: [%s]", name)
defer ps.EndPipelineStep(ctx)

df := ibd.baseDockerfile(manifest, cacheRef)
steps := manifest.Steps
ref, err := ibd.b.BuildImageFromScratch(ctx, ps, name, df, manifest.Mounts, ignore.CreateBuildContextFilter(manifest), steps, manifest.Entrypoint)
df := ibd.baseDockerfile(fbInfo, cacheRef, manifest.DockerInfo.CachePaths())
steps := fbInfo.Steps
ref, err := ibd.b.BuildImageFromScratch(ctx, ps, name, df, fbInfo.Mounts, ignore.CreateBuildContextFilter(manifest), steps, fbInfo.Entrypoint)

if err != nil {
return nil, err
}
n = ref
go ibd.maybeCreateCacheFrom(ctx, ref, state, manifest, cacheRef)
if err != nil {
return nil, err
}
n = ref
go ibd.maybeCreateCacheFrom(ctx, ref, state, manifest, cacheRef)

} else {
changed, err := state.FilesChangedSinceLastResultImage()
if err != nil {
return nil, err
}
} else {
// We have an existing image, can do an iterative build
changed, err := state.FilesChangedSinceLastResultImage()
if err != nil {
return nil, err
}

cf, err := build.FilesToPathMappings(changed, manifest.Mounts)
if err != nil {
return nil, err
}
cf, err := build.FilesToPathMappings(changed, fbInfo.Mounts)
if err != nil {
return nil, err
}

ps.StartPipelineStep(ctx, "Building from existing: [%s]", name)
defer ps.EndPipelineStep(ctx)
ps.StartPipelineStep(ctx, "Building from existing: [%s]", name)
defer ps.EndPipelineStep(ctx)

steps := manifest.Steps
ref, err := ibd.b.BuildImageFromExisting(ctx, ps, state.LastResult.Image, cf, ignore.CreateBuildContextFilter(manifest), steps)
if err != nil {
return nil, err
steps := fbInfo.Steps
ref, err := ibd.b.BuildImageFromExisting(ctx, ps, state.LastResult.Image, cf, ignore.CreateBuildContextFilter(manifest), steps)
if err != nil {
return nil, err
}
n = ref
}
n = ref
} else {
// Theoretically this should never trip b/c we `validate` the manifest beforehand...?
// If we get here, something is very wrong.
return nil, fmt.Errorf("manifest %q has no valid buildDetails (neither StaticBuildInfo nor FastBuildInfo)", manifest.Name)
}

if !ibd.canSkipPush() {
Expand Down Expand Up @@ -282,8 +289,9 @@ func (ibd *ImageBuildAndDeployer) maybeCreateCacheFrom(ctx context.Context, sour
return
}

baseDockerfile := dockerfile.Dockerfile(manifest.BaseDockerfile)
baseDockerfile := dockerfile.Dockerfile(manifest.FastBuildInfo().BaseDockerfile)
var buildArgs model.DockerBuildArgs

if sbInfo := manifest.StaticBuildInfo(); !sbInfo.Empty() {
staticDockerfile := dockerfile.Dockerfile(sbInfo.Dockerfile)
ok := true
Expand Down Expand Up @@ -323,13 +331,14 @@ func (ibd *ImageBuildAndDeployer) staticDockerfile(manifest model.Manifest, cach
Append(restDf)
}

func (ibd *ImageBuildAndDeployer) baseDockerfile(manifest model.Manifest, cacheRef reference.NamedTagged) dockerfile.Dockerfile {
df := dockerfile.Dockerfile(manifest.BaseDockerfile)
func (ibd *ImageBuildAndDeployer) baseDockerfile(fbInfo model.FastBuild,
cacheRef reference.NamedTagged, cachePaths []string) dockerfile.Dockerfile {
df := dockerfile.Dockerfile(fbInfo.BaseDockerfile)
if cacheRef == nil {
return df
}

if len(manifest.DockerInfo.CachePaths()) == 0 {
if len(cachePaths) == 0 {
return df
}

Expand Down
4 changes: 2 additions & 2 deletions internal/engine/image_build_and_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestBaseDockerfileWithCache(t *testing.T) {
f := newIBDFixture(t)
defer f.TearDown()

manifest := NewSanchoManifestWithCache([]string{"/root/.cache"})
manifest := NewSanchoFastBuildManifestWithCache(f, []string{"/root/.cache"})
cache := "gcr.io/some-project-162817/sancho:tilt-cache-3de427a264f80719a58a9abd456487b3"
f.docker.Images[cache] = types.ImageInspect{}

Expand All @@ -71,7 +71,7 @@ func TestDeployTwinImages(t *testing.T) {
f := newIBDFixture(t)
defer f.TearDown()

sancho := NewSanchoManifest()
sancho := NewSanchoFastBuildManifest(f)
manifest := sancho.WithDeployInfo(sancho.K8sInfo().AppendYAML(SanchoTwinYAML))
result, err := f.ibd.BuildAndDeploy(f.ctx, manifest, store.BuildStateClean)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions internal/engine/local_container_build_and_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func (cbd *LocalContainerBuildAndDeployer) BuildAndDeploy(ctx context.Context, m
return store.BuildResult{}, RedirectToNextBuilderf("prev. build state is empty; container build does not support initial deploy")
}

if manifest.IsStaticBuild() {
return store.BuildResult{}, RedirectToNextBuilderf("container build does not support static dockerfiles")
fbInfo := manifest.FastBuildInfo()
if fbInfo.Empty() {
return store.BuildResult{}, RedirectToNextBuilderf("container build only supports FastBuilds")
}

// Otherwise, manifest has already been deployed; try to update in the running container
Expand All @@ -67,12 +68,12 @@ func (cbd *LocalContainerBuildAndDeployer) BuildAndDeploy(ctx context.Context, m
return store.BuildResult{}, RedirectToNextBuilderf("no deploy info")
}

cf, err := build.FilesToPathMappings(state.FilesChanged(), manifest.Mounts)
cf, err := build.FilesToPathMappings(state.FilesChanged(), fbInfo.Mounts)
if err != nil {
return store.BuildResult{}, err
}
logger.Get(ctx).Infof(" → Updating container…")
boiledSteps, err := build.BoilSteps(manifest.Steps, cf)
boiledSteps, err := build.BoilSteps(fbInfo.Steps, cf)
if err != nil {
return store.BuildResult{}, err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/engine/synclet_build_and_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (sbd *SyncletBuildAndDeployer) canSyncletBuild(ctx context.Context,
return fmt.Errorf("prev. build state is empty; synclet build does not support initial deploy")
}

if manifest.IsStaticBuild() {
return fmt.Errorf("container build does not support static dockerfiles")
if fbInfo := manifest.FastBuildInfo(); fbInfo.Empty() {
return fmt.Errorf("container build only supports FastBuilds")
}

// Can't do container update if we don't know what container manifest is running in.
Expand All @@ -95,7 +95,7 @@ func (sbd *SyncletBuildAndDeployer) updateViaSynclet(ctx context.Context,
defer span.Finish()

paths, err := build.FilesToPathMappings(
state.FilesChanged(), manifest.Mounts)
state.FilesChanged(), manifest.FastBuildInfo().Mounts)
if err != nil {
return store.BuildResult{}, err
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (sbd *SyncletBuildAndDeployer) updateViaSynclet(ctx context.Context,
return store.BuildResult{}, fmt.Errorf("no deploy info")
}

cmds, err := build.BoilSteps(manifest.Steps, paths)
cmds, err := build.BoilSteps(manifest.FastBuildInfo().Steps, paths)
if err != nil {
return store.BuildResult{}, err
}
Expand Down
27 changes: 15 additions & 12 deletions internal/engine/testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ RUN go install github.com/windmilleng/sancho
ENTRYPOINT /go/bin/sancho
`

type pather interface {
Path() string
}

var SanchoRef, _ = reference.ParseNormalizedNamed("gcr.io/some-project-162817/sancho")

func NewSanchoManifest() model.Manifest {
m := model.Manifest{
Name: "sancho",
DockerInfo: model.DockerInfo{
DockerRef: SanchoRef,
},
func NewSanchoFastBuildManifest(fixture pather) model.Manifest {
fbInfo := model.FastBuild{
BaseDockerfile: SanchoBaseDockerfile,
Mounts: []model.Mount{
model.Mount{
LocalPath: "/src/sancho",
LocalPath: fixture.Path(),
ContainerPath: "/go/src/github.com/windmilleng/sancho",
},
},
Expand All @@ -41,14 +41,20 @@ func NewSanchoManifest() model.Manifest {
}),
Entrypoint: model.Cmd{Argv: []string{"/go/bin/sancho"}},
}
m := model.Manifest{
Name: "sancho",
DockerInfo: model.DockerInfo{
DockerRef: SanchoRef,
}.WithBuildDetails(fbInfo),
}

m = m.WithDeployInfo(model.K8sInfo{YAML: SanchoYAML})

return m
}

func NewSanchoManifestWithCache(paths []string) model.Manifest {
manifest := NewSanchoManifest()
func NewSanchoFastBuildManifestWithCache(fixture pather, paths []string) model.Manifest {
manifest := NewSanchoFastBuildManifest(fixture)
manifest.DockerInfo = manifest.DockerInfo.WithCachePaths(paths)
return manifest
}
Expand All @@ -71,6 +77,3 @@ func NewSanchoStaticManifestWithCache(paths []string) model.Manifest {
manifest.DockerInfo = manifest.DockerInfo.WithCachePaths(paths)
return manifest
}

var SanchoManifest = NewSanchoManifest()
var SanchoStaticManifest = NewSanchoStaticManifest()
Loading