Skip to content

Commit

Permalink
Merge pull request #180 from platformsh/akalipetis/issue-174
Browse files Browse the repository at this point in the history
Fix Laravel database and n handling
  • Loading branch information
akalipetis authored Oct 26, 2023
2 parents 8c05717 + 453709a commit 144653f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion internal/question/build_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (q *BuildSteps) Ask(ctx context.Context) error {
answers.Environment["N_PREFIX"] = "/app/.global"
answers.BuildSteps = append(
answers.BuildSteps,
"n auto",
"n auto || n lts",
"hash -r",
)
}
Expand Down
31 changes: 8 additions & 23 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"encoding/json"
"errors"
"io"
"os"
"path/filepath"
Expand All @@ -28,31 +27,17 @@ func FileExists(searchPath, name string) bool {

// FindFile searches for the file inside the path recursively
// and returns the full path of the file if found
// If multiple files exist, tries to return the one closest to root
func FindFile(searchPath, name string) string {
var found string
//nolint:errcheck
filepath.WalkDir(searchPath, func(p string, d os.DirEntry, err error) error {
if err != nil {
return err
}

if d.IsDir() {
// Skip vendor directories
if slices.Contains(skipDirs, d.Name()) {
return filepath.SkipDir
}
return nil
}

if d.Name() == name {
found = p
return errors.New("found")
}
files := FindAllFiles(searchPath, name)
if len(files) == 0 {
return ""
}

return nil
slices.SortFunc(files, func(a, b string) bool {
return len(strings.Split(a, string(os.PathSeparator))) < len(strings.Split(b, string(os.PathSeparator)))
})

return found
return files[0]
}

// FindAllFiles searches for the file inside the path recursively and returns all matches
Expand Down
19 changes: 11 additions & 8 deletions platformifier/templates/upsun/.environment
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{{- if .Database }}
export RELATIONSHIPS_JSON="$(echo ${{ .Assets.EnvPrefix }}_RELATIONSHIPS | base64 --decode)"

# Set database environment variables
export DB_HOSTNAME="${{ .DatabaseUpper }}_HOSTNAME"
{{- if .Database }}# Set database environment variables
export DB_HOST="${{ .DatabaseUpper }}_HOST"
export DB_PORT="${{ .DatabaseUpper }}_PORT"
export DB_PATH="${{ .DatabaseUpper }}_PATH"
export DB_USERNAME="${{ .DatabaseUpper }}_USERNAME"
export DB_PASSWORD="${{ .DatabaseUpper }}_PASSWORD"
export DB_SCHEME="${{ .DatabaseUpper }}_SCHEME"
export DATABASE_URL="${DB_SCHEME}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}/${DB_PATH}"
export DATABASE_URL="${DB_SCHEME}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_PATH}"
{{- end -}}
{{- if eq .Stack.Name "laravel" }}

# Set Laravel-specific environment variables
export DB_CONNECTION="$DB_SCHEME"
export DB_DATABASE="$DB_PATH"
{{- end -}}
{{- if .Cache }}

# Set Cache environment variables
export CACHE_HOSTNAME="${{ .CacheUpper }}_HOSTNAME"
export CACHE_HOST="${{ .CacheUpper }}_HOST"
export CACHE_PORT="${{ .CacheUpper }}_PORT"
export CACHE_SCHEME="${{ .CacheUpper }}_SCHEME"
export CACHE_URL="${CACHE_SCHEME}://${CACHE_HOSTNAME}:${CACHE_PORT}"
export CACHE_URL="${CACHE_SCHEME}://${CACHE_HOST}:${CACHE_PORT}"
{{- end -}}
{{- if or (eq .Cache "redis") (eq .Cache "redis_persistent") }}

Expand Down

0 comments on commit 144653f

Please sign in to comment.