Skip to content

Add snapshot save command (local)#210

Open
anisaoshafi wants to merge 17 commits into
mainfrom
drg-764-migrate-state-commands-from-cli-v1-export
Open

Add snapshot save command (local)#210
anisaoshafi wants to merge 17 commits into
mainfrom
drg-764-migrate-state-commands-from-cli-v1-export

Conversation

@anisaoshafi
Copy link
Copy Markdown
Collaborator

@anisaoshafi anisaoshafi commented Apr 28, 2026

Added a new snapshot subcommand with an initial save action that saves the current LocalStack state to a snapshot file.
Scope for this PR is saving a snapshot locally.
Saving remotely coming next.

@anisaoshafi anisaoshafi force-pushed the drg-764-migrate-state-commands-from-cli-v1-export branch 4 times, most recently from f6bbfbf to 6a24cdf Compare April 28, 2026 13:42
Comment thread cmd/snapshot.go Outdated
return fmt.Errorf("no emulator configured")
}

c := appConfig.Containers[0]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this could potentially panic. Snapshots are only for aws AFAIK so we could do this instead:
awsContainer := config.ContainerConfig{Type: config.EmulatorAWS, Port: config.DefaultAWSPort}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attempted to address here: f5a1f12

Comment thread internal/snapshot/destination.go Outdated
dest = "ls-state-export"
} else if strings.Contains(dest, "://") {
return nil, fmt.Errorf("cloud destinations are not yet supported — use a file path like ./my-snapshot")
} else if !strings.HasPrefix(dest, ".") && !strings.HasPrefix(dest, "/") && !strings.HasPrefix(dest, "~") && !strings.Contains(dest, "/") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this looks like it would not work on Windows? Can we make unit-tests more OS-agnostic to verify? Instead of defining the paths as strings we could use filepath.Join("subdir", "state")

return nil, fmt.Errorf("LocalStack returned status %d", resp.StatusCode)
}
return resp.Body, nil
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: we already have internal/snapshot/client.go for the aws emulator http api, can we add the new method there instead? Keeping a dedicated interface StateExporter just for the endpoints related to snapshots make sense to me though

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant to say internal/emulator/aws/client.go

Comment thread internal/snapshot/client.go Outdated
_ = resp.Body.Close()
return nil, fmt.Errorf("LocalStack returned status %d", resp.StatusCode)
}
return resp.Body, nil
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: instead of returning io.ReadCloser can we instead pass the io.Writer destination as argument?
This way we're sure the caller won't forget to close the returned body.

Comment thread internal/snapshot/destination.go Outdated
}

func (d LocalDestination) Writer() (io.WriteCloser, error) {
return os.Create(d.Path)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this abstraction won't work once we introduce pods because in the case of pods we are not saving to a file so we don't have a io.WriteCloser. We could just drop the interface for now?

@gtsiolis
Copy link
Copy Markdown
Member

I've posted a comment[1] in PRO-212 to discuss some potential changes, comments welcome!

@anisaoshafi anisaoshafi force-pushed the drg-764-migrate-state-commands-from-cli-v1-export branch from 19cab09 to cc8b494 Compare April 29, 2026 16:45
@anisaoshafi anisaoshafi force-pushed the drg-764-migrate-state-commands-from-cli-v1-export branch 3 times, most recently from cc4cd84 to 8ca807d Compare May 11, 2026 13:12
@anisaoshafi anisaoshafi force-pushed the drg-764-migrate-state-commands-from-cli-v1-export branch from c40edd6 to e2a83f0 Compare May 11, 2026 16:47
@anisaoshafi anisaoshafi force-pushed the drg-764-migrate-state-commands-from-cli-v1-export branch from e2a83f0 to b09a963 Compare May 11, 2026 17:02
anisaoshafi and others added 2 commits May 11, 2026 19:09
Without this, a failed io.Copy left a corrupt/partial ZIP on disk.
The user had no indication the file was incomplete.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Passing nil to runLstk inherited the developer's real $HOME, which
could write to ~/.config/lstk/lstk.log and the file-keyring fallback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verify that ErrorEvent is routed to errOut and all other events go to
out, and that nil writer arguments fall back safely without panicking.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@anisaoshafi anisaoshafi marked this pull request as ready for review May 11, 2026 17:27
@anisaoshafi anisaoshafi requested a review from silv-io as a code owner May 11, 2026 17:27
@anisaoshafi anisaoshafi force-pushed the drg-764-migrate-state-commands-from-cli-v1-export branch from 36170a5 to 7e45925 Compare May 11, 2026 17:47
@anisaoshafi anisaoshafi changed the title Add snapshot save command Add snapshot save command (local) May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants