@@ -17,11 +17,17 @@ limitations under the License.
17
17
package integration
18
18
19
19
import (
20
+ "errors"
21
+ "io"
22
+ "os"
23
+ "path/filepath"
20
24
"strings"
21
25
"testing"
22
26
23
27
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags"
24
28
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
29
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
30
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/walk"
25
31
"github.com/GoogleContainerTools/skaffold/testutil"
26
32
)
27
33
@@ -105,3 +111,97 @@ func TestDeployWithInCorrectConfig(t *testing.T) {
105
111
t .Errorf ("failed without saying the reason: %s" , output )
106
112
}
107
113
}
114
+
115
+ // Verify that we can deploy without artifact details (https://github.com/GoogleContainerTools/skaffold/issues/4616)
116
+ func TestDeployWithoutWorkspaces (t * testing.T ) {
117
+ MarkIntegrationTest (t , NeedsGcp )
118
+
119
+ ns , _ := SetupNamespace (t )
120
+
121
+ outputBytes := skaffold .Build ("--quiet" ).InDir ("examples/nodejs" ).InNs (ns .Name ).RunOrFailOutput (t )
122
+ // Parse the Build Output
123
+ buildArtifacts , err := flags .ParseBuildOutput (outputBytes )
124
+ failNowIfError (t , err )
125
+ if len (buildArtifacts .Builds ) != 1 {
126
+ t .Fatalf ("expected 1 artifact to be built, but found %d" , len (buildArtifacts .Builds ))
127
+ }
128
+
129
+ tmpDir := testutil .NewTempDir (t )
130
+ buildOutputFile := tmpDir .Path ("build.out" )
131
+ tmpDir .Write ("build.out" , string (outputBytes ))
132
+ copyFiles (tmpDir .Root (), "examples/nodejs/skaffold.yaml" )
133
+ copyFiles (tmpDir .Root (), "examples/nodejs/k8s" )
134
+
135
+ // Run Deploy using the build output
136
+ // See https://github.com/GoogleContainerTools/skaffold/issues/2372 on why status-check=false
137
+ skaffold .Deploy ("--build-artifacts" , buildOutputFile , "--status-check=false" ).InDir (tmpDir .Root ()).InNs (ns .Name ).RunOrFail (t )
138
+ }
139
+
140
+ // Copies a file or directory tree. There are 2x3 cases:
141
+ // 1. If _src_ is a file,
142
+ // 1. and _dst_ exists and is a file then _src_ is copied into _dst_
143
+ // 2. and _dst_ exists and is a directory, then _src_ is copied as _dst/$(basename src)_
144
+ // 3. and _dst_ does not exist, then _src_ is copied as _dst_.
145
+ // 2. If _src_ is a directory,
146
+ // 1. and _dst_ exists and is a file, then return an error
147
+ // 2. and _dst_ exists and is a directory, then src is copied as _dst/$(basename src)_
148
+ // 3. and _dst_ does not exist, then src is copied as _dst/src[1:]_.
149
+ func copyFiles (dst , src string ) error {
150
+ if util .IsFile (src ) {
151
+ switch {
152
+ case util .IsFile (dst ): // copy _src_ to _dst_
153
+ case util .IsDir (dst ): // copy _src_ to _dst/src[-1]
154
+ dst = filepath .Join (dst , filepath .Base (src ))
155
+ default : // copy _src_ to _dst_
156
+ if err := os .MkdirAll (filepath .Dir (dst ), os .ModePerm ); err != nil {
157
+ return err
158
+ }
159
+ }
160
+ in , err := os .Open (src )
161
+ if err != nil {
162
+ return err
163
+ }
164
+ out , err := os .Create (dst )
165
+ if err != nil {
166
+ return err
167
+ }
168
+ _ , err = io .Copy (out , in )
169
+ return err
170
+ } else if ! util .IsDir (src ) {
171
+ return errors .New ("src does not exist" )
172
+ }
173
+ // so src is a directory
174
+ if util .IsFile (dst ) {
175
+ return errors .New ("cannot copy directory into file" )
176
+ }
177
+ srcPrefix := src
178
+ if util .IsDir (dst ) { // src is copied to _dst/$(basename src)
179
+ srcPrefix = filepath .Dir (src )
180
+ } else if err := os .MkdirAll (filepath .Dir (dst ), os .ModePerm ); err != nil {
181
+ return err
182
+ }
183
+ return walk .From (src ).Unsorted ().WhenIsFile ().Do (func (path string , _ walk.Dirent ) error {
184
+ rel , err := filepath .Rel (srcPrefix , path )
185
+ if err != nil {
186
+ return err
187
+ }
188
+ in , err := os .Open (path )
189
+ if err != nil {
190
+ return err
191
+ }
192
+ defer in .Close ()
193
+
194
+ destFile := filepath .Join (dst , rel )
195
+ if err := os .MkdirAll (filepath .Dir (destFile ), os .ModePerm ); err != nil {
196
+ return err
197
+ }
198
+
199
+ out , err := os .Create (destFile )
200
+ if err != nil {
201
+ return err
202
+ }
203
+
204
+ _ , err = io .Copy (out , in )
205
+ return err
206
+ })
207
+ }
0 commit comments