Skip to content

Add snapshot save command#210

Draft
anisaoshafi wants to merge 7 commits intomainfrom
drg-764-migrate-state-commands-from-cli-v1-export
Draft

Add snapshot save command#210
anisaoshafi wants to merge 7 commits intomainfrom
drg-764-migrate-state-commands-from-cli-v1-export

Conversation

@anisaoshafi
Copy link
Copy Markdown
Contributor

@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.
ℹ️ Subject to change/be adjusted once the design is ready.

@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
Contributor 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

_ = 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
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