forked from loft-sh/devpod
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathworkspace.go
More file actions
328 lines (256 loc) · 11.5 KB
/
workspace.go
File metadata and controls
328 lines (256 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package provider
import (
"strings"
"time"
"github.com/loft-sh/api/v4/pkg/devpod"
"github.com/skevetter/devpod/pkg/config"
devcontainerconfig "github.com/skevetter/devpod/pkg/devcontainer/config"
"github.com/skevetter/devpod/pkg/git"
"github.com/skevetter/devpod/pkg/types"
)
var (
WorkspaceSourceGit = "git:"
WorkspaceSourceLocal = "local:"
WorkspaceSourceImage = "image:"
WorkspaceSourceContainer = "container:"
WorkspaceSourceUnknown = "unknown:"
)
type Workspace struct {
// ID is the workspace id to use
ID string `json:"id,omitempty"`
// UID is used to identify this specific workspace
UID string `json:"uid,omitempty"`
// Picture is the project social media image
Picture string `json:"picture,omitempty"`
// Provider is the provider used to create this workspace
Provider WorkspaceProviderConfig `json:"provider"`
// Machine is the machine to use for this workspace
Machine WorkspaceMachineConfig `json:"machine"`
// IDE holds IDE specific settings
IDE WorkspaceIDEConfig `json:"ide"`
// Source is the source where this workspace will be created from
Source WorkspaceSource `json:"source"`
// DevContainerImage is the container image to use, overriding whatever is in the devcontainer.json
DevContainerImage string `json:"devContainerImage,omitempty"`
// DevContainerPath is the relative path where the devcontainer.json is located.
DevContainerPath string `json:"devContainerPath,omitempty"`
// DevContainerConfig holds the config for the devcontainer.json.
DevContainerConfig *devcontainerconfig.DevContainerConfig `json:"devContainerConfig,omitempty"`
// CreationTimestamp is the timestamp when this workspace was created
CreationTimestamp types.Time `json:"creationTimestamp"`
// LastUsedTimestamp holds the timestamp when this workspace was last accessed
LastUsedTimestamp types.Time `json:"lastUsed"`
// Context is the context where this config file was loaded from
Context string `json:"context,omitempty"`
// Imported signals that this workspace was imported
Imported bool `json:"imported,omitempty"`
// Origin is the place where this config file was loaded from
Origin string `json:"-"`
// Pro signals this workspace is remote and doesn't necessarily exist locally. It also has more metadata about the pro workspace
Pro *ProMetadata `json:"pro,omitempty"`
// Path to the file where the SSH config to access the workspace is stored
SSHConfigPath string `json:"sshConfigPath,omitempty"`
// Path to an alternate file where DevPod entries are written (for read-only SSH configs)
SSHConfigIncludePath string `json:"sshConfigIncludePath,omitempty"`
}
type ProMetadata struct {
// InstanceName is the platform CRD name for this workspace
InstanceName string `json:"instanceName,omitempty"`
// Project is the platform project the workspace lives in
Project string `json:"project,omitempty"`
// DisplayName is the name intended to show users
DisplayName string `json:"displayName,omitempty"`
}
type WorkspaceIDEConfig struct {
// Name is the name of the IDE
Name string `json:"name,omitempty"`
// Options are the local options that override the global ones
Options map[string]config.OptionValue `json:"options,omitempty"`
}
type WorkspaceMachineConfig struct {
// ID is the machine ID to use for this workspace
ID string `json:"machineId,omitempty"`
// AutoDelete specifies if the machine should get destroyed when
// the workspace is destroyed
AutoDelete bool `json:"autoDelete,omitempty"`
}
type WorkspaceProviderConfig struct {
// Name is the provider name
Name string `json:"name,omitempty"`
// Options are the local options that override the global ones
Options map[string]config.OptionValue `json:"options,omitempty"`
}
type WorkspaceSource struct {
// GitRepository is the repository to clone
GitRepository string `json:"gitRepository,omitempty"`
// GitBranch is the branch to use
GitBranch string `json:"gitBranch,omitempty"`
// GitCommit is the commit SHA to checkout
GitCommit string `json:"gitCommit,omitempty"`
// GitPRReference is the pull request reference to checkout
GitPRReference string `json:"gitPRReference,omitempty"`
// GitSubPath is the subpath in the repo to use
GitSubPath string `json:"gitSubDir,omitempty"`
// LocalFolder is the local folder to use
LocalFolder string `json:"localFolder,omitempty"`
// Image is the docker image to use
Image string `json:"image,omitempty"`
// Container is the container to use
Container string `json:"container,omitempty"`
}
type ContainerWorkspaceInfo struct {
// IDE holds the ide config options
IDE WorkspaceIDEConfig `json:"ide"`
// CLIOptions holds the cli options
CLIOptions CLIOptions `json:"cliOptions"`
// Dockerless holds custom dockerless configuration
Dockerless ProviderDockerlessOptions `json:"dockerless"`
// ContainerTimeout is the timeout in minutes to wait until the agent tries
// to delete the container.
ContainerTimeout string `json:"containerInactivityTimeout,omitempty"`
// Source is a WorkspaceSource to be used inside the container
Source WorkspaceSource `json:"source"`
// ContentFolder holds the folder where the content is stored
ContentFolder string `json:"contentFolder,omitempty"`
// PullFromInsideContainer determines if project should be pulled from Source when container starts
PullFromInsideContainer types.StrBool `json:"pullFromInsideContainer,omitempty"`
// Agent holds the agent info
Agent ProviderAgentConfig `json:"agent"`
}
type AgentWorkspaceInfo struct {
// WorkspaceOrigin is the path where this workspace config originated from
WorkspaceOrigin string `json:"workspaceOrigin,omitempty"`
// Workspace holds the workspace info
Workspace *Workspace `json:"workspace,omitempty"`
// LastDevContainerConfig can be used as a fallback if the workspace was already started
// and we lost track of the devcontainer.json
LastDevContainerConfig *devcontainerconfig.DevContainerConfigWithPath `json:"lastDevContainerConfig,omitempty"`
// Machine holds the machine info
Machine *Machine `json:"machine,omitempty"`
// Agent holds the agent info
Agent ProviderAgentConfig `json:"agent"`
// CLIOptions holds the cli options
CLIOptions CLIOptions `json:"cliOptions"`
// Options holds the filled provider options for this workspace
Options map[string]config.OptionValue `json:"options,omitempty"`
// ContentFolder holds the folder where the content is stored
ContentFolder string `json:"contentFolder,omitempty"`
// Origin holds the folder where this config was loaded from
Origin string `json:"-"`
// InjectTimeout specifies how long to wait for the agent to be injected into the dev container
InjectTimeout time.Duration `json:"injectTimeout,omitempty"`
// RegistryCache defines the registry to use for caching builds
RegistryCache string `json:"registryCache,omitempty"`
}
type CLIOptions struct {
// Platform are the platform options
Platform devpod.PlatformOptions `json:"platformOptions"`
// up options
ID string `json:"id,omitempty"`
Source string `json:"source,omitempty"`
IDE string `json:"ide,omitempty"`
IDEOptions []string `json:"ideOptions,omitempty"`
PrebuildRepositories []string `json:"prebuildRepositories,omitempty"`
DevContainerImage string `json:"devContainerImage,omitempty"`
DevContainerPath string `json:"devContainerPath,omitempty"`
DevContainerID string `json:"devContainerID,omitempty"`
WorkspaceEnv []string `json:"workspaceEnv,omitempty"`
WorkspaceEnvFile []string `json:"workspaceEnvFile,omitempty"`
InitEnv []string `json:"initEnv,omitempty"`
Recreate bool `json:"recreate,omitempty"`
Reset bool `json:"reset,omitempty"`
DisableDaemon bool `json:"disableDaemon,omitempty"`
DaemonInterval string `json:"daemonInterval,omitempty"`
GitCloneStrategy git.CloneStrategy `json:"gitCloneStrategy,omitempty"`
GitCloneRecursiveSubmodules bool `json:"gitCloneRecursive,omitempty"`
FallbackImage string `json:"fallbackImage,omitempty"`
GitSSHSigningKey string `json:"gitSshSigningKey,omitempty"`
SSHAuthSockID string `json:"sshAuthSockID,omitempty"` // ID to use when looking for SSH_AUTH_SOCK, defaults to a new random ID if not set (only used for browser IDEs)
StrictHostKeyChecking bool `json:"strictHostKeyChecking,omitempty"`
ExtraDevContainerPath string `json:"extraDevContainerPath,omitempty"`
User string `json:"user,omitempty"`
Userns string `json:"userns,omitempty"`
UidMap []string `json:"uidMap,omitempty"`
GidMap []string `json:"gidMap,omitempty"`
// build options
Repository string `json:"repository,omitempty"`
SkipPush bool `json:"skipPush,omitempty"`
Platforms []string `json:"platform,omitempty"`
Tag []string `json:"tag,omitempty"`
ForceBuild bool `json:"forceBuild,omitempty"`
ForceDockerless bool `json:"forceDockerless,omitempty"`
ForceInternalBuildKit bool `json:"forceInternalBuildKit,omitempty"`
}
type BuildOptions struct {
CLIOptions
Platform string
RegistryCache string
ExportCache bool
NoBuild bool
}
func (w WorkspaceSource) String() string {
if w.GitRepository != "" {
if w.GitPRReference != "" {
return WorkspaceSourceGit + w.GitRepository + "@" + w.GitPRReference
} else if w.GitBranch != "" {
return WorkspaceSourceGit + w.GitRepository + "@" + w.GitBranch
} else if w.GitCommit != "" {
return WorkspaceSourceGit + w.GitRepository + git.CommitDelimiter + w.GitCommit
}
return WorkspaceSourceGit + w.GitRepository
} else if w.LocalFolder != "" {
return WorkspaceSourceLocal + w.LocalFolder
} else if w.Image != "" {
return WorkspaceSourceImage + w.Image
} else if w.Container != "" {
return WorkspaceSourceContainer + w.Container
}
return ""
}
func (w WorkspaceSource) Type() string {
if w.GitRepository != "" {
if w.GitPRReference != "" {
return WorkspaceSourceGit + "pr"
} else if w.GitBranch != "" {
return WorkspaceSourceGit + "branch"
} else if w.GitCommit != "" {
return WorkspaceSourceGit + "commit"
}
return WorkspaceSourceGit
} else if w.LocalFolder != "" {
return WorkspaceSourceLocal
} else if w.Image != "" {
return WorkspaceSourceImage
} else if w.Container != "" {
return WorkspaceSourceContainer
}
return WorkspaceSourceUnknown
}
func ParseWorkspaceSource(source string) *WorkspaceSource {
if after, ok := strings.CutPrefix(source, WorkspaceSourceGit); ok {
gitRepo, gitPRReference, gitBranch, gitCommit, gitSubdir := git.NormalizeRepository(after)
return &WorkspaceSource{
GitRepository: gitRepo,
GitPRReference: gitPRReference,
GitBranch: gitBranch,
GitCommit: gitCommit,
GitSubPath: gitSubdir,
}
} else if after, ok := strings.CutPrefix(source, WorkspaceSourceLocal); ok {
return &WorkspaceSource{
LocalFolder: after,
}
} else if after, ok := strings.CutPrefix(source, WorkspaceSourceImage); ok {
return &WorkspaceSource{
Image: after,
}
} else if after, ok := strings.CutPrefix(source, WorkspaceSourceContainer); ok {
return &WorkspaceSource{
Container: after,
}
}
return nil
}
func (w *Workspace) IsPro() bool {
return w.Pro != nil
}