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 committed 2023-02-14 03:56:28 -05:00
1 parent 0eccfe8ba4
commit 87828515a1
5 files changed
+37 -3

No files matched your search

+16
View File
@@ -221,6 +221,22 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# TODO # 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` ### `builder-image-is-cnb`
- Description: Checks if an image is cnb-based - Description: Checks if an image is cnb-based
+5 -2
View File
@@ -83,9 +83,12 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
b, _ := common.PlugnTriggerOutput("git-get-property", []string{appName, "source-image"}...) b, _ := common.PlugnTriggerOutput("git-get-property", []string{appName, "source-image"}...)
appSourceImage := strings.TrimSpace(string(b[:])) 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") repoDefaultAppJSONPath := path.Join(sourceWorkDir, "app.json")
if appSourceImage == "" { if appSourceImage == "" {
repoAppJSONPath := path.Join(sourceWorkDir, appJSONPath) repoAppJSONPath := path.Join(sourceWorkDir, buildDir, appJSONPath)
if !common.FileExists(repoAppJSONPath) { if !common.FileExists(repoAppJSONPath) {
if appJSONPath != "app.json" && common.FileExists(repoDefaultAppJSONPath) { if appJSONPath != "app.json" && common.FileExists(repoDefaultAppJSONPath) {
if err := os.Remove(repoDefaultAppJSONPath); err != nil { if err := os.Remove(repoDefaultAppJSONPath); err != nil {
@@ -105,7 +108,7 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
} }
} }
} else { } 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)) return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificAppJSON))
} }
} }
+1 -1
View File
@@ -1,5 +1,5 @@
SUBCOMMANDS = subcommands/report subcommands/set 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 BUILD = commands subcommands triggers
PLUGIN_NAME = builder PLUGIN_NAME = builder
+4
View File
@@ -21,6 +21,10 @@ func main() {
case "builder-detect": case "builder-detect":
appName := flag.Arg(0) appName := flag.Arg(0)
err = builder.TriggerBuilderDetect(appName) 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": case "builder-image-is-cnb":
appName := flag.Arg(0) appName := flag.Arg(0)
image := flag.Arg(1) image := flag.Arg(1)
+11
View File
@@ -1,6 +1,7 @@
package builder package builder
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@@ -26,6 +27,16 @@ func TriggerBuilderDetect(appName string) error {
return nil 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 // TriggerBuilderImageIsCNB prints true if an image is cnb based, false otherwise
func TriggerBuilderImageIsCNB(appName string, image string) error { func TriggerBuilderImageIsCNB(appName string, image string) error {
if common.IsImageCnbBased(image) { if common.IsImageCnbBased(image) {