Просмотр исходного кода

Merge branch 'master' of https://github.com/porter-dev/porter

portersupport 4 лет назад
Родитель
Сommit
aa37f1dec1

+ 19 - 0
cli/cmd/create.go

@@ -5,6 +5,7 @@ import (
 	"io/ioutil"
 	"os"
 	"path/filepath"
+	"strings"
 
 	"github.com/fatih/color"
 	api "github.com/porter-dev/porter/api/client"
@@ -119,6 +120,14 @@ func init() {
 		"the path to the dockerfile",
 	)
 
+	createCmd.PersistentFlags().StringArrayVarP(
+		&buildFlagsEnv,
+		"env",
+		"e",
+		[]string{},
+		"Build-time environment variable, in the form 'VAR=VALUE'. These are not available at image runtime.",
+	)
+
 	createCmd.PersistentFlags().StringVar(
 		&method,
 		"method",
@@ -179,6 +188,15 @@ func createFull(_ *types.GetAuthenticatedUserResponse, client *api.Client, args
 		buildMethod = deploy.DeployBuildTypeDocker
 	}
 
+	// add additional env, if they exist
+	additionalEnv := make(map[string]string)
+
+	for _, buildEnv := range buildFlagsEnv {
+		if strSplArr := strings.SplitN(buildEnv, "=", 2); len(strSplArr) >= 2 {
+			additionalEnv[strSplArr[0]] = strSplArr[1]
+		}
+	}
+
 	createAgent := &deploy.CreateAgent{
 		Client: client,
 		CreateOpts: &deploy.CreateOpts{
@@ -189,6 +207,7 @@ func createFull(_ *types.GetAuthenticatedUserResponse, client *api.Client, args
 				LocalPath:       fullPath,
 				LocalDockerfile: dockerfile,
 				Method:          buildMethod,
+				AdditionalEnv:   additionalEnv,
 			},
 			Kind:        args[0],
 			ReleaseName: name,

+ 22 - 0
cli/cmd/deploy.go

@@ -3,6 +3,7 @@ package cmd
 import (
 	"fmt"
 	"os"
+	"strings"
 
 	"github.com/fatih/color"
 	api "github.com/porter-dev/porter/api/client"
@@ -204,8 +205,11 @@ var tag string
 var dockerfile string
 var method string
 var stream bool
+var buildFlagsEnv []string
 
 func init() {
+	buildFlagsEnv = []string{}
+
 	rootCmd.AddCommand(updateCmd)
 
 	updateCmd.PersistentFlags().StringVar(
@@ -262,6 +266,14 @@ func init() {
 		"the path to the dockerfile",
 	)
 
+	updateCmd.PersistentFlags().StringArrayVarP(
+		&buildFlagsEnv,
+		"env",
+		"e",
+		[]string{},
+		"Build-time environment variable, in the form 'VAR=VALUE'. These are not available at image runtime.",
+	)
+
 	updateCmd.PersistentFlags().StringVar(
 		&method,
 		"method",
@@ -382,6 +394,15 @@ func updateGetAgent(client *api.Client) (*deploy.DeployAgent, error) {
 		buildMethod = deploy.DeployBuildType(method)
 	}
 
+	// add additional env, if they exist
+	additionalEnv := make(map[string]string)
+
+	for _, buildEnv := range buildFlagsEnv {
+		if strSplArr := strings.SplitN(buildEnv, "=", 2); len(strSplArr) >= 2 {
+			additionalEnv[strSplArr[0]] = strSplArr[1]
+		}
+	}
+
 	// initialize the update agent
 	return deploy.NewDeployAgent(client, app, &deploy.DeployOpts{
 		SharedOpts: &deploy.SharedOpts{
@@ -392,6 +413,7 @@ func updateGetAgent(client *api.Client) (*deploy.DeployAgent, error) {
 			LocalDockerfile: dockerfile,
 			OverrideTag:     tag,
 			Method:          buildMethod,
+			AdditionalEnv:   additionalEnv,
 		},
 		Local: source != "github",
 	})

+ 5 - 0
cli/cmd/deploy/create.go

@@ -272,6 +272,11 @@ func (c *CreateAgent) CreateFromDocker(
 		env = map[string]string{}
 	}
 
+	// add additional env based on options
+	for key, val := range opts.SharedOpts.AdditionalEnv {
+		env[key] = val
+	}
+
 	buildAgent := &BuildAgent{
 		SharedOpts:  opts.SharedOpts,
 		client:      c.Client,

+ 12 - 1
cli/cmd/deploy/deploy.go

@@ -142,7 +142,18 @@ func NewDeployAgent(client *client.Client, app string, opts *DeployOpts) (*Deplo
 
 // GetBuildEnv retrieves the build env from the release config and returns it
 func (d *DeployAgent) GetBuildEnv() (map[string]string, error) {
-	return GetEnvFromConfig(d.release.Config)
+	env, err := GetEnvFromConfig(d.release.Config)
+
+	if err != nil {
+		return nil, err
+	}
+
+	// add additional env based on options
+	for key, val := range d.opts.SharedOpts.AdditionalEnv {
+		env[key] = val
+	}
+
+	return env, nil
 }
 
 // SetBuildEnv sets the build env vars in the process so that other commands can

+ 1 - 0
cli/cmd/deploy/shared.go

@@ -9,4 +9,5 @@ type SharedOpts struct {
 	LocalDockerfile string
 	OverrideTag     string
 	Method          DeployBuildType
+	AdditionalEnv   map[string]string
 }

+ 5 - 1
dashboard/src/main/home/launch/Launch.tsx

@@ -26,6 +26,8 @@ const tabOptions = [
   { label: "Community Add-ons", value: "community" },
 ];
 
+const HIDDEN_CHARTS = ["porter-agent"];
+
 type PropsType = RouteComponentProps & {};
 
 type StateType = {
@@ -74,7 +76,9 @@ class Templates extends Component<PropsType, StateType> {
         };
       });
       sortedVersionData.sort((a: any, b: any) => (a.name > b.name ? 1 : -1));
-
+      sortedVersionData = sortedVersionData.filter(
+        (template: any) => !HIDDEN_CHARTS.includes(template?.name)
+      );
       this.setState({ addonTemplates: sortedVersionData, error: false });
     } catch (error) {
       this.setState({ loading: false, error: true });

+ 1 - 1
dashboard/src/main/home/launch/launch-flow/SettingsPage.tsx

@@ -175,7 +175,7 @@ class SettingsPage extends Component<PropsType, StateType> {
           </Placeholder>
           <SaveButton
             text="Deploy"
-            onClick={onSubmit}
+            onClick={() => onSubmit({})}
             status={saveValuesStatus}
             makeFlush={true}
           />