Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
94 changes: 60 additions & 34 deletions builder/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,47 +60,64 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
state.Put("config", &b.config)
state.Put("hook", hook)
state.Put("ui", ui)
generatedData := &packerbuilderdata.GeneratedData{State: state}
var generatedData *packerbuilderdata.GeneratedData
if !b.config.BuildOnly {
generatedData = &packerbuilderdata.GeneratedData{State: state}
}

// Setup the driver that will talk to Docker
state.Put("driver", driver)

steps := []multistep.Step{
&StepDefaultGeneratedData{
GeneratedData: generatedData,
},
&StepTempDir{},
&stepBuild{
buildArgs: b.config.BuildConfig,
},
&StepPull{
bootstrapped: !b.config.BuildConfig.IsDefault(),
GeneratedData: generatedData,
},
&StepRun{},
&communicator.StepConnect{
Config: &b.config.Comm,
Host: commHost(b.config.Comm.Host()),
SSHConfig: b.config.Comm.SSHConfigFunc(),
CustomConnect: map[string]multistep.Step{
"docker": &StepConnectDocker{},
"dockerWindowsContainer": &StepConnectDocker{},
var steps []multistep.Step
if !b.config.BuildOnly {
steps = []multistep.Step{
&StepDefaultGeneratedData{
GeneratedData: generatedData,
},
&StepTempDir{},
&stepBuild{
buildArgs: b.config.BuildConfig,
},
&StepPull{
bootstrapped: !b.config.BuildConfig.IsDefault(),
GeneratedData: generatedData,
},
},
&commonsteps.StepProvision{},
&commonsteps.StepCleanupTempKeys{
Comm: &b.config.Comm,
},
&StepRun{},
&communicator.StepConnect{
Config: &b.config.Comm,
Host: commHost(b.config.Comm.Host()),
SSHConfig: b.config.Comm.SSHConfigFunc(),
CustomConnect: map[string]multistep.Step{
"docker": &StepConnectDocker{},
"dockerWindowsContainer": &StepConnectDocker{},
},
},
&commonsteps.StepProvision{},
&commonsteps.StepCleanupTempKeys{
Comm: &b.config.Comm,
},
}
} else {
steps = []multistep.Step{
&stepBuild{
buildArgs: b.config.BuildConfig,
},
&commonsteps.StepCleanupTempKeys{
Comm: &b.config.Comm,
},
}
}

if b.config.Discard {
log.Print("[DEBUG] Container will be discarded")
} else if b.config.Commit {
log.Print("[DEBUG] Container will be committed")
steps = append(steps, &StepSetDefaults{})
steps = append(steps, &StepCommit{
GeneratedData: generatedData,
})
if !b.config.BuildOnly {
steps = append(steps, &StepCommit{
GeneratedData: generatedData,
})
}
} else if b.config.ExportPath != "" {
log.Printf("[DEBUG] Container will be exported to %s", b.config.ExportPath)
steps = append(steps, new(StepExport))
Expand Down Expand Up @@ -129,11 +146,20 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)

var artifact packersdk.Artifact
if b.config.Commit {
artifact = &ImportArtifact{
IdValue: state.Get("image_id").(string),
BuilderIdValue: BuilderIdImport,
Driver: driver,
StateData: stateData,
if b.config.BuildOnly {
artifact = &ImportArtifact{
IdValue: b.config.Image,
BuilderIdValue: BuilderIdImport,
Driver: driver,
StateData: stateData,
}
} else {
artifact = &ImportArtifact{
IdValue: state.Get("image_id").(string),
BuilderIdValue: BuilderIdImport,
Driver: driver,
StateData: stateData,
}
}
} else {
artifact = &ExportArtifact{
Expand Down
4 changes: 4 additions & 0 deletions builder/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type Config struct {
// [Bootstrapping a build with a Dockerfile](#bootstrapping-a-build-with-a-dockerfile)
// section of this documentation.
BuildConfig DockerfileBootstrapConfig `mapstructure:"build"`
// If true, the resulting image will be built only using `build` section,
// which effectively means that the image will be buit using `docker build`
// command only.
BuildOnly bool `mapstructure:"build_only" required:"false"`
// Set the author (e-mail) of a commit.
Author string `mapstructure:"author"`
// Dockerfile instructions to add to the commit. Example of instructions
Expand Down
2 changes: 2 additions & 0 deletions builder/docker/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs-partials/builder/docker/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[Bootstrapping a build with a Dockerfile](#bootstrapping-a-build-with-a-dockerfile)
section of this documentation.

- `build_only` (string) - If true, use `docker build` step only. Defaults to false.

- `author` (string) - Set the author (e-mail) of a commit.

- `changes` ([]string) - Dockerfile instructions to add to the commit. Example of instructions
Expand Down