-
-
Notifications
You must be signed in to change notification settings - Fork 585
/
assets.go
84 lines (72 loc) · 2.51 KB
/
assets.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
80
81
82
83
84
package ddevapp
import (
"embed"
"github.com/ddev/ddev/pkg/globalconfig"
"path/filepath"
"github.com/ddev/ddev/pkg/fileutil"
)
// The bundled assets for the project .ddev directory are in directory dotddev_assets
// And the global .ddev assets are in directory global_dotddev_assets
//
//go:embed dotddev_assets/* dotddev_assets/commands/.gitattributes
//go:embed global_dotddev_assets/* global_dotddev_assets/.gitignore global_dotddev_assets/commands/.gitattributes
//go:embed app_compose_template.yaml
//go:embed router_compose_template.yaml
//go:embed ssh_auth_compose_template.yaml
//go:embed traefik_config_template.yaml
//go:embed traefik_static_config_template.yaml
//go:embed traefik_global_config_template.yaml
//go:embed router_Dockerfile_template
//go:embed django4/*
//go:embed drupal/*
//go:embed magento/*
//go:embed wordpress/*
//go:embed typo3/*
//go:embed postgres/*
//go:embed healthcheck/*
var bundledAssets embed.FS
// PopulateExamplesCommandsHomeadditions grabs embedded assets and
// installs them into the named directory
// Note that running this with no appName (very common) can result in updating
// a *different* projects assets. So `ddev start something` will first update the current
// directory's assets (if it's a project) and then later (when called with appName) update
// the actual project's assets.
func PopulateExamplesCommandsHomeadditions(appName string) error {
err := fileutil.CopyEmbedAssets(bundledAssets, "global_dotddev_assets", globalconfig.GetGlobalDdevDir())
if err != nil {
return err
}
app, err := GetActiveApp(appName)
// If we have an error from GetActiveApp, it means we're not in a project directory
// That is not an error. It means we can not do this work, so return nil.
if err != nil {
return nil
}
err = fileutil.CopyEmbedAssets(bundledAssets, "dotddev_assets", app.GetConfigPath(""))
if err != nil {
return err
}
return nil
}
func IsBundledCustomCommand(globalCommand bool, service, command string) bool {
var baseDir string
if globalCommand {
baseDir = "global_dotddev_assets"
} else {
baseDir = "dotddev_assets"
}
_, err := bundledAssets.ReadFile(filepath.Join(baseDir, "commands", service, command))
return err == nil
}
func IsBundledCustomProvider(provider string) bool {
paths := []string{
filepath.Join("dotddev_assets", "providers", provider) + ".yaml",
filepath.Join("dotddev_assets", "providers", provider) + ".yaml.example",
}
for _, path := range paths {
if _, err := bundledAssets.ReadFile(path); err == nil {
return true
}
}
return false
}