fix: reformat existing buildpacks files
Previously, the shorthand was not properly supported. While this _should_ be the domain of the gliderlabs/herokuish repository, we do it here as a courtesy to Dokku users. Additionally, support the heroku-community => heroku mapping. Closes #4452
This commit is contained in:
@@ -3,18 +3,51 @@ package buildpacks
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
func rewriteBuildpacksFile(sourceWorkDir string) error {
|
||||
buildpacksPath := filepath.Join(sourceWorkDir, ".buildpacks")
|
||||
if !common.FileExists(buildpacksPath) {
|
||||
return nil
|
||||
}
|
||||
|
||||
buildpacks, err := common.FileToSlice(buildpacksPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i, buildpack := range buildpacks {
|
||||
if buildpack == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
buildpack, err = validBuildpackURL(buildpack)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse .buildpacks file, line %d: %s", i, err)
|
||||
}
|
||||
|
||||
buildpacks[i] = buildpack
|
||||
}
|
||||
|
||||
return common.WriteSliceToFile(buildpacksPath, buildpacks)
|
||||
}
|
||||
|
||||
func validBuildpackURL(buildpack string) (string, error) {
|
||||
if buildpack == "" {
|
||||
return buildpack, errors.New("Must specify a buildpack to add")
|
||||
}
|
||||
|
||||
reHerokuValue := regexp.MustCompile(`(?m)^([\w]+\/[\w]+)$`)
|
||||
reHerokuValue := regexp.MustCompile(`(?m)^([\w-]+\/[\w-]+)$`)
|
||||
if found := reHerokuValue.Find([]byte(buildpack)); found != nil {
|
||||
parts := strings.SplitN(buildpack, "/", 2)
|
||||
if parts[0] == "heroku-community" {
|
||||
parts[0] = "heroku"
|
||||
}
|
||||
return fmt.Sprintf("https://github.com/%s/heroku-buildpack-%s.git", parts[0], parts[1]), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ func TriggerPostExtract(appName string, sourceWorkDir string) error {
|
||||
}
|
||||
|
||||
if len(buildpacks) == 0 {
|
||||
return nil
|
||||
return rewriteBuildpacksFile(sourceWorkDir)
|
||||
}
|
||||
|
||||
buildpacksPath := filepath.Join(sourceWorkDir, ".buildpacks")
|
||||
|
||||
Reference in New Issue
Block a user