cos/tools: Add top-workdir input flag to anthos-installer-install

Teams tends to download the package tarballs directly using pkg-spec.
As /tmp dir size is small, we cannot relying on the /tmp dir as a working dir
always.

BUG=b/209349277
TEST=manual
verification(https://console.cloud.google.com/cloud-build/builds/4f516ea9-786f-4de9-8306-d8f5ea2bd757?project=821698443087)

Change-Id: Ia20d50d02a776554d45dcbc1ef5f09b314734587
Reviewed-on: https://cos-review.googlesource.com/c/cos/tools/+/26040
Reviewed-by: Robert Kolchmeyer <rkolchmeyer@google.com>
Cloud-Build: GCB Service account <228075978874@cloudbuild.gserviceaccount.com>
Reviewed-by: Roy Yang <royyang@google.com>
Tested-by: Varsha Teratipally <teratipally@google.com>
diff --git a/src/cmd/cos_customizer/install_packages.go b/src/cmd/cos_customizer/install_packages.go
index 8c6220c..b6c21f8 100644
--- a/src/cmd/cos_customizer/install_packages.go
+++ b/src/cmd/cos_customizer/install_packages.go
@@ -35,6 +35,7 @@
 // pkg-spec by the anthos-installer.
 type InstallPackage struct {
 	PkgSpecURL string
+	TopWorkDir string
 }
 
 // Name implements subcommands.Command.Name.
@@ -56,6 +57,7 @@
 // SetFlags implements subcommands.Command.SetFlags.
 func (ip *InstallPackage) SetFlags(f *flag.FlagSet) {
 	f.StringVar(&ip.PkgSpecURL, "pkgspec-url", "", "URL path that points to the package spec.")
+	f.StringVar(&ip.TopWorkDir, "top-workdir", "", "Path to the top working directory, used to hold package spec and package tarballs.")
 }
 
 // Execute implements subcommands.Command.Execute. It configures the current image build process to
@@ -84,6 +86,7 @@
 	buf, err := json.Marshal(&provisioner.InstallPackagesStep{
 		BuildContext:                 "user",
 		PkgSpecURL:                   ip.PkgSpecURL,
+		TopWorkDir:                   ip.TopWorkDir,
 		AnthosInstallerReleaseBucket: anthosInstallerReleaseBucket,
 		AnthosInstallerVersion:       anthosInstallerVersion,
 	})
diff --git a/src/pkg/provisioner/anthos_installer_install_script.go b/src/pkg/provisioner/anthos_installer_install_script.go
index aee9c61..28db991 100644
--- a/src/pkg/provisioner/anthos_installer_install_script.go
+++ b/src/pkg/provisioner/anthos_installer_install_script.go
@@ -23,6 +23,7 @@
 export ANTHOS_INSTALLER_VERSION={{.AnthosInstallerVersion}}
 export BUILD_CONTEXT_DIR={{.BuildContext}}
 export BIN_DIR={{.AnthosInstallerDir}}/bin
+export TOP_WORKDIR={{.TopWorkDir}}
 
 install_anthos_installer() {
 	tar -xvf ${ANTHOS_INSTALLER_DIR}/${ANTHOS_INSTALLER_VERSION} -C ${ANTHOS_INSTALLER_DIR}
@@ -30,7 +31,10 @@
 }
 
 install_packages() {
-	${BIN_DIR}/anthos_installer install -pkgspec-url=${PACKAGE_SPEC_DIR} -build-contextdir=${BUILD_CONTEXT_DIR}
+	echo "${TOP_WORKDIR}"
+	${BIN_DIR}/anthos_installer install -pkgspec-url=${PACKAGE_SPEC_DIR} \
+			-build-contextdir=${BUILD_CONTEXT_DIR} \
+			-top-workdir=${TOP_WORKDIR}
 	echo "Successfully installed the packages"
 }
 
diff --git a/src/pkg/provisioner/install_packages_step.go b/src/pkg/provisioner/install_packages_step.go
index 41a7144..f7e729e 100644
--- a/src/pkg/provisioner/install_packages_step.go
+++ b/src/pkg/provisioner/install_packages_step.go
@@ -29,6 +29,7 @@
 type InstallPackagesStep struct {
 	BuildContext                 string
 	PkgSpecURL                   string
+	TopWorkDir                   string
 	AnthosInstallerDir           string
 	AnthosInstallerVersion       string
 	AnthosInstallerReleaseBucket string
@@ -62,6 +63,7 @@
 	}
 	if err := t.Execute(f, &InstallPackagesStep{
 		PkgSpecURL:             utils.QuoteForShell(pkgSpecURL),
+		TopWorkDir:             utils.QuoteForShell(ip.TopWorkDir),
 		AnthosInstallerDir:     utils.QuoteForShell(ip.AnthosInstallerDir),
 		AnthosInstallerVersion: utils.QuoteForShell(ip.AnthosInstallerVersion),
 	}); err != nil {