@@ -38,7 +38,7 @@ func (c *BootstrapGcpCmd) RunE(_ *cobra.Command, args []string) error {
3838 return nil
3939}
4040
41- func AddBootstrapGcpCmd (root * cobra.Command , opts * GlobalOptions ) {
41+ func AddBootstrapGcpCmd (parent * cobra.Command , opts * GlobalOptions ) {
4242 bootstrapGcpCmd := BootstrapGcpCmd {
4343 cmd : & cobra.Command {
4444 Use : "bootstrap-gcp" ,
@@ -53,6 +53,7 @@ func AddBootstrapGcpCmd(root *cobra.Command, opts *GlobalOptions) {
5353 Env : env .NewEnv (),
5454 CodesphereEnv : & gcp.CodesphereEnvironment {},
5555 }
56+ bootstrapGcpCmd .cmd .RunE = bootstrapGcpCmd .RunE
5657
5758 flags := bootstrapGcpCmd .cmd .Flags ()
5859 flags .StringVar (& bootstrapGcpCmd .CodesphereEnv .ProjectName , "project-name" , "" , "Unique GCP Project Name (required)" )
@@ -82,8 +83,8 @@ func AddBootstrapGcpCmd(root *cobra.Command, opts *GlobalOptions) {
8283 util .MarkFlagRequired (bootstrapGcpCmd .cmd , "billing-account" )
8384 util .MarkFlagRequired (bootstrapGcpCmd .cmd , "base-domain" )
8485
85- bootstrapGcpCmd . cmd . RunE = bootstrapGcpCmd .RunE
86- root . AddCommand (bootstrapGcpCmd .cmd )
86+ parent . AddCommand ( bootstrapGcpCmd .cmd )
87+ AddBootstrapGcpPostconfigCmd (bootstrapGcpCmd .cmd , opts )
8788}
8889
8990func (c * BootstrapGcpCmd ) BootstrapGcp () error {
@@ -92,9 +93,8 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error {
9293 icg := installer .NewInstallConfigManager ()
9394 gcpClient := gcp .NewGCPClient (ctx , stlog , os .Getenv ("GOOGLE_APPLICATION_CREDENTIALS" ))
9495 fw := util .NewFilesystemWriter ()
95- nm := node .NewNode (fw , c .CodesphereEnv .SSHPrivateKeyPath , c .SSHQuiet )
9696
97- bs , err := gcp .NewGCPBootstrapper (ctx , c .Env , stlog , c .CodesphereEnv , icg , gcpClient , nm , fw )
97+ bs , err := gcp .NewGCPBootstrapper (ctx , c .Env , stlog , c .CodesphereEnv , icg , gcpClient , fw , node . NewSSHNodeClient ( c . SSHQuiet ) )
9898 if err != nil {
9999 return err
100100 }
@@ -103,21 +103,34 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error {
103103
104104 err = bs .Bootstrap ()
105105 envBytes , err2 := json .MarshalIndent (bs .Env , "" , " " )
106+
106107 envString := string (envBytes )
107108 if err2 != nil {
108109 envString = ""
109110 }
111+
110112 if err != nil {
111- if bs .Env .Jumpbox != nil && bs . Env . Jumpbox .GetExternalIP () != "" {
113+ if bs .Env .Jumpbox .GetExternalIP () != "" {
112114 log .Printf ("To debug on the jumpbox host:\n ssh-add $SSH_KEY_PATH; ssh -o StrictHostKeyChecking=no -o ForwardAgent=yes -o SendEnv=OMS_PORTAL_API_KEY root@%s" , bs .Env .Jumpbox .GetExternalIP ())
113115 }
114116 return fmt .Errorf ("failed to bootstrap GCP: %w, env: %s" , err , envString )
115117 }
116118
119+ workdir := env .NewEnv ().GetOmsWorkdir ()
120+ err = fw .MkdirAll (workdir , 0755 )
121+ if err != nil {
122+ return fmt .Errorf ("failed to create workdir: %w" , err )
123+ }
124+ infraFilePath := gcp .GetInfraFilePath ()
125+ err = fw .WriteFile (infraFilePath , envBytes , 0644 )
126+ if err != nil {
127+ return fmt .Errorf ("failed to write gcp bootstrap env file: %w" , err )
128+ }
129+
117130 log .Println ("\n 🎉🎉🎉 GCP infrastructure bootstrapped successfully!" )
118131 log .Println (envString )
132+ log .Printf ("Infrastructure details written to %s" , infraFilePath )
119133 log .Printf ("Start the Codesphere installation using OMS from the jumpbox host:\n ssh-add $SSH_KEY_PATH; ssh -o StrictHostKeyChecking=no -o ForwardAgent=yes -o SendEnv=OMS_PORTAL_API_KEY root@%s" , bs .Env .Jumpbox .GetExternalIP ())
120- log .Printf ("When the installation is done, run the k0s configuration script generated at the k0s-1 host %s /root/configure-k0s.sh." , bs .Env .ControlPlaneNodes [0 ].GetInternalIP ())
121134
122- return err
135+ return nil
123136}
0 commit comments