{"id":21570472,"url":"https://github.com/gitpod-samples/persist-filesystem","last_synced_at":"2025-03-18T06:14:13.279Z","repository":{"id":261608571,"uuid":"884814958","full_name":"gitpod-samples/persist-filesystem","owner":"gitpod-samples","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-07T13:26:23.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T12:45:31.583Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gitpod-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-07T12:45:52.000Z","updated_at":"2024-11-07T13:26:27.000Z","dependencies_parsed_at":"2024-11-07T13:47:42.248Z","dependency_job_id":"d5481b9b-28b6-4e09-bd5d-23836e3d8263","html_url":"https://github.com/gitpod-samples/persist-filesystem","commit_stats":null,"previous_names":["gitpod-samples/persist-filesystem"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitpod-samples%2Fpersist-filesystem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitpod-samples%2Fpersist-filesystem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitpod-samples%2Fpersist-filesystem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitpod-samples%2Fpersist-filesystem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gitpod-samples","download_url":"https://codeload.github.com/gitpod-samples/persist-filesystem/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244166758,"owners_count":20409179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T11:12:54.575Z","updated_at":"2025-03-18T06:14:13.257Z","avatar_url":"https://github.com/gitpod-samples.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# persist filesystem\n\nThis repository demonstrates how you can configure your Gitpod workspace so that changes to $HOME (for example) or anywhere outside of `/workspace` directory survives from prebuild environments and between workspace reboots.\n\n\n# Quick Demo\n\nTo give you an idea of what this is and how it works, this repository is configured to persist all changes made to $HOME directory.\n\nHow to test this:\n1. Open this repository on Gitpod (direct link: https://gitpod.io/#https://github.com/gitpod-samples/persist-filesystem)\n2. Open a terminal\n3. Switch to $HOME: `cd $HOME`\n4. Perform any filesystem operation. For instance, create a new file: `touch hello`\n5. Stop your workspace: `gp stop`\n6. Re-start the same workspace again.\n7. Go back to $HOME and see if you can find the file: `cd \u0026\u0026 ls`\n\n# How it works and what you need to know\n\nWe're using two simple scripts, below is a description of their function\n\n### runonce\n\n[runonce](./runonce) reads the bash scripts from `$HOME/.runonce` directory and ensures that they're executed only once per session of a workspace, with the help of atomic locks. `runonce` command is added to `/etc/bash.bashrc` file, which is loaded on the very beginning of a Gitpod workspace startup via one of the init processes, so even if you use a different SHELL, it should be effective.\n\n### create-overlay\n\n[create-overlay](./create-overlay) is a wrapper script for [fuse-overlayfs](https://github.com/containers/fuse-overlayfs). It's only operation is to easily setup a overlayfs mount for your desired directory outside of `/workspace` in a way that they survive Gitpod workspace restarts or prebuild environments. This is done by redirecting all filesystem operations from your mountpoint to a hidden directory inside `/workspace`.\n\nThe usage is as follows:\n\n```bash\n# To persist $HOME and /etc directory. Usually, only $HOME is enough.\ncreate-overlay $HOME /etc\n```\n\n#### Automatic execution of create-overlay\n\nTo set it up automatically each time our workspace starts, we can create a [.runonce](#runonce) script from our Dockerfile as shown below:\n\n```dockerfile\n# If you want to persist $HOME (for example)\nRUN echo 'create-overlay $HOME' \u003e \"$HOME/.runonce/1-home_persist\"\n```\n\n# How to implement this for your existing Gitpod configuration\n\n- Merge the contents of [Dockerfile](./Dockerfile) with your own Dockerfile, you should exclude the `FROM ...` statement at the top though.\n- Copy [runonce](./runonce) and [create-overlay](./create-overlay) scripts over to your repository and commit them.\n- Configure [automatic execution](#automatic-execution-of-create-overlay) of [create-overlay](#create-overlay) with your desired directories that you want to persist.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitpod-samples%2Fpersist-filesystem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitpod-samples%2Fpersist-filesystem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitpod-samples%2Fpersist-filesystem/lists"}