Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/content-service-api/go/config/config.go
2499 views
1
// Copyright (c) 2021 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 config
6
7
import (
8
"os"
9
10
"github.com/gitpod-io/gitpod/common-go/baseserver"
11
)
12
13
// StorageConfig configures the remote storage we use
14
type StorageConfig struct {
15
// Stage represents the deployment environment in which we're operating
16
Stage Stage `json:"stage"`
17
18
// Kind determines the type of storage we ought to use
19
Kind RemoteStorageType `json:"kind"`
20
21
// GCloudConfig configures the Google Bucket remote storage
22
GCloudConfig GCPConfig `json:"gcloud,omitempty"`
23
24
// MinIOConfig configures the MinIO remote storage
25
MinIOConfig MinIOConfig `json:"minio,omitempty"`
26
27
// S3Config configures the S3 remote storage
28
S3Config *S3Config `json:"s3,omitempty"`
29
30
BlobQuota int64 `json:"blobQuota"`
31
}
32
33
// Stage represents the deployment environment in which we're operating
34
type Stage string
35
36
const (
37
// StageProduction is the live environment in which our users live
38
StageProduction Stage = "prod"
39
40
// StageStaging is our staging environment which runs very closely to production (hence the name)
41
StageStaging Stage = "prodcopy"
42
43
// StageDevStaging is our local or branch-built development environment
44
StageDevStaging Stage = "dev"
45
)
46
47
// RemoteStorageType is a kind of storage where we persist/backup workspaces to
48
type RemoteStorageType string
49
50
const (
51
// GCloudStorage stores workspaces in GCloud buckets
52
GCloudStorage RemoteStorageType = "gcloud"
53
54
// MinIOStorage stores workspaces in a MinIO/S3 storage
55
MinIOStorage RemoteStorageType = "minio"
56
57
// S3Storage stores workspaces in a S3 storage. It assumes the AWS-typical credentials
58
// exist in the environment. See https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/config#LoadDefaultConfig for more details.
59
S3Storage RemoteStorageType = "s3"
60
61
// NullStorage does not synchronize workspaces at all
62
NullStorage RemoteStorageType = ""
63
)
64
65
// GetStage reads the KUBE_STAGE envvar and maps its value to the storage stage naming
66
func getStageFromEnv() Stage {
67
// the stage does not have to be explicitly set in the storage config (as that would duplicate the
68
// info in our Helm values.yaml), but can be supplied as env var, as the default env vars in our
69
// Helm charts do.
70
stg := os.Getenv("KUBE_STAGE")
71
switch stg {
72
case "production":
73
return StageProduction
74
case "staging":
75
return StageStaging
76
default:
77
return StageDevStaging
78
}
79
}
80
81
// GetStage provides the storage stage from either this config or the environment
82
func (c *StorageConfig) GetStage() Stage {
83
if c.Stage == "" {
84
return getStageFromEnv()
85
}
86
87
return c.Stage
88
}
89
90
// GCPConfig controls the access to GCloud resources/buckets
91
type GCPConfig struct {
92
CredentialsFile string `json:"credentialsFile"`
93
Region string `json:"region"`
94
Project string `json:"projectId"`
95
}
96
97
// MinIOConfig MinIOconfigures the MinIO remote storage backend
98
type MinIOConfig struct {
99
Endpoint string `json:"endpoint"`
100
AccessKeyID string `json:"accessKey"`
101
AccessKeyIdFile string `json:"accessKeyFile"`
102
SecretAccessKey string `json:"secretKey"`
103
SecretAccessKeyFile string `json:"secretKeyFile"`
104
Secure bool `json:"secure,omitempty"`
105
106
Region string `json:"region"`
107
ParallelUpload uint `json:"parallelUpload,omitempty"`
108
109
BucketName string `json:"bucket,omitempty"`
110
}
111
112
// S3Config configures the S3 remote storage backend
113
type S3Config struct {
114
Bucket string `json:"bucket"`
115
Region string `json:"region"`
116
CredentialsFile string `json:"credentialsFile"`
117
}
118
119
type PProf struct {
120
Addr string `json:"address"`
121
}
122
123
// UsageReportConfig configures the upload of workspace instance usage reports
124
type UsageReportConfig struct {
125
BucketName string `json:"bucketName"`
126
}
127
128
type ServiceConfig struct {
129
Service baseserver.ServerConfiguration `json:"service"`
130
Storage StorageConfig `json:"storage"`
131
// Deprecated
132
_ UsageReportConfig `json:"usageReport"`
133
}
134
135