-
Notifications
You must be signed in to change notification settings - Fork 7
Release: v1.0.1 #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Release: v1.0.1 #30
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43c2b5c
Update commands to use new `--required-only` flag
chrismaddalena ccebebc
Fixed help message
chrismaddalena 9285274
Updated for changes
chrismaddalena e4b0e6d
Added `build` alias
chrismaddalena fe01bd7
Potential fix for pull request finding
chrismaddalena 46711f3
Added guardrails for older versions of Ghostwriter
chrismaddalena 675f6e8
Streams stdout/stderr live to the terminal while capturing
chrismaddalena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // buildCmd represents the build command | ||
| var buildCmd = &cobra.Command{ | ||
| Use: "build", | ||
| Short: "Shortcut for `containers build`", | ||
| Run: buildContainers, | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(buildCmd) | ||
| buildCmd.Flags().BoolVar( | ||
| &skipseed, | ||
| "skip-seed", | ||
| false, | ||
| `Skip (re-)seeding the database. This is useful when upgrading an existing installation and you know there are no new or adjusted values.`, | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package internal | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestCommandOutputTailKeepsBoundedTail(t *testing.T) { | ||
| tail := newCommandOutputTail(10) | ||
|
|
||
| if _, err := tail.Write([]byte("first-")); err != nil { | ||
| t.Fatalf("unexpected write error: %v", err) | ||
| } | ||
| if _, err := tail.Write([]byte("second")); err != nil { | ||
| t.Fatalf("unexpected write error: %v", err) | ||
| } | ||
|
|
||
| if got := tail.String(); got != "rst-second" { | ||
| t.Fatalf("expected bounded tail %q, got %q", "rst-second", got) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| // SeedDatabase runs Ghostwriter's /seed_data helper with optional arguments. | ||
| // | ||
| // Some older Ghostwriter images and local source checkouts do not support newer | ||
| // /seed_data flags, and the CLI cannot reliably infer support from VERSION or | ||
| // the network. When an optional argument is rejected by the command-line parser, | ||
| // retry once without optional arguments so updates can proceed against older | ||
| // builds. Other seed failures still return as hard errors. | ||
| func SeedDatabase(dockerInterface DockerInterface, seedArgs ...string) error { | ||
| output, err := runSeedData(dockerInterface, seedArgs...) | ||
| fmt.Print(output) | ||
| if err == nil { | ||
| return nil | ||
| } | ||
|
|
||
| if len(seedArgs) > 0 && seedArgsUnsupported(output, seedArgs...) { | ||
| fmt.Println("[!] This Ghostwriter build does not support the requested seed option(s); retrying without them...") | ||
| output, retryErr := runSeedData(dockerInterface) | ||
| fmt.Print(output) | ||
| if retryErr == nil { | ||
| return nil | ||
| } | ||
| return fmt.Errorf("optional seed arguments are unsupported, and retrying without them failed: %w", retryErr) | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| // runSeedData builds and runs the docker compose command for /seed_data. | ||
| func runSeedData(dockerInterface DockerInterface, seedArgs ...string) (string, error) { | ||
| seedCmd := append([]string{"run", "--rm", "django", "/seed_data"}, seedArgs...) | ||
| return dockerInterface.RunComposeCmdWithCombinedOutput(seedCmd...) | ||
| } | ||
|
|
||
| // seedArgsUnsupported reports whether Django's loaddata command rejected one | ||
| // of the optional seed arguments. This matches the observed invalid-argument | ||
| // output from Ghostwriter's local loaddata command: | ||
| // | ||
| // manage.py loaddata: error: unrecognized arguments: --unknown-option | ||
| func seedArgsUnsupported(output string, seedArgs ...string) bool { | ||
| lowerOutput := strings.ToLower(output) | ||
| loaddataInvalidArgs := "manage.py loaddata: error: unrecognized arguments:" | ||
| if !strings.Contains(lowerOutput, loaddataInvalidArgs) { | ||
| return false | ||
| } | ||
|
|
||
| for _, seedArg := range seedArgs { | ||
| if strings.Contains(lowerOutput, strings.ToLower(seedArg)) { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package internal | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestSeedArgsUnsupportedDetectsLoaddataInvalidArgument(t *testing.T) { | ||
| output := `usage: manage.py loaddata [-h] [--force] | ||
| fixture [fixture ...] | ||
| manage.py loaddata: error: unrecognized arguments: --required-only` | ||
|
|
||
| if !seedArgsUnsupported(output, "--required-only") { | ||
| t.Fatalf("expected loaddata invalid-argument output to be detected") | ||
| } | ||
| } | ||
|
|
||
| func TestSeedArgsUnsupportedIgnoresOtherParserErrors(t *testing.T) { | ||
| output := `usage: manage.py loaddata [-h] [--force] | ||
| fixture [fixture ...] | ||
| manage.py loaddata: error: the following arguments are required: fixture` | ||
|
|
||
| if seedArgsUnsupported(output, "--required-only") { | ||
| t.Fatalf("expected non-invalid-argument parser error to be ignored") | ||
| } | ||
| } | ||
|
|
||
| func TestSeedArgsUnsupportedIgnoresOtherSeedFailures(t *testing.T) { | ||
| output := "django.db.utils.IntegrityError: duplicate key value violates unique constraint" | ||
|
|
||
| if seedArgsUnsupported(output, "--required-only") { | ||
| t.Fatalf("expected unrelated seed failure to be ignored") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.