-
-
Notifications
You must be signed in to change notification settings - Fork 585
/
silverstripe.go
79 lines (72 loc) · 2.37 KB
/
silverstripe.go
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
package ddevapp
import (
"fmt"
"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/util"
"os"
"path/filepath"
)
// see https://github.com/ddev/ddev/pull/5058 if the bin folder changes.
// isSilverstripeApp returns true if the app is of type Silverstripe
func isSilverstripeApp(app *DdevApp) bool {
return fileutil.FileExists(filepath.Join(app.AppRoot, app.ComposerRoot, "vendor/bin/sake"))
}
func silverstripePostStartAction(app *DdevApp) error {
// We won't touch env if disable_settings_management: true
if app.DisableSettingsManagement {
return nil
}
envFilePath := filepath.Join(app.AppRoot, app.ComposerRoot, ".env")
_, envText, err := ReadProjectEnvFile(envFilePath)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("Unable to read .env file: %v", err)
}
if os.IsNotExist(err) {
err = fileutil.CopyFile(filepath.Join(app.AppRoot, app.ComposerRoot, ".env.example"), envFilePath)
if err != nil {
util.Debug("Silverstripe: .env.example does not exist yet, not trying to process it")
return nil
}
_, envText, err = ReadProjectEnvFile(envFilePath)
if err != nil {
return err
}
}
port := "3306"
dbConnection := "MySQLDatabase"
// Although possible, it is extremely uncommon to use Postgres with Silverstripe.
// Thus the option is there to override
if app.Database.Type == nodeps.Postgres {
dbConnection = "PostgreSQLDatabase"
port = "5432"
}
envMap := map[string]string{
"SS_DATABASE_SERVER": "db",
"SS_DATABASE_PORT": port,
"SS_DATABASE_NAME": "db",
"SS_DATABASE_USERNAME": "db",
"SS_DATABASE_PASSWORD": "db",
"SS_ENVIRONMENT_TYPE": "dev",
"SS_DATABASE_CLASS": dbConnection,
"MAILER_DSN": "smtp://localhost:1025",
"SS_DEFAULT_ADMIN_USERNAME": "admin",
"SS_DEFAULT_ADMIN_PASSWORD": "password",
}
err = WriteProjectEnvFile(envFilePath, envMap, envText)
if err != nil {
return err
}
return nil
}
// getSilverstripeUploadDirs will return the default paths.
func getSilverstripeUploadDirs(_ *DdevApp) []string {
uploadDirs := []string{"assets"}
return uploadDirs
}
// silverstripeConfigOverrideAction: Silverstripe prefers Apache
// https://docs.silverstripe.org/en/5/getting_started/#server-requirements
func silverstripeConfigOverrideAction(app *DdevApp) error {
app.WebserverType = nodeps.WebserverApacheFPM
return nil
}