Skip to content

Commit

Permalink
lay out cli command a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-lombardi committed Dec 30, 2024
1 parent f2b7ad3 commit c2fca12
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 18 deletions.
13 changes: 9 additions & 4 deletions pkg/abstractions/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

const (
shellContainerPrefix string = "shell-"
shellContainerPrefix string = "shell"
defaultContainerCpu int64 = 100
defaultContainerMemory int64 = 128
)
Expand Down Expand Up @@ -111,7 +111,7 @@ func (ss *SSHShellService) CreateShell(ctx context.Context, in *pb.CreateShellRe
}, nil
}

containerId := fmt.Sprintf("%s%s", shellContainerPrefix, uuid.New().String())
containerId := ss.genContainerId(stub.ExternalId)

go ss.keyEventManager.ListenForPattern(ctx, common.RedisKeys.SchedulerContainerExitCode(containerId), keyEventChan)

Expand Down Expand Up @@ -175,7 +175,7 @@ func (ss *SSHShellService) CreateShell(ctx context.Context, in *pb.CreateShellRe
StubId: stub.ExternalId,
WorkspaceId: authInfo.Workspace.ExternalId,
Workspace: *authInfo.Workspace,
EntryPoint: []string{"/usr/sbin/sshd", "-D"},
EntryPoint: []string{"tail", "-f", "/dev/null"},
Mounts: mounts,
Stub: *stub,
})
Expand All @@ -202,6 +202,11 @@ func (ss *SSHShellService) CreateShell(ctx context.Context, in *pb.CreateShellRe
log.Println("Connected to shell: ", conn)

return &pb.CreateShellResponse{
Ok: true,
Ok: true,
ContainerId: containerId,
}, nil
}

func (ss *SSHShellService) genContainerId(stubId string) string {
return fmt.Sprintf("%s-%s-%s", shellContainerPrefix, stubId, uuid.New().String()[:8])
}
5 changes: 4 additions & 1 deletion pkg/abstractions/shell/shell.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ message CreateShellRequest {
int32 timeout = 2;
}

message CreateShellResponse { bool ok = 1; }
message CreateShellResponse {
bool ok = 1;
string container_id = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package backend_postgres_migrations

import (
"context"
"database/sql"
"fmt"

"github.com/pressly/goose/v3"
)

func init() {
goose.AddMigrationContext(upAddShellStubType, downRemoveShellStubType)
}

func upAddShellStubType(ctx context.Context, tx *sql.Tx) error {
newStubTypes := []string{"schedule/shell", "asgi/shell", "endpoint/shell", "taskqueue/shell", "function/shell"}

for _, stubType := range newStubTypes {
addEnumSQL := fmt.Sprintf(`
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_type t
JOIN pg_enum e ON t.oid = e.enumtypid
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
WHERE n.nspname = 'public' AND t.typname = 'stub_type' AND e.enumlabel = '%s'
) THEN
EXECUTE 'ALTER TYPE stub_type ADD VALUE ' || quote_literal('%s');
END IF;
END
$$;`, stubType, stubType)

if _, err := tx.Exec(addEnumSQL); err != nil {
return err
}
}

return nil
}

func downRemoveShellStubType(ctx context.Context, tx *sql.Tx) error {
// PostgreSQL doesn't support removing values from an ENUM directly
// hi
return nil
}
9 changes: 9 additions & 0 deletions pkg/types/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,34 @@ const (
StubTypeFunction string = "function"
StubTypeFunctionDeployment string = "function/deployment"
StubTypeFunctionServe string = "function/serve"
StubTypeFunctionShell string = "function/shell"
StubTypeContainer string = "container"
StubTypeTaskQueue string = "taskqueue"
StubTypeTaskQueueDeployment string = "taskqueue/deployment"
StubTypeTaskQueueServe string = "taskqueue/serve"
StubTypeTaskQueueShell string = "taskqueue/shell"
StubTypeEndpoint string = "endpoint"
StubTypeEndpointDeployment string = "endpoint/deployment"
StubTypeEndpointServe string = "endpoint/serve"
StubTypeEndpointShell string = "endpoint/shell"
StubTypeASGI string = "asgi"
StubTypeASGIDeployment string = "asgi/deployment"
StubTypeASGIServe string = "asgi/serve"
StubTypeASGIShell string = "asgi/shell"
StubTypeScheduledJob string = "schedule"
StubTypeScheduledJobDeployment string = "schedule/deployment"
StubTypeScheduledJobShell string = "schedule/shell"
StubTypeBot string = "bot"
StubTypeBotDeployment string = "bot/deployment"
StubTypeBotServe string = "bot/serve"
)

type StubType string

func (t StubType) IsShell() bool {
return strings.HasSuffix(string(t), "/shell")
}

func (t StubType) IsServe() bool {
return strings.HasSuffix(string(t), "/serve")
}
Expand Down
32 changes: 21 additions & 11 deletions proto/shell.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c2fca12

Please sign in to comment.