github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/nodeps/values.go (about)

     1  package nodeps
     2  
     3  import (
     4  	"sort"
     5  	"strings"
     6  
     7  	"github.com/maruel/natural"
     8  
     9  	"github.com/ddev/ddev/pkg/config/types"
    10  )
    11  
    12  // Providers
    13  // TODO: This should be removed as many providers will now be valid
    14  const (
    15  	// ProviderDefault contains the name of the default provider which will be used if one is not otherwise specified.
    16  	ProviderDefault = "default"
    17  )
    18  
    19  // Database Types
    20  const (
    21  	MariaDB  = "mariadb"
    22  	MySQL    = "mysql"
    23  	Postgres = "postgres"
    24  )
    25  
    26  // Container types used with ddev
    27  const (
    28  	DdevSSHAgentContainer = "ddev-ssh-agent"
    29  	DBContainer           = "db"
    30  	WebContainer          = "web"
    31  	RouterContainer       = "ddev-router"
    32  )
    33  
    34  // Webserver types
    35  const (
    36  	WebserverNginxFPM      = "nginx-fpm"
    37  	WebserverApacheFPM     = "apache-fpm"
    38  	WebserverNginxGunicorn = "nginx-gunicorn"
    39  )
    40  
    41  // ValidOmitContainers is the list of things that can be omitted
    42  var ValidOmitContainers = map[string]bool{
    43  	DBContainer:           true,
    44  	DdevSSHAgentContainer: true,
    45  }
    46  
    47  // DdevFileSignature is the text we use to detect whether a settings file is managed by us.
    48  // If this string is found, we assume we can replace/update the file.
    49  const DdevFileSignature = "#ddev-generated"
    50  
    51  // WebserverDefault is the default webserver type, overridden by $DDEV_WEBSERVER_TYPE
    52  var WebserverDefault = WebserverNginxFPM
    53  
    54  // PerformanceModeDefault is default value for app.PerformanceMode
    55  var PerformanceModeDefault = types.PerformanceModeEmpty
    56  
    57  const NodeJSDefault = "20"
    58  
    59  // NoBindMountsDefault is default value for globalconfig.DDEVGlobalConfig.NoBindMounts
    60  var NoBindMountsDefault = false
    61  
    62  // UseNginxProxyRouter is used in testing to override the default
    63  // setting for tests.
    64  var UseNginxProxyRouter = false
    65  
    66  // SimpleFormatting is turned on by DDEV_USE_SIMPLE_FORMATTING
    67  // and makes ddev list and describe, etc. use simpler formatting
    68  var SimpleFormatting = false
    69  
    70  // FailOnHookFailDefault is the default value for app.FailOnHookFail
    71  var FailOnHookFailDefault = false
    72  
    73  // GoroutineLimit is the number of goroutines allowed at exit in parts of some tests
    74  // Can be overridden by setting DDEV_TEST_GOROUTINE_LIMIT=<somenumber>
    75  var GoroutineLimit = 10
    76  
    77  // ValidWebserverTypes should be updated whenever supported webserver types are added or
    78  // removed, and should be used to ensure user-supplied values are valid.
    79  var ValidWebserverTypes = map[string]bool{
    80  	WebserverNginxFPM:      true,
    81  	WebserverApacheFPM:     true,
    82  	WebserverNginxGunicorn: true,
    83  }
    84  
    85  // App types
    86  const (
    87  	AppTypeNone         = ""
    88  	AppTypeBackdrop     = "backdrop"
    89  	AppTypeCakePHP      = "cakephp"
    90  	AppTypeCraftCms     = "craftcms"
    91  	AppTypeDjango4      = "django4"
    92  	AppTypeDrupal6      = "drupal6"
    93  	AppTypeDrupal7      = "drupal7"
    94  	AppTypeDrupal8      = "drupal8"
    95  	AppTypeDrupal9      = "drupal9"
    96  	AppTypeDrupal10     = "drupal10"
    97  	AppTypeDrupal       = "drupal"
    98  	AppTypeLaravel      = "laravel"
    99  	AppTypeSilverstripe = "silverstripe"
   100  	AppTypeMagento      = "magento"
   101  	AppTypeMagento2     = "magento2"
   102  	AppTypePHP          = "php"
   103  	AppTypePython       = "python"
   104  	AppTypeShopware6    = "shopware6"
   105  	AppTypeTYPO3        = "typo3"
   106  	AppTypeWordPress    = "wordpress"
   107  )
   108  
   109  // Ports and other defaults
   110  const (
   111  	// DdevDefaultRouterHTTPPort is the default router HTTP port
   112  	DdevDefaultRouterHTTPPort = "80"
   113  
   114  	// DdevDefaultRouterHTTPSPort is the default router HTTPS port
   115  	DdevDefaultRouterHTTPSPort = "443"
   116  	// DdevDefaultMailpitHTTPPort is the default router port for Mailpit
   117  	DdevDefaultMailpitHTTPPort  = "8025"
   118  	DdevDefaultMailpitHTTPSPort = "8026"
   119  	// DdevDefaultTLD is the top-level-domain used by default, can be overridden
   120  	DdevDefaultTLD                  = "ddev.site"
   121  	DefaultDefaultContainerTimeout  = "120"
   122  	InternetDetectionTimeoutDefault = 3000
   123  	TraefikMonitorPortDefault       = "10999"
   124  	MinimumDockerSpaceWarning       = 5000000 // 5GB in KB (to compare against df reporting in KB)
   125  )
   126  
   127  // IsValidPHPVersion is a helper function to determine if a PHP version is valid, returning
   128  // true if the supplied PHP version is valid and false otherwise.
   129  func IsValidPHPVersion(phpVersion string) bool {
   130  	if _, ok := ValidPHPVersions[phpVersion]; !ok {
   131  		return false
   132  	}
   133  
   134  	return true
   135  }
   136  
   137  // GetValidPHPVersions is a helper function that returns a list of valid PHP versions.
   138  func GetValidPHPVersions() []string {
   139  	s := make([]string, 0, len(ValidPHPVersions))
   140  
   141  	for p := range ValidPHPVersions {
   142  		s = append(s, p)
   143  	}
   144  	sort.Sort(natural.StringSlice(s))
   145  	return s
   146  }
   147  
   148  // IsValidDatabaseVersion checks if the version is valid for the provided database type
   149  func IsValidDatabaseVersion(dbType string, dbVersion string) bool {
   150  	switch dbType {
   151  	case MariaDB:
   152  		return IsValidMariaDBVersion(dbVersion)
   153  	case MySQL:
   154  		return IsValidMySQLVersion(dbVersion)
   155  	case Postgres:
   156  		return IsValidPostgresVersion(dbVersion)
   157  	}
   158  	return false
   159  }
   160  
   161  // GetValidDatabaseVersions returns a slice of valid versions with the format
   162  // mariadb:10.5/mysql:5.7/postgres:14
   163  func GetValidDatabaseVersions() []string {
   164  	combos := []string{}
   165  	for _, v := range GetValidMariaDBVersions() {
   166  		combos = append(combos, MariaDB+":"+v)
   167  	}
   168  	for _, v := range GetValidMySQLVersions() {
   169  		combos = append(combos, MySQL+":"+v)
   170  	}
   171  	for _, v := range GetValidPostgresVersions() {
   172  		combos = append(combos, Postgres+":"+v)
   173  	}
   174  
   175  	return combos
   176  }
   177  
   178  // IsValidMariaDBVersion is a helper function to determine if a MariaDB version is valid, returning
   179  // true if the supplied MariaDB version is valid and false otherwise.
   180  func IsValidMariaDBVersion(v string) bool {
   181  	if _, ok := ValidMariaDBVersions[strings.TrimPrefix(v, MariaDB+":")]; !ok {
   182  		return false
   183  	}
   184  
   185  	return true
   186  }
   187  
   188  // IsValidMySQLVersion is a helper function to determine if a MySQL version is valid, returning
   189  // true if the supplied version is valid and false otherwise.
   190  func IsValidMySQLVersion(v string) bool {
   191  	if _, ok := ValidMySQLVersions[strings.TrimPrefix(v, MySQL+":")]; !ok {
   192  		return false
   193  	}
   194  
   195  	return true
   196  }
   197  
   198  // GetValidMariaDBVersions is a helper function that returns a list of valid MariaDB versions.
   199  func GetValidMariaDBVersions() []string {
   200  	s := make([]string, 0, len(ValidMariaDBVersions))
   201  
   202  	for p := range ValidMariaDBVersions {
   203  		s = append(s, p)
   204  	}
   205  	sort.Sort(natural.StringSlice(s))
   206  	return s
   207  }
   208  
   209  // IsValidPostgresVersion is a helper function to determine if a PostgreSQL version is valid, returning
   210  // true if the supplied version is valid and false otherwise.
   211  func IsValidPostgresVersion(v string) bool {
   212  	if _, ok := ValidPostgresVersions[strings.TrimPrefix(v, Postgres+":")]; !ok {
   213  		return false
   214  	}
   215  
   216  	return true
   217  }
   218  
   219  // GetValidMySQLVersions is a helper function that returns a list of valid MySQL versions.
   220  func GetValidMySQLVersions() []string {
   221  	s := make([]string, 0, len(ValidMySQLVersions))
   222  
   223  	for p := range ValidMySQLVersions {
   224  		s = append(s, p)
   225  	}
   226  	sort.Sort(natural.StringSlice(s))
   227  	return s
   228  }
   229  
   230  // GetValidPostgresVersions is a helper function that returns a list of valid PostgreSQL versions.
   231  func GetValidPostgresVersions() []string {
   232  	s := make([]string, 0, len(ValidPostgresVersions))
   233  
   234  	for p := range ValidPostgresVersions {
   235  		s = append(s, p)
   236  	}
   237  	sort.Sort(natural.StringSlice(s))
   238  	return s
   239  }
   240  
   241  // IsValidWebserverType is a helper function to determine if a webserver type is valid, returning
   242  // true if the supplied webserver type is valid and false otherwise.
   243  func IsValidWebserverType(webserverType string) bool {
   244  	if _, ok := ValidWebserverTypes[webserverType]; !ok {
   245  		return false
   246  	}
   247  
   248  	return true
   249  }
   250  
   251  // GetValidWebserverTypes is a helper function that returns a list of valid webserver types.
   252  func GetValidWebserverTypes() []string {
   253  	s := make([]string, 0, len(ValidWebserverTypes))
   254  
   255  	for p := range ValidWebserverTypes {
   256  		s = append(s, p)
   257  	}
   258  
   259  	return s
   260  }
   261  
   262  // IsValidOmitContainers is a helper function to determine if a the OmitContainers array is valid
   263  func IsValidOmitContainers(containerList []string) bool {
   264  	for _, containerName := range containerList {
   265  		if _, ok := ValidOmitContainers[containerName]; !ok {
   266  			return false
   267  		}
   268  	}
   269  	return true
   270  }
   271  
   272  // GetValidOmitContainers is a helper function that returns a list of valid containers for OmitContainers.
   273  func GetValidOmitContainers() []string {
   274  	s := make([]string, 0, len(ValidOmitContainers))
   275  
   276  	for p := range ValidOmitContainers {
   277  		s = append(s, p)
   278  	}
   279  
   280  	return s
   281  }