Skip to content

Commit

Permalink
make sure workdir is owned by autopilot user (#275)
Browse files Browse the repository at this point in the history
* make sure workdir is owned by autopilot user
* added clearer errors for `generateManifests`
  • Loading branch information
ATGardner authored Apr 10, 2022
1 parent ca1b7a6 commit 8764c02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RUN make local DEV_MODE=false
### Run
FROM alpine:3.15 as autopilot

WORKDIR /go/src/github.com/argoproj-labs/argocd-autopilot
WORKDIR /home/autopilot

RUN apk -U add --no-cache git

Expand All @@ -50,6 +50,7 @@ COPY --from=base /etc/passwd /etc/passwd
COPY --from=base /etc/group /etc/group
COPY --chown=autopilot:autopilot --from=autopilot-build /go/src/github.com/argoproj-labs/argocd-autopilot/dist/* /usr/local/bin/argocd-autopilot

RUN chown -R autopilot:autopilot /home/autopilot
USER autopilot:autopilot

ENTRYPOINT [ "argocd-autopilot" ]
12 changes: 6 additions & 6 deletions pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,27 +507,27 @@ func fixResourcesPaths(k *kusttypes.Kustomization, newKustDir string) error {
var generateManifests = func(k *kusttypes.Kustomization) ([]byte, error) {
td, err := ioutil.TempDir(".", "auto-pilot")
if err != nil {
return nil, err
return nil, fmt.Errorf("failed creating temp dir: %w", err)
}
defer os.RemoveAll(td)

absTd, err := filepath.Abs(td)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed getting abs path for \"%s\": %w", td, err)
}

if err = fixResourcesPaths(k, absTd); err != nil {
return nil, err
return nil, fmt.Errorf("failed fixing resources paths: %w", err)
}

kyaml, err := yaml.Marshal(k)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed marshaling yaml: %w", err)
}

kustomizationPath := filepath.Join(td, "kustomization.yaml")
if err = ioutil.WriteFile(kustomizationPath, kyaml, 0400); err != nil {
return nil, err
return nil, fmt.Errorf("failed writing file to \"%s\": %w", kustomizationPath, err)
}

log.G().WithFields(log.Fields{
Expand All @@ -541,7 +541,7 @@ var generateManifests = func(k *kusttypes.Kustomization) ([]byte, error) {
fs := filesys.MakeFsOnDisk()
res, err := kust.Run(fs, td)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed running kustomization: %w", err)
}

return res.AsYaml()
Expand Down

0 comments on commit 8764c02

Please sign in to comment.