@@ -60,47 +60,64 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
6060 state .Put ("config" , & b .config )
6161 state .Put ("hook" , hook )
6262 state .Put ("ui" , ui )
63- generatedData := & packerbuilderdata.GeneratedData {State : state }
63+ var generatedData * packerbuilderdata.GeneratedData
64+ if ! b .config .BuildOnly {
65+ generatedData = & packerbuilderdata.GeneratedData {State : state }
66+ }
6467
6568 // Setup the driver that will talk to Docker
6669 state .Put ("driver" , driver )
6770
68- steps := []multistep.Step {
69- & StepDefaultGeneratedData {
70- GeneratedData : generatedData ,
71- },
72- & StepTempDir {},
73- & stepBuild {
74- buildArgs : b .config .BuildConfig ,
75- },
76- & StepPull {
77- bootstrapped : ! b .config .BuildConfig .IsDefault (),
78- GeneratedData : generatedData ,
79- },
80- & StepRun {},
81- & communicator.StepConnect {
82- Config : & b .config .Comm ,
83- Host : commHost (b .config .Comm .Host ()),
84- SSHConfig : b .config .Comm .SSHConfigFunc (),
85- CustomConnect : map [string ]multistep.Step {
86- "docker" : & StepConnectDocker {},
87- "dockerWindowsContainer" : & StepConnectDocker {},
71+ var steps []multistep.Step
72+ if ! b .config .BuildOnly {
73+ steps = []multistep.Step {
74+ & StepDefaultGeneratedData {
75+ GeneratedData : generatedData ,
76+ },
77+ & StepTempDir {},
78+ & stepBuild {
79+ buildArgs : b .config .BuildConfig ,
80+ },
81+ & StepPull {
82+ bootstrapped : ! b .config .BuildConfig .IsDefault (),
83+ GeneratedData : generatedData ,
8884 },
89- },
90- & commonsteps.StepProvision {},
91- & commonsteps.StepCleanupTempKeys {
92- Comm : & b .config .Comm ,
93- },
85+ & StepRun {},
86+ & communicator.StepConnect {
87+ Config : & b .config .Comm ,
88+ Host : commHost (b .config .Comm .Host ()),
89+ SSHConfig : b .config .Comm .SSHConfigFunc (),
90+ CustomConnect : map [string ]multistep.Step {
91+ "docker" : & StepConnectDocker {},
92+ "dockerWindowsContainer" : & StepConnectDocker {},
93+ },
94+ },
95+ & commonsteps.StepProvision {},
96+ & commonsteps.StepCleanupTempKeys {
97+ Comm : & b .config .Comm ,
98+ },
99+ }
100+ } else {
101+ steps = []multistep.Step {
102+ & stepBuild {
103+ buildArgs : b .config .BuildConfig ,
104+ },
105+ & commonsteps.StepCleanupTempKeys {
106+ Comm : & b .config .Comm ,
107+ },
108+ }
94109 }
95110
96111 if b .config .Discard {
97112 log .Print ("[DEBUG] Container will be discarded" )
98113 } else if b .config .Commit {
99114 log .Print ("[DEBUG] Container will be committed" )
100115 steps = append (steps , & StepSetDefaults {})
101- steps = append (steps , & StepCommit {
102- GeneratedData : generatedData ,
103- })
116+ if ! b .config .BuildOnly {
117+ steps = append (steps , & StepCommit {
118+ GeneratedData : generatedData ,
119+ })
120+ }
104121 } else if b .config .ExportPath != "" {
105122 log .Printf ("[DEBUG] Container will be exported to %s" , b .config .ExportPath )
106123 steps = append (steps , new (StepExport ))
@@ -129,11 +146,20 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
129146
130147 var artifact packersdk.Artifact
131148 if b .config .Commit {
132- artifact = & ImportArtifact {
133- IdValue : state .Get ("image_id" ).(string ),
134- BuilderIdValue : BuilderIdImport ,
135- Driver : driver ,
136- StateData : stateData ,
149+ if b .config .BuildOnly {
150+ artifact = & ImportArtifact {
151+ IdValue : b .config .Image ,
152+ BuilderIdValue : BuilderIdImport ,
153+ Driver : driver ,
154+ StateData : stateData ,
155+ }
156+ } else {
157+ artifact = & ImportArtifact {
158+ IdValue : state .Get ("image_id" ).(string ),
159+ BuilderIdValue : BuilderIdImport ,
160+ Driver : driver ,
161+ StateData : stateData ,
162+ }
137163 }
138164 } else {
139165 artifact = & ExportArtifact {
0 commit comments