fix: respect the build-dir in app-json extraction

Because the app-json extraction happens before the build-dir is set, it doesn't end up respecting the value, and thus the user might get the wrong app.json file.

This takes advantage of path.Join()'s default of ignoring empty paths.
This commit is contained in:
Jose Diaz-Gonzalez
2023-02-14 03:56:09 -05:00
parent 0eccfe8ba4
commit 87828515a1
5 changed files with 37 additions and 3 deletions

View File

@@ -221,6 +221,22 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# TODO
```
### `builder-get-property`
- Description: Return the value for an app's builder property
- Invoked by:
- Arguments: `$APP $KEY`
- Example:
```shell
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
APP="$1"; PROPERTY="$2"
# TODO
```
### `builder-image-is-cnb`
- Description: Checks if an image is cnb-based

View File

@@ -83,9 +83,12 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
b, _ := common.PlugnTriggerOutput("git-get-property", []string{appName, "source-image"}...)
appSourceImage := strings.TrimSpace(string(b[:]))
b, _ = common.PlugnTriggerOutput("builder-get-property", []string{appName, "build-dir"}...)
buildDir := strings.TrimSpace(string(b[:]))
repoDefaultAppJSONPath := path.Join(sourceWorkDir, "app.json")
if appSourceImage == "" {
repoAppJSONPath := path.Join(sourceWorkDir, appJSONPath)
repoAppJSONPath := path.Join(sourceWorkDir, buildDir, appJSONPath)
if !common.FileExists(repoAppJSONPath) {
if appJSONPath != "app.json" && common.FileExists(repoDefaultAppJSONPath) {
if err := os.Remove(repoDefaultAppJSONPath); err != nil {
@@ -105,7 +108,7 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
}
}
} else {
if err := common.CopyFromImage(appName, appSourceImage, appJSONPath, processSpecificAppJSON); err != nil {
if err := common.CopyFromImage(appName, appSourceImage, path.Join(buildDir, appJSONPath), processSpecificAppJSON); err != nil {
return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificAppJSON))
}
}

View File

@@ -1,5 +1,5 @@
SUBCOMMANDS = subcommands/report subcommands/set
TRIGGERS = triggers/builder-detect triggers/builder-image-is-cnb triggers/builder-image-is-herokuish triggers/core-post-extract triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report
TRIGGERS = triggers/builder-detect triggers/builder-get-property triggers/builder-image-is-cnb triggers/builder-image-is-herokuish triggers/core-post-extract triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report
BUILD = commands subcommands triggers
PLUGIN_NAME = builder

View File

@@ -21,6 +21,10 @@ func main() {
case "builder-detect":
appName := flag.Arg(0)
err = builder.TriggerBuilderDetect(appName)
case "builder-get-property":
appName := flag.Arg(0)
property := flag.Arg(1)
err = builder.TriggerBuilderGetProperty(appName, property)
case "builder-image-is-cnb":
appName := flag.Arg(0)
image := flag.Arg(1)

View File

@@ -1,6 +1,7 @@
package builder
import (
"errors"
"fmt"
"io/ioutil"
"os"
@@ -26,6 +27,16 @@ func TriggerBuilderDetect(appName string) error {
return nil
}
// TriggerBuilderGetProperty writes the builder key to stdout for a given app container
func TriggerBuilderGetProperty(appName string, key string) error {
if key != "selected" && key != "build-dir" {
return errors.New("Invalid logs property specified")
}
fmt.Println(common.PropertyGet("builder", appName, key))
return nil
}
// TriggerBuilderImageIsCNB prints true if an image is cnb based, false otherwise
func TriggerBuilderImageIsCNB(appName string, image string) error {
if common.IsImageCnbBased(image) {