Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
update build context usage ; comments and docs
Browse files Browse the repository at this point in the history
Signed-off-by: Oscar Ward <[email protected]>
  • Loading branch information
Oscar Ward committed Oct 12, 2023
1 parent 635f88d commit bc084f4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
3 changes: 2 additions & 1 deletion docs/docs/100-reference/01-command-line/acorn_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ acorn dev <IMAGE>
acorn dev .
acorn dev --name wandering-sound
acorn dev --name wandering-sound <IMAGE>
acorn dev --name wandering-sound --clone [acorn args]
```

Expand All @@ -26,7 +27,7 @@ acorn dev --name wandering-sound <IMAGE>
--args-file string Default args to apply to run/update command (default ".args.acorn")
--auto-upgrade Enabled automatic upgrades.
-b, --bidirectional-sync In interactive mode download changes in addition to uploading
--clone Clone the vcs repository for the given app
--clone Clone the vcs repository and infer the build context for the given app allowing for local development
-f, --file string Name of the build file (default "DIRECTORY/Acornfile")
-h, --help help for dev
--help-advanced Show verbose help text
Expand Down
11 changes: 5 additions & 6 deletions pkg/cli/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ acorn dev <IMAGE>
acorn dev .
acorn dev --name wandering-sound
acorn dev --name wandering-sound <IMAGE>
acorn dev --name wandering-sound --clone [acorn args]
`})

// This will produce an error if the volume flag doesn't exist or a completion function has already
Expand All @@ -46,7 +47,7 @@ type Dev struct {
RunArgs
BidirectionalSync bool `usage:"In interactive mode download changes in addition to uploading" short:"b"`
Replace bool `usage:"Replace the app with only defined values, resetting undefined fields to default values" json:"replace,omitempty"` // Replace sets patchMode to false, resulting in a full update, resetting all undefined fields to their defaults
Clone bool `usage:"Clone the vcs repository for the given app"`
Clone bool `usage:"Clone the vcs repository and infer the build context for the given app allowing for local development"`
HelpAdvanced bool `usage:"Show verbose help text"`
out io.Writer
client ClientFactory
Expand All @@ -73,16 +74,14 @@ func (s *Dev) Run(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

acornfile, buildContext, err := vcs.ImageInfoFromApp(cmd.Context(), app)
if err != nil {
return err
}

bc := app.Status.Staged.AppImage.VCS.BuildContext
if bc != "" {
args = append(args, buildContext)
}
// We append the build context to the start of the args so that it gets set, and we can pass any args down to the running app
args = append([]string{buildContext}, args...)

imageSource = imagesource.NewImageSource(s.client.AcornConfigFile(), acornfile, s.ArgsFile, args, nil, z.Dereference(s.AutoUpgrade))
}

Expand Down
9 changes: 3 additions & 6 deletions pkg/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func ImageInfoFromApp(ctx context.Context, app *apiv1.App) (string, string, erro
}

for _, remote := range vcs.Remotes {
// Since we use ssh auth to clone the repo we need a git url but will sometimes get http urls
var gitUrl string
httpUrl, err := url.Parse(remote)
if err == nil {
Expand All @@ -113,6 +114,7 @@ func ImageInfoFromApp(ctx context.Context, app *apiv1.App) (string, string, erro
gitUrl = remote
}

// Determine the repository name from the repo url
idx := strings.LastIndex(remote, "/")
if idx < 0 || idx >= len(remote) {
fmt.Printf("failed to determine repository name %q\n", remote)
Expand Down Expand Up @@ -163,12 +165,7 @@ func ImageInfoFromApp(ctx context.Context, app *apiv1.App) (string, string, erro
}

// Get the build context
var buildContext string
if vcs.BuildContext == "." {
buildContext = workdir
} else {
buildContext = filepath.Join(workdir, vcs.BuildContext)
}
buildContext := filepath.Join(workdir, vcs.BuildContext)

return acornfile, buildContext, nil
}
Expand Down

0 comments on commit bc084f4

Please sign in to comment.