summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-08-14 09:55:42 +0200
committerMartin Polden <mpolden@mpolden.no>2023-08-14 10:18:03 +0200
commitc644eefd16e2803362a773989b9758401e0cb006 (patch)
tree2f41b17675b4dc0e0a9143beeaf82efb6e6f8154
parente9df5f7b7aa6f9f1301d3d0f83e4749e5758e72d (diff)
Look harder for application package
-rw-r--r--client/go/internal/vespa/application.go21
-rw-r--r--client/go/internal/vespa/deploy_test.go21
2 files changed, 32 insertions, 10 deletions
diff --git a/client/go/internal/vespa/application.go b/client/go/internal/vespa/application.go
index b31dde54d67..b6b5b9427b3 100644
--- a/client/go/internal/vespa/application.go
+++ b/client/go/internal/vespa/application.go
@@ -216,17 +216,28 @@ func copyFile(src *zip.File, dst string) error {
// FindApplicationPackage finds the path to an application package from the zip file or directory zipOrDir. If
// requirePackaging is true, the application package is required to be packaged with mvn package.
+//
+// Package to use is preferred in this order:
+// 1. Given path, if it's a zip
+// 2. target/application
+// 3. target/application.zip
+// 4. src/main/application
+// 5. Given path, if it contains services.xml
func FindApplicationPackage(zipOrDir string, requirePackaging bool) (ApplicationPackage, error) {
if isZip(zipOrDir) {
return ApplicationPackage{Path: zipOrDir}, nil
}
- if util.PathExists(filepath.Join(zipOrDir, "pom.xml")) {
- zip := filepath.Join(zipOrDir, "target", "application.zip")
- if util.PathExists(zip) {
+ // Prefer uncompressed application because this allows us to add security/clients.pem to the package on-demand
+ if path := filepath.Join(zipOrDir, "target", "application"); util.PathExists(path) {
+ return ApplicationPackage{Path: path}, nil
+ }
+ appZip := filepath.Join(zipOrDir, "target", "application.zip")
+ if util.PathExists(filepath.Join(zipOrDir, "pom.xml")) || util.PathExists(appZip) {
+ if util.PathExists(appZip) {
if testZip := filepath.Join(zipOrDir, "target", "application-test.zip"); util.PathExists(testZip) {
- return ApplicationPackage{Path: zip, TestPath: testZip}, nil
+ return ApplicationPackage{Path: appZip, TestPath: testZip}, nil
}
- return ApplicationPackage{Path: zip}, nil
+ return ApplicationPackage{Path: appZip}, nil
}
if requirePackaging {
return ApplicationPackage{}, errors.New("found pom.xml, but target/application.zip does not exist: run 'mvn package' first")
diff --git a/client/go/internal/vespa/deploy_test.go b/client/go/internal/vespa/deploy_test.go
index 39a9f2bcdf2..c68ad750f1a 100644
--- a/client/go/internal/vespa/deploy_test.go
+++ b/client/go/internal/vespa/deploy_test.go
@@ -131,6 +131,11 @@ func TestFindApplicationPackage(t *testing.T) {
existingFile: filepath.Join(dir, "services.xml"),
})
assertFindApplicationPackage(t, dir, pkgFixture{
+ expectedPath: dir,
+ expectedTestPath: dir,
+ existingFiles: []string{filepath.Join(dir, "services.xml"), filepath.Join(dir, "tests", "foo.json")},
+ })
+ assertFindApplicationPackage(t, dir, pkgFixture{
expectedPath: filepath.Join(dir, "src", "main", "application"),
existingFile: filepath.Join(dir, "src", "main", "application") + string(os.PathSeparator),
})
@@ -149,11 +154,17 @@ func TestFindApplicationPackage(t *testing.T) {
existingFiles: []string{filepath.Join(dir, "pom.xml"), filepath.Join(dir, "target", "application.zip")},
requirePackaging: true,
})
- dir2 := t.TempDir()
- assertFindApplicationPackage(t, dir2, pkgFixture{
- expectedPath: dir2,
- expectedTestPath: dir2,
- existingFiles: []string{filepath.Join(dir2, "services.xml"), filepath.Join(dir2, "tests", "foo.json")},
+ assertFindApplicationPackage(t, dir, pkgFixture{
+ expectedPath: filepath.Join(dir, "target", "application.zip"),
+ existingFiles: []string{filepath.Join(dir, "target", "application.zip")},
+ })
+ assertFindApplicationPackage(t, dir, pkgFixture{
+ expectedPath: filepath.Join(dir, "target", "application"),
+ existingFiles: []string{filepath.Join(dir, "target", "application"), filepath.Join(dir, "target", "application.zip")},
+ })
+ zip := filepath.Join(dir, "myapp.zip")
+ assertFindApplicationPackage(t, zip, pkgFixture{
+ expectedPath: zip,
})
}