Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/pkg/gitpodlib/config.go
2500 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package gitpodlib
6
7
type GitpodImage struct {
8
File string
9
Context string `yaml:"context,omitempty"`
10
}
11
12
type gitpodPort struct {
13
Number int32 `yaml:"port"`
14
}
15
16
type gitpodTask struct {
17
Command string `yaml:"command,omitempty"`
18
Init string `yaml:"init,omitempty"`
19
}
20
21
type GitpodFile struct {
22
Image interface{} `yaml:"image,omitempty"`
23
Ports []gitpodPort `yaml:"ports,omitempty"`
24
Tasks []gitpodTask `yaml:"tasks,omitempty"`
25
CheckoutLocation string `yaml:"checkoutLocation,omitempty"`
26
WorkspaceLocation string `yaml:"workspaceLocation,omitempty"`
27
}
28
29
// SetImageName configures a pre-built docker image by name
30
func (cfg *GitpodFile) SetImageName(name string) {
31
if name == "" {
32
return
33
}
34
cfg.Image = name
35
}
36
37
// SetImage configures a Dockerfile as workspace image
38
func (cfg *GitpodFile) SetImage(img GitpodImage) {
39
cfg.Image = img
40
}
41
42
// AddPort adds a port to the list of exposed ports
43
func (cfg *GitpodFile) AddPort(port int32) {
44
cfg.Ports = append(cfg.Ports, gitpodPort{
45
Number: port,
46
})
47
}
48
49
// AddTask adds a workspace startup task
50
func (cfg *GitpodFile) AddTask(task ...string) {
51
if len(task) > 1 {
52
cfg.Tasks = append(cfg.Tasks, gitpodTask{
53
Command: task[0],
54
Init: task[1],
55
})
56
} else {
57
cfg.Tasks = append(cfg.Tasks, gitpodTask{
58
Command: task[0],
59
})
60
}
61
}
62
63