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

     1  package ddevapp
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/ddev/ddev/pkg/fileutil"
     6  	"github.com/ddev/ddev/pkg/nodeps"
     7  	"github.com/ddev/ddev/pkg/util"
     8  	"os"
     9  	"path/filepath"
    10  )
    11  
    12  // see https://github.com/ddev/ddev/pull/5058 if the bin folder changes.
    13  // isSilverstripeApp returns true if the app is of type Silverstripe
    14  func isSilverstripeApp(app *DdevApp) bool {
    15  	return fileutil.FileExists(filepath.Join(app.AppRoot, app.ComposerRoot, "vendor/bin/sake"))
    16  }
    17  
    18  func silverstripePostStartAction(app *DdevApp) error {
    19  	// We won't touch env if disable_settings_management: true
    20  	if app.DisableSettingsManagement {
    21  		return nil
    22  	}
    23  	envFilePath := filepath.Join(app.AppRoot, app.ComposerRoot, ".env")
    24  	_, envText, err := ReadProjectEnvFile(envFilePath)
    25  	if err != nil && !os.IsNotExist(err) {
    26  		return fmt.Errorf("Unable to read .env file: %v", err)
    27  	}
    28  	if os.IsNotExist(err) {
    29  		err = fileutil.CopyFile(filepath.Join(app.AppRoot, app.ComposerRoot, ".env.example"), envFilePath)
    30  		if err != nil {
    31  			util.Debug("Silverstripe: .env.example does not exist yet, not trying to process it")
    32  			return nil
    33  		}
    34  		_, envText, err = ReadProjectEnvFile(envFilePath)
    35  		if err != nil {
    36  			return err
    37  		}
    38  	}
    39  	port := "3306"
    40  	dbConnection := "MySQLDatabase"
    41  	// Although possible, it is extremely uncommon to use Postgres with Silverstripe.
    42  	// Thus the option is there to override
    43  	if app.Database.Type == nodeps.Postgres {
    44  		dbConnection = "PostgreSQLDatabase"
    45  		port = "5432"
    46  	}
    47  	envMap := map[string]string{
    48  		"SS_DATABASE_SERVER":        "db",
    49  		"SS_DATABASE_PORT":          port,
    50  		"SS_DATABASE_NAME":          "db",
    51  		"SS_DATABASE_USERNAME":      "db",
    52  		"SS_DATABASE_PASSWORD":      "db",
    53  		"SS_ENVIRONMENT_TYPE":       "dev",
    54  		"SS_DATABASE_CLASS":         dbConnection,
    55  		"MAILER_DSN":                "smtp://localhost:1025",
    56  		"SS_DEFAULT_ADMIN_USERNAME": "admin",
    57  		"SS_DEFAULT_ADMIN_PASSWORD": "password",
    58  	}
    59  	err = WriteProjectEnvFile(envFilePath, envMap, envText)
    60  	if err != nil {
    61  		return err
    62  	}
    63  
    64  	return nil
    65  }
    66  
    67  // getSilverstripeUploadDirs will return the default paths.
    68  func getSilverstripeUploadDirs(_ *DdevApp) []string {
    69  	uploadDirs := []string{"assets"}
    70  
    71  	return uploadDirs
    72  }
    73  
    74  // silverstripeConfigOverrideAction: Silverstripe prefers Apache
    75  // https://docs.silverstripe.org/en/5/getting_started/#server-requirements
    76  func silverstripeConfigOverrideAction(app *DdevApp) error {
    77  	app.WebserverType = nodeps.WebserverApacheFPM
    78  	return nil
    79  }