|
|
@@ -36,7 +36,7 @@ func CreateApplicationDeploy(client *api.Client, worker *switchboardWorker.Worke
|
|
|
return nil, fmt.Errorf("malformed application definition: %w", err)
|
|
|
}
|
|
|
|
|
|
- deployStackHook := &DeployAppHook{
|
|
|
+ deployAppHook := &DeployAppHook{
|
|
|
Client: client,
|
|
|
ApplicationName: applicationName,
|
|
|
ProjectID: cliConf.Project,
|
|
|
@@ -46,60 +46,63 @@ func CreateApplicationDeploy(client *api.Client, worker *switchboardWorker.Worke
|
|
|
Builder: builder,
|
|
|
}
|
|
|
|
|
|
- worker.RegisterHook("deploy-stack", deployStackHook)
|
|
|
- if os.Getenv("GITHUB_RUN_ID") != "" {
|
|
|
- err := createAppEvent(client, applicationName, cliConf)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ worker.RegisterHook("deploy-app", deployAppHook)
|
|
|
return resources, nil
|
|
|
}
|
|
|
|
|
|
// Create app event to signfy start of build
|
|
|
-func createAppEvent(client *api.Client, applicationName string, cliConf *config.CLIConfig) error {
|
|
|
- req := &types.CreateOrUpdatePorterAppEventRequest{
|
|
|
- Status: "PROGRESSING",
|
|
|
- Type: types.PorterAppEventType_Build,
|
|
|
- TypeExternalSource: "GITHUB",
|
|
|
- Metadata: map[string]any{
|
|
|
- "action_run_id": os.Getenv("GITHUB_RUN_ID"),
|
|
|
- "org": os.Getenv("GITHUB_REPOSITORY_OWNER"),
|
|
|
- },
|
|
|
- }
|
|
|
+func createAppEvent(client *api.Client, applicationName string, projectId, clusterId uint) (string, error) {
|
|
|
+ var req *types.CreateOrUpdatePorterAppEventRequest
|
|
|
+ if os.Getenv("GITHUB_RUN_ID") != "" {
|
|
|
+ req = &types.CreateOrUpdatePorterAppEventRequest{
|
|
|
+ Status: "PROGRESSING",
|
|
|
+ Type: types.PorterAppEventType_Build,
|
|
|
+ TypeExternalSource: "GITHUB",
|
|
|
+ Metadata: map[string]any{
|
|
|
+ "action_run_id": os.Getenv("GITHUB_RUN_ID"),
|
|
|
+ "org": os.Getenv("GITHUB_REPOSITORY_OWNER"),
|
|
|
+ },
|
|
|
+ }
|
|
|
|
|
|
- repoNameSplit := strings.Split(os.Getenv("GITHUB_REPOSITORY"), "/")
|
|
|
- if len(repoNameSplit) != 2 {
|
|
|
- return fmt.Errorf("unable to parse GITHUB_REPOSITORY")
|
|
|
- }
|
|
|
- req.Metadata["repo"] = repoNameSplit[1]
|
|
|
+ repoNameSplit := strings.Split(os.Getenv("GITHUB_REPOSITORY"), "/")
|
|
|
+ if len(repoNameSplit) != 2 {
|
|
|
+ return "", fmt.Errorf("unable to parse GITHUB_REPOSITORY")
|
|
|
+ }
|
|
|
+ req.Metadata["repo"] = repoNameSplit[1]
|
|
|
|
|
|
- actionRunID := os.Getenv("GITHUB_RUN_ID")
|
|
|
- if actionRunID != "" {
|
|
|
- arid, err := strconv.Atoi(actionRunID)
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("unable to parse GITHUB_RUN_ID as int: %w", err)
|
|
|
+ actionRunID := os.Getenv("GITHUB_RUN_ID")
|
|
|
+ if actionRunID != "" {
|
|
|
+ arid, err := strconv.Atoi(actionRunID)
|
|
|
+ if err != nil {
|
|
|
+ return "", fmt.Errorf("unable to parse GITHUB_RUN_ID as int: %w", err)
|
|
|
+ }
|
|
|
+ req.Metadata["action_run_id"] = arid
|
|
|
}
|
|
|
- req.Metadata["action_run_id"] = arid
|
|
|
- }
|
|
|
|
|
|
- repoOwnerAccountID := os.Getenv("GITHUB_REPOSITORY_OWNER_ID")
|
|
|
- if repoOwnerAccountID != "" {
|
|
|
- arid, err := strconv.Atoi(repoOwnerAccountID)
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("unable to parse GITHUB_REPOSITORY_OWNER_ID as int: %w", err)
|
|
|
+ repoOwnerAccountID := os.Getenv("GITHUB_REPOSITORY_OWNER_ID")
|
|
|
+ if repoOwnerAccountID != "" {
|
|
|
+ arid, err := strconv.Atoi(repoOwnerAccountID)
|
|
|
+ if err != nil {
|
|
|
+ return "", fmt.Errorf("unable to parse GITHUB_REPOSITORY_OWNER_ID as int: %w", err)
|
|
|
+ }
|
|
|
+ req.Metadata["github_account_id"] = arid
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ req = &types.CreateOrUpdatePorterAppEventRequest{
|
|
|
+ Status: "PROGRESSING",
|
|
|
+ Type: types.PorterAppEventType_Build,
|
|
|
+ TypeExternalSource: "GITHUB",
|
|
|
+ Metadata: map[string]any{},
|
|
|
}
|
|
|
- req.Metadata["github_account_id"] = arid
|
|
|
}
|
|
|
|
|
|
ctx := context.Background()
|
|
|
- _, err := client.CreateOrUpdatePorterAppEvent(ctx, cliConf.Project, cliConf.Cluster, applicationName, req)
|
|
|
+ event, err := client.CreateOrUpdatePorterAppEvent(ctx, projectId, clusterId, applicationName, req)
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("unable to create porter app build event: %w", err)
|
|
|
+ return "", fmt.Errorf("unable to create porter app build event: %w", err)
|
|
|
}
|
|
|
|
|
|
- return nil
|
|
|
+ return event.ID, nil
|
|
|
}
|
|
|
|
|
|
func createV1BuildResources(client *api.Client, app *Application, stackName string, projectID uint, clusterID uint) ([]*switchboardTypes.Resource, string, error) {
|
|
|
@@ -118,7 +121,6 @@ func createV1BuildResources(client *api.Client, app *Application, stackName stri
|
|
|
color.New(color.FgYellow).Printf("No build values specified in porter.yaml, attempting to load stack build settings instead \n")
|
|
|
|
|
|
res, err := client.GetPorterApp(context.Background(), stackConf.projectID, stackConf.clusterID, stackConf.stackName)
|
|
|
-
|
|
|
if err != nil {
|
|
|
return nil, "", fmt.Errorf("unable to read build info from DB: %w", err)
|
|
|
}
|
|
|
@@ -147,7 +149,6 @@ func createV1BuildResources(client *api.Client, app *Application, stackName stri
|
|
|
stackConf.clusterID,
|
|
|
stackConf.parsed.Env,
|
|
|
)
|
|
|
-
|
|
|
if err != nil {
|
|
|
return nil, "", err
|
|
|
}
|
|
|
@@ -164,7 +165,6 @@ func createV1BuildResources(client *api.Client, app *Application, stackName stri
|
|
|
}
|
|
|
|
|
|
func createStackConf(client *api.Client, app *Application, stackName string, projectID uint, clusterID uint) (*StackConf, error) {
|
|
|
-
|
|
|
err := config.ValidateCLIEnvironment()
|
|
|
if err != nil {
|
|
|
errMsg := composePreviewMessage("porter CLI is not configured correctly", Error)
|