deploy.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. package cmd
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. "github.com/fatih/color"
  9. api "github.com/porter-dev/porter/api/client"
  10. "github.com/porter-dev/porter/api/types"
  11. "github.com/porter-dev/porter/cli/cmd/config"
  12. "github.com/porter-dev/porter/cli/cmd/deploy"
  13. "github.com/porter-dev/porter/cli/cmd/utils"
  14. templaterUtils "github.com/porter-dev/porter/internal/templater/utils"
  15. "github.com/spf13/cobra"
  16. "k8s.io/client-go/util/homedir"
  17. )
  18. // updateCmd represents the "porter update" base command when called
  19. // without any subcommands
  20. var updateCmd = &cobra.Command{
  21. Use: "update",
  22. Short: "Builds and updates a specified application given by the --app flag.",
  23. Long: fmt.Sprintf(`
  24. %s
  25. Builds and updates a specified application given by the --app flag. For example:
  26. %s
  27. This command will automatically build from a local path. The path can be configured via the
  28. --path flag. You can also overwrite the tag using the --tag flag. For example, to build from the
  29. local directory ~/path-to-dir with the tag "testing":
  30. %s
  31. If the application has a remote Git repository source configured, you can specify that the remote
  32. Git repository should be used to build the new image by specifying "--source github". Porter will use
  33. the latest commit from the remote repo and branch to update an application, and will use the latest
  34. commit as the image tag.
  35. %s
  36. To add new configuration or update existing configuration, you can pass a values.yaml file in via the
  37. --values flag. For example;
  38. %s
  39. If your application is set up to use a Dockerfile by default, you can use a buildpack via the flag
  40. "--method pack". Conversely, if your application is set up to use a buildpack by default, you can
  41. use a Dockerfile by passing the flag "--method docker". You can specify the relative path to a Dockerfile
  42. in your remote Git repository. For example, if a Dockerfile is found at ./docker/prod.Dockerfile, you can
  43. specify it as follows:
  44. %s
  45. `,
  46. color.New(color.FgBlue, color.Bold).Sprintf("Help for \"porter update\":"),
  47. color.New(color.FgGreen, color.Bold).Sprintf("porter update --app example-app"),
  48. color.New(color.FgGreen, color.Bold).Sprintf("porter update --app example-app --path ~/path-to-dir --tag testing"),
  49. color.New(color.FgGreen, color.Bold).Sprintf("porter update --app remote-git-app --source github"),
  50. color.New(color.FgGreen, color.Bold).Sprintf("porter update --app example-app --values my-values.yaml"),
  51. color.New(color.FgGreen, color.Bold).Sprintf("porter update --app example-app --method docker --dockerfile ./docker/prod.Dockerfile"),
  52. ),
  53. Run: func(cmd *cobra.Command, args []string) {
  54. err := checkLoginAndRun(args, updateFull)
  55. if err != nil {
  56. os.Exit(1)
  57. }
  58. },
  59. }
  60. var updateGetEnvCmd = &cobra.Command{
  61. Use: "get-env",
  62. Short: "Gets environment variables for a deployment for a specified application given by the --app flag.",
  63. Long: fmt.Sprintf(`
  64. %s
  65. Gets environment variables for a deployment for a specified application given by the --app
  66. flag. By default, env variables are printed via stdout for use in downstream commands:
  67. %s
  68. Output can also be written to a file via the --file flag, which should specify the
  69. destination path for a .env file. For example:
  70. %s
  71. `,
  72. color.New(color.FgBlue, color.Bold).Sprintf("Help for \"porter update get-env\":"),
  73. color.New(color.FgGreen, color.Bold).Sprintf("porter update get-env --app example-app | xargs"),
  74. color.New(color.FgGreen, color.Bold).Sprintf("porter update get-env --app example-app --file .env"),
  75. ),
  76. Run: func(cmd *cobra.Command, args []string) {
  77. err := checkLoginAndRun(args, updateGetEnv)
  78. if err != nil {
  79. os.Exit(1)
  80. }
  81. },
  82. }
  83. var updateBuildCmd = &cobra.Command{
  84. Use: "build",
  85. Short: "Builds a new version of the application specified by the --app flag.",
  86. Long: fmt.Sprintf(`
  87. %s
  88. Builds a new version of the application specified by the --app flag. Depending on the
  89. configured settings, this command may work automatically or will require a specified
  90. --method flag.
  91. If you have configured the Dockerfile path and/or a build context for this application,
  92. this command will by default use those settings, so you just need to specify the --app
  93. flag:
  94. %s
  95. If you have not linked the build-time requirements for this application, the command will
  96. use a local build. By default, the cloud-native buildpacks builder will automatically be run
  97. from the current directory. If you would like to change the build method, you can do so by
  98. using the --method flag, for example:
  99. %s
  100. When using "--method docker", you can specify the path to the Dockerfile using the
  101. --dockerfile flag. This will also override the Dockerfile path that you may have linked
  102. for the application:
  103. %s
  104. `,
  105. color.New(color.FgBlue, color.Bold).Sprintf("Help for \"porter update build\":"),
  106. color.New(color.FgGreen, color.Bold).Sprintf("porter update build --app example-app"),
  107. color.New(color.FgGreen, color.Bold).Sprintf("porter update build --app example-app --method docker"),
  108. color.New(color.FgGreen, color.Bold).Sprintf("porter update build --app example-app --method docker --dockerfile ./prod.Dockerfile"),
  109. ),
  110. Run: func(cmd *cobra.Command, args []string) {
  111. err := checkLoginAndRun(args, updateBuild)
  112. if err != nil {
  113. os.Exit(1)
  114. }
  115. },
  116. }
  117. var updatePushCmd = &cobra.Command{
  118. Use: "push",
  119. Short: "Pushes a new image for an application specified by the --app flag.",
  120. Long: fmt.Sprintf(`
  121. %s
  122. Pushes a new image for an application specified by the --app flag. This command uses
  123. the image repository saved in the application config by default. For example, if an
  124. application "nginx" was created from the image repo "gcr.io/snowflake-123456/nginx",
  125. the following command would push the image "gcr.io/snowflake-123456/nginx:new-tag":
  126. %s
  127. This command will not use your pre-saved authentication set up via "docker login," so if you
  128. are using an image registry that was created outside of Porter, make sure that you have
  129. linked it via "porter connect".
  130. `,
  131. color.New(color.FgBlue, color.Bold).Sprintf("Help for \"porter update push\":"),
  132. color.New(color.FgGreen, color.Bold).Sprintf("porter update push --app nginx --tag new-tag"),
  133. ),
  134. Run: func(cmd *cobra.Command, args []string) {
  135. err := checkLoginAndRun(args, updatePush)
  136. if err != nil {
  137. os.Exit(1)
  138. }
  139. },
  140. }
  141. var updateConfigCmd = &cobra.Command{
  142. Use: "config",
  143. Short: "Updates the configuration for an application specified by the --app flag.",
  144. Long: fmt.Sprintf(`
  145. %s
  146. Updates the configuration for an application specified by the --app flag, using the configuration
  147. given by the --values flag. This will trigger a new deployment for the application with
  148. new configuration set. Note that this will merge your existing configuration with configuration
  149. specified in the --values file. For example:
  150. %s
  151. You can update the configuration with only a new tag with the --tag flag, which will only update
  152. the image that the application uses if no --values file is specified:
  153. %s
  154. `,
  155. color.New(color.FgBlue, color.Bold).Sprintf("Help for \"porter update config\":"),
  156. color.New(color.FgGreen, color.Bold).Sprintf("porter update config --app example-app --values my-values.yaml"),
  157. color.New(color.FgGreen, color.Bold).Sprintf("porter update config --app example-app --tag custom-tag"),
  158. ),
  159. Run: func(cmd *cobra.Command, args []string) {
  160. err := checkLoginAndRun(args, updateUpgrade)
  161. if err != nil {
  162. os.Exit(1)
  163. }
  164. },
  165. }
  166. var updateEnvGroupCmd = &cobra.Command{
  167. Use: "env-group",
  168. Aliases: []string{"eg", "envgroup", "env-groups", "envgroups"},
  169. Short: "Updates an environment group's variables, specified by the --name flag.",
  170. Run: func(cmd *cobra.Command, args []string) {
  171. color.New(color.FgRed).Println("need to specify an operation to continue")
  172. },
  173. }
  174. var updateSetEnvGroupCmd = &cobra.Command{
  175. Use: "set",
  176. Short: "Sets the desired value of an environment variable in an env group in the form VAR=VALUE.",
  177. Run: func(cmd *cobra.Command, args []string) {
  178. err := checkLoginAndRun(args, updateSetEnvGroup)
  179. if err != nil {
  180. os.Exit(1)
  181. }
  182. },
  183. }
  184. var updateUnsetEnvGroupCmd = &cobra.Command{
  185. Use: "unset",
  186. Short: "Removes an environment variable from an env group.",
  187. Run: func(cmd *cobra.Command, args []string) {
  188. err := checkLoginAndRun(args, updateUnsetEnvGroup)
  189. if err != nil {
  190. os.Exit(1)
  191. }
  192. },
  193. }
  194. var app string
  195. var getEnvFileDest string
  196. var localPath string
  197. var tag string
  198. var dockerfile string
  199. var method string
  200. var stream bool
  201. var buildFlagsEnv []string
  202. var forcePush bool
  203. var useCache bool
  204. var value string
  205. var version uint
  206. func init() {
  207. buildFlagsEnv = []string{}
  208. rootCmd.AddCommand(updateCmd)
  209. updateCmd.PersistentFlags().StringVar(
  210. &app,
  211. "app",
  212. "",
  213. "Application in the Porter dashboard",
  214. )
  215. updateCmd.MarkPersistentFlagRequired("app")
  216. updateCmd.PersistentFlags().BoolVar(
  217. &useCache,
  218. "use-cache",
  219. false,
  220. "Whether to use cache (currently in beta)",
  221. )
  222. updateCmd.PersistentFlags().StringVar(
  223. &namespace,
  224. "namespace",
  225. "default",
  226. "Namespace of the application",
  227. )
  228. updateCmd.PersistentFlags().StringVar(
  229. &source,
  230. "source",
  231. "local",
  232. "the type of source (\"local\" or \"github\")",
  233. )
  234. updateCmd.PersistentFlags().StringVarP(
  235. &localPath,
  236. "path",
  237. "p",
  238. "",
  239. "If local build, the path to the build directory. If remote build, the relative path from the repository root to the build directory.",
  240. )
  241. updateCmd.PersistentFlags().StringVarP(
  242. &tag,
  243. "tag",
  244. "t",
  245. "",
  246. "the specified tag to use, if not \"latest\"",
  247. )
  248. updateCmd.PersistentFlags().StringVarP(
  249. &values,
  250. "values",
  251. "v",
  252. "",
  253. "Filepath to a values.yaml file",
  254. )
  255. updateCmd.PersistentFlags().StringVar(
  256. &dockerfile,
  257. "dockerfile",
  258. "",
  259. "the path to the dockerfile",
  260. )
  261. updateCmd.PersistentFlags().StringArrayVarP(
  262. &buildFlagsEnv,
  263. "env",
  264. "e",
  265. []string{},
  266. "Build-time environment variable, in the form 'VAR=VALUE'. These are not available at image runtime.",
  267. )
  268. updateCmd.PersistentFlags().StringVar(
  269. &method,
  270. "method",
  271. "",
  272. "the build method to use (\"docker\" or \"pack\")",
  273. )
  274. updateCmd.PersistentFlags().BoolVar(
  275. &stream,
  276. "stream",
  277. false,
  278. "stream update logs to porter dashboard",
  279. )
  280. updateCmd.PersistentFlags().BoolVar(
  281. &forceBuild,
  282. "force-build",
  283. false,
  284. "set this to force build an image (images tagged with \"latest\" have this set by default)",
  285. )
  286. updateCmd.PersistentFlags().BoolVar(
  287. &forcePush,
  288. "force-push",
  289. false,
  290. "set this to force push an image (images tagged with \"latest\" have this set by default)",
  291. )
  292. updateCmd.PersistentFlags().MarkDeprecated("force-build", "--force-build is now deprecated")
  293. updateCmd.PersistentFlags().MarkDeprecated("force-push", "--force-push is now deprecated")
  294. updateCmd.AddCommand(updateGetEnvCmd)
  295. updateGetEnvCmd.PersistentFlags().StringVar(
  296. &getEnvFileDest,
  297. "file",
  298. "",
  299. "file destination for .env files",
  300. )
  301. updateEnvGroupCmd.PersistentFlags().StringVar(
  302. &name,
  303. "name",
  304. "",
  305. "the name of the environment group",
  306. )
  307. updateEnvGroupCmd.PersistentFlags().UintVar(
  308. &version,
  309. "version",
  310. 0,
  311. "the version of the environment group",
  312. )
  313. updateEnvGroupCmd.AddCommand(updateSetEnvGroupCmd)
  314. updateEnvGroupCmd.AddCommand(updateUnsetEnvGroupCmd)
  315. updateCmd.AddCommand(updateBuildCmd)
  316. updateCmd.AddCommand(updatePushCmd)
  317. updateCmd.AddCommand(updateConfigCmd)
  318. updateCmd.AddCommand(updateEnvGroupCmd)
  319. }
  320. func updateFull(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
  321. fullPath, err := filepath.Abs(localPath)
  322. if err != nil {
  323. return err
  324. }
  325. if os.Getenv("GITHUB_ACTIONS") == "" && source == "local" && fullPath == homedir.HomeDir() {
  326. proceed, err := utils.PromptConfirm("You are deploying your home directory. Do you want to continue?", false)
  327. if err != nil {
  328. return err
  329. }
  330. if !proceed {
  331. return nil
  332. }
  333. }
  334. color.New(color.FgGreen).Println("Deploying app:", app)
  335. updateAgent, err := updateGetAgent(client)
  336. if err != nil {
  337. return err
  338. }
  339. err = updateBuildWithAgent(updateAgent)
  340. if err != nil {
  341. return err
  342. }
  343. err = updatePushWithAgent(updateAgent)
  344. if err != nil {
  345. return err
  346. }
  347. err = updateUpgradeWithAgent(updateAgent)
  348. if err != nil {
  349. return err
  350. }
  351. return nil
  352. }
  353. func updateGetEnv(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
  354. updateAgent, err := updateGetAgent(client)
  355. if err != nil {
  356. return err
  357. }
  358. buildEnv, err := updateAgent.GetBuildEnv(&deploy.GetBuildEnvOpts{
  359. UseNewConfig: false,
  360. })
  361. if err != nil {
  362. return err
  363. }
  364. // set the environment variables in the process
  365. err = updateAgent.SetBuildEnv(buildEnv)
  366. if err != nil {
  367. return err
  368. }
  369. // write the environment variables to either a file or stdout (stdout by default)
  370. return updateAgent.WriteBuildEnv(getEnvFileDest)
  371. }
  372. func updateBuild(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
  373. updateAgent, err := updateGetAgent(client)
  374. if err != nil {
  375. return err
  376. }
  377. return updateBuildWithAgent(updateAgent)
  378. }
  379. func updatePush(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
  380. updateAgent, err := updateGetAgent(client)
  381. if err != nil {
  382. return err
  383. }
  384. return updatePushWithAgent(updateAgent)
  385. }
  386. func updateUpgrade(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
  387. updateAgent, err := updateGetAgent(client)
  388. if err != nil {
  389. return err
  390. }
  391. return updateUpgradeWithAgent(updateAgent)
  392. }
  393. func updateSetEnvGroup(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
  394. if len(args) == 0 {
  395. return fmt.Errorf("need variable in the form VAR=VALUE")
  396. }
  397. key, value, found := strings.Cut(args[0], "=")
  398. if !found {
  399. return fmt.Errorf("need variable in the form VAR=VALUE")
  400. }
  401. envGroup, err := client.GetEnvGroup(context.Background(), cliConf.Project, cliConf.Cluster, namespace, &types.GetEnvGroupRequest{
  402. Name: name, Version: version,
  403. })
  404. if err != nil {
  405. return err
  406. }
  407. return nil
  408. }
  409. func updateUnsetEnvGroup(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
  410. return nil
  411. }
  412. // HELPER METHODS
  413. func updateGetAgent(client *api.Client) (*deploy.DeployAgent, error) {
  414. var buildMethod deploy.DeployBuildType
  415. if method != "" {
  416. buildMethod = deploy.DeployBuildType(method)
  417. }
  418. // add additional env, if they exist
  419. additionalEnv := make(map[string]string)
  420. for _, buildEnv := range buildFlagsEnv {
  421. if strSplArr := strings.SplitN(buildEnv, "=", 2); len(strSplArr) >= 2 {
  422. additionalEnv[strSplArr[0]] = strSplArr[1]
  423. }
  424. }
  425. // initialize the update agent
  426. return deploy.NewDeployAgent(client, app, &deploy.DeployOpts{
  427. SharedOpts: &deploy.SharedOpts{
  428. ProjectID: cliConf.Project,
  429. ClusterID: cliConf.Cluster,
  430. Namespace: namespace,
  431. LocalPath: localPath,
  432. LocalDockerfile: dockerfile,
  433. OverrideTag: tag,
  434. Method: buildMethod,
  435. AdditionalEnv: additionalEnv,
  436. UseCache: useCache,
  437. },
  438. Local: source != "github",
  439. })
  440. }
  441. func updateBuildWithAgent(updateAgent *deploy.DeployAgent) error {
  442. // build the deployment
  443. color.New(color.FgGreen).Println("Building docker image for", app)
  444. if stream {
  445. updateAgent.StreamEvent(types.SubEvent{
  446. EventID: "build",
  447. Name: "Build",
  448. Index: 100,
  449. Status: types.EventStatusInProgress,
  450. Info: "",
  451. })
  452. }
  453. if useCache {
  454. err := config.SetDockerConfig(updateAgent.Client)
  455. if err != nil {
  456. return err
  457. }
  458. }
  459. // read the values if necessary
  460. valuesObj, err := readValuesFile()
  461. if err != nil {
  462. return err
  463. }
  464. buildEnv, err := updateAgent.GetBuildEnv(&deploy.GetBuildEnvOpts{
  465. UseNewConfig: true,
  466. NewConfig: valuesObj,
  467. })
  468. if err != nil {
  469. if stream {
  470. // another concern: is it safe to ignore the error here?
  471. updateAgent.StreamEvent(types.SubEvent{
  472. EventID: "build",
  473. Name: "Build",
  474. Index: 110,
  475. Status: types.EventStatusFailed,
  476. Info: err.Error(),
  477. })
  478. }
  479. return err
  480. }
  481. // set the environment variables in the process
  482. err = updateAgent.SetBuildEnv(buildEnv)
  483. if err != nil {
  484. if stream {
  485. updateAgent.StreamEvent(types.SubEvent{
  486. EventID: "build",
  487. Name: "Build",
  488. Index: 120,
  489. Status: types.EventStatusFailed,
  490. Info: err.Error(),
  491. })
  492. }
  493. return err
  494. }
  495. if err := updateAgent.Build(nil); err != nil {
  496. if stream {
  497. updateAgent.StreamEvent(types.SubEvent{
  498. EventID: "build",
  499. Name: "Build",
  500. Index: 130,
  501. Status: types.EventStatusFailed,
  502. Info: err.Error(),
  503. })
  504. }
  505. return err
  506. }
  507. if stream {
  508. updateAgent.StreamEvent(types.SubEvent{
  509. EventID: "build",
  510. Name: "Build",
  511. Index: 140,
  512. Status: types.EventStatusSuccess,
  513. Info: "",
  514. })
  515. }
  516. return nil
  517. }
  518. func updatePushWithAgent(updateAgent *deploy.DeployAgent) error {
  519. if useCache {
  520. color.New(color.FgGreen).Println("Skipping image push for", app, "as use-cache is set")
  521. return nil
  522. }
  523. // push the deployment
  524. color.New(color.FgGreen).Println("Pushing new image for", app)
  525. if stream {
  526. updateAgent.StreamEvent(types.SubEvent{
  527. EventID: "push",
  528. Name: "Push",
  529. Index: 200,
  530. Status: types.EventStatusInProgress,
  531. Info: "",
  532. })
  533. }
  534. if err := updateAgent.Push(); err != nil {
  535. if stream {
  536. updateAgent.StreamEvent(types.SubEvent{
  537. EventID: "push",
  538. Name: "Push",
  539. Index: 210,
  540. Status: types.EventStatusFailed,
  541. Info: err.Error(),
  542. })
  543. }
  544. return err
  545. }
  546. if stream {
  547. updateAgent.StreamEvent(types.SubEvent{
  548. EventID: "push",
  549. Name: "Push",
  550. Index: 220,
  551. Status: types.EventStatusSuccess,
  552. Info: "",
  553. })
  554. }
  555. return nil
  556. }
  557. func updateUpgradeWithAgent(updateAgent *deploy.DeployAgent) error {
  558. // push the deployment
  559. color.New(color.FgGreen).Println("Upgrading configuration for", app)
  560. if stream {
  561. updateAgent.StreamEvent(types.SubEvent{
  562. EventID: "upgrade",
  563. Name: "Upgrade",
  564. Index: 300,
  565. Status: types.EventStatusInProgress,
  566. Info: "",
  567. })
  568. }
  569. var err error
  570. // read the values if necessary
  571. valuesObj, err := readValuesFile()
  572. if err != nil {
  573. return err
  574. }
  575. if err != nil {
  576. if stream {
  577. updateAgent.StreamEvent(types.SubEvent{
  578. EventID: "upgrade",
  579. Name: "Upgrade",
  580. Index: 310,
  581. Status: types.EventStatusFailed,
  582. Info: err.Error(),
  583. })
  584. }
  585. return err
  586. }
  587. if len(updateAgent.Opts.AdditionalEnv) > 0 {
  588. syncedEnv, err := deploy.GetSyncedEnv(
  589. updateAgent.Client,
  590. updateAgent.Release.Config,
  591. updateAgent.Opts.ProjectID,
  592. updateAgent.Opts.ClusterID,
  593. updateAgent.Opts.Namespace,
  594. false,
  595. )
  596. if err != nil {
  597. return err
  598. }
  599. for k := range updateAgent.Opts.AdditionalEnv {
  600. if _, ok := syncedEnv[k]; ok {
  601. return fmt.Errorf("environment variable %s already exists as part of a synced environment group", k)
  602. }
  603. }
  604. normalEnv, err := deploy.GetNormalEnv(
  605. updateAgent.Client,
  606. updateAgent.Release.Config,
  607. updateAgent.Opts.ProjectID,
  608. updateAgent.Opts.ClusterID,
  609. updateAgent.Opts.Namespace,
  610. false,
  611. )
  612. if err != nil {
  613. return err
  614. }
  615. // add the additional environment variables to container.env.normal
  616. for k, v := range updateAgent.Opts.AdditionalEnv {
  617. normalEnv[k] = v
  618. }
  619. valuesObj = templaterUtils.CoalesceValues(valuesObj, map[string]interface{}{
  620. "container": map[string]interface{}{
  621. "env": map[string]interface{}{
  622. "normal": normalEnv,
  623. },
  624. },
  625. })
  626. }
  627. err = updateAgent.UpdateImageAndValues(valuesObj)
  628. if err != nil {
  629. if stream {
  630. updateAgent.StreamEvent(types.SubEvent{
  631. EventID: "upgrade",
  632. Name: "Upgrade",
  633. Index: 320,
  634. Status: types.EventStatusFailed,
  635. Info: err.Error(),
  636. })
  637. }
  638. return err
  639. }
  640. if stream {
  641. updateAgent.StreamEvent(types.SubEvent{
  642. EventID: "upgrade",
  643. Name: "Upgrade",
  644. Index: 330,
  645. Status: types.EventStatusSuccess,
  646. Info: "",
  647. })
  648. }
  649. color.New(color.FgGreen).Println("Successfully updated", app)
  650. return nil
  651. }