-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): support mounting sim.Container to state directories (#6295)
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)*.
- Loading branch information
Showing
6 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
4 changes: 4 additions & 0 deletions
4
libs/wingsdk/test/target-sim/my-docker-image.mounted-volume/Dockerfile
This file contains 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,4 @@ | ||
FROM node:20.8.0-alpine | ||
EXPOSE 3000 | ||
ADD index.js /app/index.js | ||
ENTRYPOINT [ "/app/index.js" ] |
18 changes: 18 additions & 0 deletions
18
libs/wingsdk/test/target-sim/my-docker-image.mounted-volume/index.js
This file contains 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 @@ | ||
#!/usr/bin/env node | ||
const http = require("http"); | ||
const fs = require("fs"); | ||
|
||
process.on("SIGINT", () => { | ||
console.info("Interrupted"); | ||
process.exit(0); | ||
}); | ||
|
||
const server = http.createServer((req, res) => { | ||
console.log(`request received: ${req.method} ${req.url}`); | ||
res.end(fs.readdirSync("/tmp").join("\n")); | ||
}); | ||
|
||
fs.writeFileSync("/tmp/hello.txt", "Hello, World!", "utf8"); | ||
|
||
console.log("listening on port 3000"); | ||
server.listen(3000); |