diff --git a/api/server/handlers/deployment_target/create.go b/api/server/handlers/deployment_target/create.go index 77e978237d..0741716fbf 100644 --- a/api/server/handlers/deployment_target/create.go +++ b/api/server/handlers/deployment_target/create.go @@ -71,12 +71,24 @@ func (c *CreateDeploymentTargetHandler) ServeHTTP(w http.ResponseWriter, r *http name = request.Selector } + var metadata *porterv1.DeploymentTargetMeta + if request.Metadata.PullRequest.Repository != "" { + metadata = &porterv1.DeploymentTargetMeta{ + PullRequest: &porterv1.PullRequest{ + Number: int64(request.Metadata.PullRequest.Number), + Repository: request.Metadata.PullRequest.Repository, + HeadRef: request.Metadata.PullRequest.HeadRef, + }, + } + } + createReq := connect.NewRequest(&porterv1.CreateDeploymentTargetRequest{ ProjectId: int64(project.ID), ClusterId: int64(clusterId), Name: name, Namespace: name, IsPreview: request.Preview, + Metadata: metadata, }) ccpResp, err := c.Config().ClusterControlPlaneClient.CreateDeploymentTarget(ctx, createReq) diff --git a/api/types/deployment_target.go b/api/types/deployment_target.go index b98b343ea7..5b62d0571c 100644 --- a/api/types/deployment_target.go +++ b/api/types/deployment_target.go @@ -28,6 +28,21 @@ type CreateDeploymentTargetRequest struct { Preview bool `json:"preview"` // required if using the project-scoped endpoint ClusterId uint `json:"cluster_id"` + // optional metadata field + Metadata Metadata `json:"metadata,omitempty"` +} + +// Metadata is a DB-level representation of the metadata field in a deployment target +type Metadata struct { + PullRequest TargetPullRequest `json:"pull_request"` +} + +// TargetPullRequest represents a pull request in the metadata field of a deployment target +type TargetPullRequest struct { + Repository string `json:"repository"` + Number int `json:"number"` + Title string `json:"title"` + HeadRef string `json:"head_ref"` } // CreateDeploymentTargetResponse is the response object for the /deployment-targets POST endpoint diff --git a/cli/cmd/v2/apply.go b/cli/cmd/v2/apply.go index dc9f5165f5..916547fee7 100644 --- a/cli/cmd/v2/apply.go +++ b/cli/cmd/v2/apply.go @@ -81,18 +81,19 @@ func Apply(ctx context.Context, inp ApplyInput) error { return errors.New("cluster must be set") } - deploymentTargetID, err := deploymentTargetFromConfig(ctx, client, cliConf.Project, cliConf.Cluster, inp.PreviewApply) - if err != nil { - return fmt.Errorf("error getting deployment target from config: %w", err) - } - var prNumber int prNumberEnv := os.Getenv("PORTER_PR_NUMBER") if prNumberEnv != "" { - prNumber, err = strconv.Atoi(prNumberEnv) + parsedPRInt, err := strconv.Atoi(prNumberEnv) if err != nil { return fmt.Errorf("error parsing PORTER_PR_NUMBER to int: %w", err) } + prNumber = parsedPRInt + } + + deploymentTargetID, err := deploymentTargetFromConfig(ctx, client, cliConf.Project, cliConf.Cluster, inp.PreviewApply, prNumber) + if err != nil { + return fmt.Errorf("error getting deployment target from config: %w", err) } porterYamlExists := len(inp.PorterYamlPath) != 0 @@ -343,7 +344,7 @@ func commitSHAFromEnv() string { return commitSHA } -func deploymentTargetFromConfig(ctx context.Context, client api.Client, projectID, clusterID uint, previewApply bool) (string, error) { +func deploymentTargetFromConfig(ctx context.Context, client api.Client, projectID, clusterID uint, previewApply bool, prNumber int) (string, error) { var deploymentTargetID string if os.Getenv("PORTER_DEPLOYMENT_TARGET_ID") != "" { @@ -375,11 +376,25 @@ func deploymentTargetFromConfig(ctx context.Context, client api.Client, projectI return deploymentTargetID, errors.New("branch name is empty. Please run apply in a git repository with access to the git CLI") } + var repository string + if os.Getenv("PORTER_REPO_NAME") != "" { + repository = os.Getenv("PORTER_REPO_NAME") + } else if os.Getenv("GITHUB_REPOSITORY") != "" { + repository = os.Getenv("GITHUB_REPOSITORY") + } + targetResp, err := client.CreateDeploymentTarget(ctx, projectID, &types.CreateDeploymentTargetRequest{ Selector: "", Name: branchName, Preview: true, ClusterId: clusterID, + Metadata: types.Metadata{ + PullRequest: types.TargetPullRequest{ + Repository: repository, + Number: prNumber, + HeadRef: branchName, + }, + }, }) if err != nil { return deploymentTargetID, fmt.Errorf("error calling create deployment target endpoint: %w", err) diff --git a/dashboard/src/assets/git-compare.svg b/dashboard/src/assets/git-compare.svg new file mode 100644 index 0000000000..7ccb5ef61a --- /dev/null +++ b/dashboard/src/assets/git-compare.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/dashboard/src/lib/hooks/useAddon.ts b/dashboard/src/lib/hooks/useAddon.ts index 78f7ebac3d..f5d37fb043 100644 --- a/dashboard/src/lib/hooks/useAddon.ts +++ b/dashboard/src/lib/hooks/useAddon.ts @@ -139,7 +139,7 @@ export const useAddonList = ({ "monitoring", "porter-agent-system", "external-secrets", - "infisical-operator" + "infisical" ].includes(a.namespace ?? ""); }); }, diff --git a/dashboard/src/main/home/add-on-dashboard/legacy_AddOnDashboard.tsx b/dashboard/src/main/home/add-on-dashboard/legacy_AddOnDashboard.tsx index 6432d9f0d8..d335d0f5a7 100644 --- a/dashboard/src/main/home/add-on-dashboard/legacy_AddOnDashboard.tsx +++ b/dashboard/src/main/home/add-on-dashboard/legacy_AddOnDashboard.tsx @@ -50,7 +50,7 @@ export const RestrictedNamespaces = [ "monitoring", "porter-agent-system", "external-secrets", - "infisical-operator" + "infisical", ]; const templateBlacklist = ["web", "worker", "job", "umbrella"]; diff --git a/dashboard/src/main/home/app-dashboard/new-app-flow/utils.ts b/dashboard/src/main/home/app-dashboard/new-app-flow/utils.ts index e7be71bd99..0262e51970 100644 --- a/dashboard/src/main/home/app-dashboard/new-app-flow/utils.ts +++ b/dashboard/src/main/home/app-dashboard/new-app-flow/utils.ts @@ -24,7 +24,7 @@ export const getGithubAction = ( stackName: string, branchName: string, porterYamlPath: string = "porter.yaml", - deploymentTargetId: string = "", + deploymentTargetId: string = "" ): string => { return `on: push: @@ -52,7 +52,11 @@ jobs: PORTER_STACK_NAME: ${stackName} PORTER_TAG: \${{ steps.vars.outputs.sha_short }} PORTER_TOKEN: \${{ secrets.PORTER_STACK_${projectID}_${clusterId} }} - ${deploymentTargetId ? `PORTER_DEPLOYMENT_TARGET_ID: ${deploymentTargetId}` : ""}`; + ${ + deploymentTargetId + ? `PORTER_DEPLOYMENT_TARGET_ID: ${deploymentTargetId}` + : "" + }`; }; export const getPreviewGithubAction = ({ @@ -67,7 +71,7 @@ export const getPreviewGithubAction = ({ appName: string; branch: string; porterYamlPath?: string; -}) => { +}): string => { return `"on": pull_request: branches: @@ -101,5 +105,6 @@ jobs: PORTER_STACK_NAME: ${appName} PORTER_TAG: \${{ steps.vars.outputs.sha_short }} PORTER_TOKEN: \${{ secrets.PORTER_STACK_${projectId}_${clusterId} }} - PORTER_PR_NUMBER: \${{ github.event.number }}`; + PORTER_PR_NUMBER: \${{ github.event.number }} + PORTER_REPO_NAME: \${{ github.event.repository.name }}`; }; diff --git a/dashboard/src/main/home/cluster-dashboard/preview-environments/v2/ConfigurableAppList.tsx b/dashboard/src/main/home/cluster-dashboard/preview-environments/v2/ConfigurableAppList.tsx index 93e5946925..63fa08cc4a 100644 --- a/dashboard/src/main/home/cluster-dashboard/preview-environments/v2/ConfigurableAppList.tsx +++ b/dashboard/src/main/home/cluster-dashboard/preview-environments/v2/ConfigurableAppList.tsx @@ -24,10 +24,6 @@ export const ConfigurableAppList: React.FC = () => { clusterId: currentCluster?.id ?? 0, }); - if (status === "loading") { - return ; - } - if (apps.length === 0) { return (
diff --git a/dashboard/src/main/home/cluster-dashboard/preview-environments/v2/setup-app/PreviewAppDataContainer.tsx b/dashboard/src/main/home/cluster-dashboard/preview-environments/v2/setup-app/PreviewAppDataContainer.tsx index 649bff44ea..60c05ccc74 100644 --- a/dashboard/src/main/home/cluster-dashboard/preview-environments/v2/setup-app/PreviewAppDataContainer.tsx +++ b/dashboard/src/main/home/cluster-dashboard/preview-environments/v2/setup-app/PreviewAppDataContainer.tsx @@ -168,6 +168,7 @@ export const PreviewAppDataContainer: React.FC = ({ })) .otherwise(() => ({})); const secrets = match(addon.config) + .returnType>() .with({ type: "postgres" }, (conf) => ({ POSTGRESQL_PASSWORD: conf.password, })) diff --git a/go.mod b/go.mod index 143c407913..2189363b2a 100644 --- a/go.mod +++ b/go.mod @@ -87,7 +87,7 @@ require ( github.com/nats-io/nats.go v1.24.0 github.com/open-policy-agent/opa v0.44.0 github.com/ory/client-go v1.9.0 - github.com/porter-dev/api-contracts v0.2.157 + github.com/porter-dev/api-contracts v0.2.158 github.com/riandyrn/otelchi v0.5.1 github.com/santhosh-tekuri/jsonschema/v5 v5.0.1 github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d diff --git a/go.sum b/go.sum index af542518a8..bf8e10bbf3 100644 --- a/go.sum +++ b/go.sum @@ -1563,8 +1563,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw= -github.com/porter-dev/api-contracts v0.2.157 h1:xjC1q4/8ZUl5QLVyCkTfIiMZn+k8h0c9AO9nrCFcZ1Y= -github.com/porter-dev/api-contracts v0.2.157/go.mod h1:VV5BzXd02ZdbWIPLVP+PX3GKawJSGQnxorVT2sUZALU= +github.com/porter-dev/api-contracts v0.2.158 h1:928I9vELiqntau4Yp8cVuX7FcLgo95Lv2uBVYj84is8= +github.com/porter-dev/api-contracts v0.2.158/go.mod h1:VV5BzXd02ZdbWIPLVP+PX3GKawJSGQnxorVT2sUZALU= github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M= github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= diff --git a/internal/integrations/ci/actions/steps.go b/internal/integrations/ci/actions/steps.go index 64137861d3..9e19580e08 100644 --- a/internal/integrations/ci/actions/steps.go +++ b/internal/integrations/ci/actions/steps.go @@ -106,6 +106,7 @@ func getDeployStackStep( "PORTER_TAG": "${{ steps.vars.outputs.sha_short }}", "PORTER_STACK_NAME": stackName, "PORTER_PR_NUMBER": "${{ github.event.number }}", + "PORTER_REPO_NAME": "${{ github.event.repository.name }}", } if deploymentTargetId != "" {