Skip to content
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

Postgres winglib does not retain state in simulator after reloading #6284

Closed
staycoolcall911 opened this issue Apr 21, 2024 · 5 comments · Fixed by winglang/winglibs#207
Closed
Assignees
Labels
✨ enhancement New feature or request 📚 libraries Wing Libraries needs-discussion Further discussion is needed prior to impl 🕹️ simulator Related to the `sim` compilation target

Comments

@staycoolcall911
Copy link
Contributor

Use Case

Postgres db is currently losing its state when the simulator is reloaded.
The use case here is to use postgres populated with some test data and avoiding having to re-populate the data frequently.

Proposed Solution

The Postgres Winglib sim implementation should save state to a local dir, similar to what was done for cloud.Buckets in #5164

Implementation Notes

See #5164 which added this capability to cloud.Buckets

Component

Libraries

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.
@staycoolcall911 staycoolcall911 added ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl labels Apr 21, 2024
@Chriscbr
Copy link
Contributor

I tested this locally - the state is retained as long as WING_ENABLE_INPLACE_UPDATES=true is enabled in your shell.

We have an issue for removing this feature flag here #6185, so I'll mark this resolved - @staycoolcall911 feel free to reopen if needed

@ekeren
Copy link
Collaborator

ekeren commented Apr 22, 2024 via email

@ekeren
Copy link
Collaborator

ekeren commented Apr 22, 2024

I mean persistent between two new runs

@ekeren
Copy link
Collaborator

ekeren commented Apr 22, 2024

You'll notice that I am using this flag in package.json

@ekeren ekeren reopened this Apr 22, 2024
@Chriscbr
Copy link
Contributor

Ah, I misunderstood. Thanks @ekeren, makes sense 👍

I'll look into this, it feels like there should be some way to do this with the volumes option in sim.Container

@Chriscbr Chriscbr self-assigned this Apr 22, 2024
mergify bot pushed a commit that referenced this issue Apr 22, 2024
To support retaining the state of `sim.Container` across separate Wing Console sessions, this PR adds the capability to reference the resource's state directory through the `WING_STATE_DIR` environment variable. This will be used by the `postgres` winglib to persist state through a mounted volume:

```js
let container = new sim.Container(
  name: "postgres",
  image: image,
  env: {
    POSTGRES_PASSWORD: "password"
  },
  volumes: ["$WING_STATE_DIR/pgdata:/var/lib/postgresql/data"],
  containerPort: 5432
);
```

Related to #6284

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@staycoolcall911 staycoolcall911 added 🕹️ simulator Related to the `sim` compilation target 📚 libraries Wing Libraries labels Apr 23, 2024
mergify bot pushed a commit that referenced this issue Apr 26, 2024
Another pass at solving #6284

The approach taken in #6295 where we allow users to bind to the state directory is problematic because docker sometimes changes the permissions of directories on the user's file system after mounting them. This was causing `wing test` to fail (fixed in #6320) and `wing pack` to fail as well.

This PR reworks the API so that data can be persisted via named volumes. Specifically, an anonymous docker volume can be specified, and Wing will automatically name it and reuse it across Wing Console runs. The change should fix the previous issues since named volumes are managed by docker.

The main downside of this approach is that deleting your `target` directory or the state files in `.state/` will not clean everything up all resources/files created by Wing from your machine, as Docker volumes may still exist. Eventually we can provide some facilities for automatically cleaning these, but we're leaving it intentionally out of scope until this general approach has been validated.

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request 📚 libraries Wing Libraries needs-discussion Further discussion is needed prior to impl 🕹️ simulator Related to the `sim` compilation target
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants