Skip to content

Commit 17d611e

Browse files
committed
Merge branch 'main' of github.com:unkeyed/unkey
2 parents 81f3e04 + 7802460 commit 17d611e

File tree

21 files changed

+312
-114
lines changed

21 files changed

+312
-114
lines changed

cmd/dev/github/trigger_webhook.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,20 @@ func triggerWebhook(ctx context.Context, cmd *cli.Command) error {
115115
fmt.Printf("Repository: %s (id: %d)\n", repository, repositoryID)
116116
fmt.Printf("Project: %s\n", projectID)
117117

118+
// Resolve the default app for this project
119+
fmt.Println("Looking up default app for project...")
120+
appRow, err := db.Query.FindAppByProjectAndSlug(ctx, database.RO(), db.FindAppByProjectAndSlugParams{
121+
ProjectID: projectID,
122+
Slug: "default",
123+
})
124+
if err != nil {
125+
return fmt.Errorf("failed to find default app for project %s: %w\n\nMake sure the project exists and has a 'default' app", projectID, err)
126+
}
127+
fmt.Printf("App: %s (id: %s)\n", appRow.App.Slug, appRow.App.ID)
128+
118129
// Ensure github_repo_connection exists
119130
fmt.Println("Ensuring GitHub connection exists in database...")
120-
if err := svc.ensureGithubConnection(ctx, projectID, installationID, repositoryID, repository); err != nil {
131+
if err := svc.ensureGithubConnection(ctx, projectID, appRow.App.ID, installationID, repositoryID, repository); err != nil {
121132
return fmt.Errorf("failed to create GitHub connection: %w", err)
122133
}
123134
fmt.Println("✔ GitHub connection ready")
@@ -217,11 +228,11 @@ func triggerWebhook(ctx context.Context, cmd *cli.Command) error {
217228
}
218229
}
219230

220-
func (s *Service) ensureGithubConnection(ctx context.Context, projectID string, installationID, repositoryID int64, repository string) error {
231+
func (s *Service) ensureGithubConnection(ctx context.Context, projectID, appID string, installationID, repositoryID int64, repository string) error {
221232
// Try to insert, ignore if already exists
222233
err := db.Query.InsertGithubRepoConnection(ctx, s.db.RW(), db.InsertGithubRepoConnectionParams{
223234
ProjectID: projectID,
224-
AppID: "",
235+
AppID: appID,
225236
InstallationID: installationID,
226237
RepositoryID: repositoryID,
227238
RepositoryFullName: repository,

pkg/db/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ go_library(
3030
"app_environment_variables_list_for_connections.sql_generated.go",
3131
"app_find_by_id.sql_generated.go",
3232
"app_find_by_project_and_slug.sql_generated.go",
33+
"app_find_by_workspace_project_slug_app_slug.sql_generated.go",
3334
"app_find_with_settings.sql_generated.go",
3435
"app_insert.sql_generated.go",
3536
"app_list_by_project.sql_generated.go",

pkg/db/app_find_by_workspace_project_slug_app_slug.sql_generated.go

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/querier_generated.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- name: FindAppByWorkspaceAndSlugs :one
2+
SELECT sqlc.embed(p), sqlc.embed(a)
3+
FROM apps a
4+
INNER JOIN projects p ON p.id = a.project_id
5+
WHERE p.workspace_id = sqlc.arg(workspace_id)
6+
AND p.slug = sqlc.arg(project_slug)
7+
AND a.slug = sqlc.arg(app_slug);

pkg/db/schema.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,10 @@ CREATE INDEX `bucket` ON `audit_log_target` (`bucket`);
723723
CREATE INDEX `id_idx` ON `audit_log_target` (`id`);
724724
CREATE INDEX `environments_project_idx` ON `environments` (`project_id`);
725725
CREATE INDEX `apps_workspace_idx` ON `apps` (`workspace_id`);
726-
CREATE INDEX `apps_project_idx` ON `apps` (`project_id`);
727726
CREATE INDEX `workspace_idx` ON `deployments` (`workspace_id`);
728727
CREATE INDEX `project_idx` ON `deployments` (`project_id`);
729728
CREATE INDEX `status_idx` ON `deployments` (`status`);
730729
CREATE INDEX `workspace_idx` ON `deployment_steps` (`workspace_id`);
731-
CREATE INDEX `deployment_idx` ON `deployment_steps` (`deployment_id`);
732730
CREATE INDEX `workspace_idx` ON `deployment_topology` (`workspace_id`);
733731
CREATE INDEX `status_idx` ON `deployment_topology` (`desired_status`);
734732
CREATE INDEX `domain_idx` ON `acme_users` (`workspace_id`);

svc/api/internal/testutil/seed/seed.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,35 @@ func (s *Seeder) CreateEnvironment(ctx context.Context, req CreateEnvironmentReq
236236
})
237237
require.NoError(s.t, err)
238238

239-
// Environment settings are now app-scoped (app_runtime_settings / app_build_settings).
240-
// Seed code should create an app and its settings separately.
239+
// Insert default app build settings for this (app, environment) pair.
240+
err = db.Query.UpsertAppBuildSettings(ctx, s.DB.RW(), db.UpsertAppBuildSettingsParams{
241+
WorkspaceID: req.WorkspaceID,
242+
AppID: req.AppID,
243+
EnvironmentID: req.ID,
244+
Dockerfile: "Dockerfile",
245+
DockerContext: ".",
246+
CreatedAt: now,
247+
UpdatedAt: sql.NullInt64{Valid: false},
248+
})
249+
require.NoError(s.t, err)
250+
251+
// Insert default app runtime settings for this (app, environment) pair.
252+
err = db.Query.UpsertAppRuntimeSettings(ctx, s.DB.RW(), db.UpsertAppRuntimeSettingsParams{
253+
WorkspaceID: req.WorkspaceID,
254+
AppID: req.AppID,
255+
EnvironmentID: req.ID,
256+
Port: 8080,
257+
CpuMillicores: 100,
258+
MemoryMib: 128,
259+
Command: nil,
260+
Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false},
261+
RegionConfig: nil,
262+
ShutdownSignal: db.AppRuntimeSettingsShutdownSignalSIGTERM,
263+
SentinelConfig: []byte("{}"),
264+
CreatedAt: now,
265+
UpdatedAt: sql.NullInt64{Valid: false},
266+
})
267+
require.NoError(s.t, err)
241268

242269
environment, err := db.Query.FindEnvironmentById(ctx, s.DB.RO(), req.ID)
243270
require.NoError(s.t, err)

svc/api/openapi/gen.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svc/api/openapi/openapi-generated.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,22 +344,22 @@ components:
344344
V2DeployCreateDeploymentRequestBody:
345345
type: object
346346
required:
347-
- projectId
347+
- project
348+
- app
348349
- branch
349350
- environmentSlug
350351
- dockerImage
351352
properties:
352-
projectId:
353+
project:
353354
type: string
354355
minLength: 1
355-
description: Unkey project ID
356-
example: "proj_123abc"
357-
pattern: "^proj_[a-zA-Z0-9]+$"
358-
appSlug:
356+
description: Project slug
357+
example: "my-project"
358+
app:
359359
type: string
360-
description: App slug within the project. Defaults to "default" if not specified.
360+
minLength: 1
361+
description: App slug within the project
361362
example: "default"
362-
default: "default"
363363
keyspaceId:
364364
type: string
365365
description: Optional keyspace ID for authentication context

svc/api/openapi/spec/paths/v2/deploy/createDeployment/V2DeployCreateDeploymentRequestBody.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
type: object
22
required:
3-
- projectId
3+
- project
4+
- app
45
- branch
56
- environmentSlug
67
- dockerImage
78
properties:
8-
projectId:
9+
project:
910
type: string
1011
minLength: 1
11-
description: Unkey project ID
12-
example: "proj_123abc"
13-
pattern: "^proj_[a-zA-Z0-9]+$"
14-
appSlug:
12+
description: Project slug
13+
example: "my-project"
14+
app:
1515
type: string
16-
description: App slug within the project. Defaults to "default" if not specified.
16+
minLength: 1
17+
description: App slug within the project
1718
example: "default"
18-
default: "default"
1919
keyspaceId:
2020
type: string
2121
description: Optional keyspace ID for authentication context

0 commit comments

Comments
 (0)