Skip to content

Commit

Permalink
Fix filepath setup
Browse files Browse the repository at this point in the history
With the new mountPath spec, you can assume users specify a full/correct path in harness
  • Loading branch information
michaeljguarino committed May 27, 2024
1 parent 56a697c commit 8ffc1d9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
4 changes: 3 additions & 1 deletion dockerfiles/harness/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ COPY --chown=nonroot --from=environment /bin/sh /bin/sh
COPY --chown=nonroot --from=environment /bin/sleep /bin/sleep
COPY --from=builder /plural/harness /harness

ENTRYPOINT ["/harness", "--working-dir=plural"]
WORKDIR /plural

ENTRYPOINT ["/harness", "--working-dir=/plural"]
5 changes: 5 additions & 0 deletions internal/helpers/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helpers

import (
"os"
"path/filepath"
)

var (
Expand All @@ -19,5 +20,9 @@ func File() FileClient {
type fileClient struct{}

func (in *fileClient) Create(path, content string) error {
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return err
}

return os.WriteFile(path, []byte(content), 0644)
}
2 changes: 1 addition & 1 deletion pkg/harness/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (in *stackRunController) prepare() error {
env := environment.New(
environment.WithStackRun(in.stackRun),
environment.WithWorkingDir(in.dir),
environment.WithFilesDir(in.execWorkDir()),
environment.WithFilesDir(in.dir),
environment.WithFetchClient(in.fetchClient),
)

Expand Down
4 changes: 1 addition & 3 deletions pkg/harness/environment/environment.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package environment

import (
"path"

"k8s.io/klog/v2"

"github.com/pluralsh/deployment-operator/internal/helpers"
Expand Down Expand Up @@ -38,7 +36,7 @@ func (in *environment) prepareFiles() error {
}

for _, fragment := range in.stackRun.Files {
destination := path.Join(in.filesDir, fragment.Path)
destination := fragment.Path
if err := helpers.File().Create(destination, fragment.Content); err != nil {
klog.ErrorS(err, "failed preparing files", "path", destination)
return err
Expand Down
16 changes: 7 additions & 9 deletions pkg/harness/tool/terraform/modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"path"

"github.com/pluralsh/polly/algorithms"
"github.com/samber/lo"

"github.com/pluralsh/deployment-operator/internal/helpers"
)
Expand All @@ -20,9 +20,7 @@ func NewInitModifier() *InitModifier {

// Args implements exec.ArgsModifier type.
func (in *PlanModifier) Args(args []string) []string {
if algorithms.Index(args, func(a string) bool {
return a == "plan"
}) < 0 {
if !lo.Contains(args, "plan") {
return args
}

Expand All @@ -34,11 +32,11 @@ func NewPlanModifier(planFileName string) *PlanModifier {
}

func (in *ApplyModifier) Args(args []string) []string {
if !helpers.IsExists(path.Join(in.dir, in.planFileName)) ||
// This is to avoid doubling plan file arg if API already adds it
algorithms.Index(args, func(a string) bool {
return a == in.planFileName
}) >= 0 {
if !lo.Contains(args, "apply") {
return args
}

if !helpers.IsExists(path.Join(in.dir, in.planFileName)) || lo.Contains(args, in.planFileName) {
return args
}

Expand Down

0 comments on commit 8ffc1d9

Please sign in to comment.