Skip to content

Commit 26f8384

Browse files
isaacmbrownjules-pjkeech
authored
[Improvement] Codespaces: Document that any changes outside /workspaces are cleared on rebuild (github#35698)
Co-authored-by: Jules <[email protected]> Co-authored-by: John Keech <[email protected]>
1 parent 3fa5a2a commit 26f8384

File tree

11 files changed

+77
-39
lines changed

11 files changed

+77
-39
lines changed

content/codespaces/codespaces-reference/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ children:
1010
- /using-the-github-codespaces-plugin-for-jetbrains
1111
- /using-the-vs-code-command-palette-in-codespaces
1212
- /security-in-github-codespaces
13-
- /performing-a-full-rebuild-of-a-container
1413
- /disaster-recovery-for-github-codespaces
1514
---
1615

content/codespaces/developing-in-codespaces/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ children:
1717
- /using-github-codespaces-for-pull-requests
1818
- /stopping-and-starting-a-codespace
1919
- /forwarding-ports-in-your-codespace
20+
- /rebuilding-the-container-in-a-codespace
2021
- /default-environment-variables-for-your-codespace
2122
- /persisting-environment-variables-and-temporary-files
2223
- /connecting-to-a-private-network

content/codespaces/developing-in-codespaces/persisting-environment-variables-and-temporary-files.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ For all the methods of setting custom variables listed below, you can access the
2222

2323
You can set the value of the environment variable in the `~/.bashrc` file, or in an equivalent configuration file if you are not using the Bash shell. For example, add the statement `VARNAME=value`.
2424

25-
After you save the change to this file, the value will be set the next time you open the codespace, or you can set it immediately by using a command such as `source ~/.bashrc`. The variable will remain set if you stop and start the codespace. However, changes to files in the home directory will be reset if you rebuild the container, so variables set in the `~/.bashrc` file will not persist over a rebuild.
25+
After you save the change to this file, the value will be set the next time you open the codespace, or you can set it immediately by using a command such as `source ~/.bashrc`. The variable will remain set if you stop and start the codespace. However, changes to files in the home directory will be reset if you rebuild the container, so variables set in the `~/.bashrc` file will not persist over a rebuild. For more information, see "[Preventing temporary files from being automatically deleted](#preventing-temporary-files-from-being-automatically-deleted)."
2626

2727
### For all codespaces for a repository
2828

@@ -72,6 +72,8 @@ If you want to set a personalized environment variable for all codespaces that y
7272

7373
## Preventing temporary files from being automatically deleted
7474

75-
Files saved to your workspace will be available the next time you start the codespace. The exception to this is any file you save in the `/tmp` directory. The contents of this directory are deleted each time the codespace stops (for example, when the codespace session times out after a period of inactivity).
75+
{% data reusables.codespaces.workspaces-directory %} For information about creating symlinks to preserve data outside the `/workspaces` directory, see "[AUTOTITLE](/codespaces/developing-in-codespaces/rebuilding-the-container-in-a-codespace#persisting-data-over-a-rebuild)."
7676

77-
If you have temporary files that you want to be available the next time you start the codespace, do not save them in the `/tmp` directory. For more information, see "[AUTOTITLE](/codespaces/customizing-your-codespace/setting-your-timeout-period-for-github-codespaces)."
77+
The `/tmp` directory is an exception because it is mounted into the container, but it is not persistent. Therefore, the contents of the `/tmp` directory are persisted over a rebuild, but are cleared each time the codespace stops. For example, the `/tmp` directory is cleared when a codespace session times out after a period of inactivity. For more information, see "[AUTOTITLE](/codespaces/customizing-your-codespace/setting-your-timeout-period-for-github-codespaces)."
78+
79+
If you have temporary files that you want to be available the next time you start the codespace, do not save them in the `/tmp` directory.

content/codespaces/codespaces-reference/performing-a-full-rebuild-of-a-container.md renamed to content/codespaces/developing-in-codespaces/rebuilding-the-container-in-a-codespace.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
---
2-
title: Performing a full rebuild of a container
3-
intro: 'If you are low on disk space, or want to ensure your dev container configuration will work in new codespaces, you can perform a full rebuild of a container.'
2+
title: Rebuilding the container in a codespace
3+
intro: 'You can rebuild a container to apply configuration changes to the codespaces you are working in. From time to time, you may want to perform a full rebuild.'
44
versions:
55
fpt: '*'
66
ghec: '*'
7-
type: reference
7+
type: how_to
88
topics:
99
- Codespaces
10-
shortTitle: Full rebuilds
10+
shortTitle: Rebuilding a container
11+
redirect_from:
12+
- /codespaces/codespaces-reference/performing-a-full-rebuild-of-a-container
1113
---
1214

1315
## About rebuilding a container
@@ -23,20 +25,26 @@ Occasionally, you may want to perform a full rebuild of your container. With a f
2325
- You want to ensure that the setup defined in your configuration is not dependent on cached images, and will run as required when someone creates a new codespace based on the configuration. For example, a dependency may have been removed from the base image since it was last pulled into your codespace.
2426
- You want to free up the disk space used by your cache, for example if you are low on disk space or want to minimize storage charges. Your image cache might be using a significant amount of disk space if you've changed your base image multiple times, if you've made a large number of iterative changes to your configuration, or if you're running multiple containers with Docker Compose.
2527

26-
## Performing a full rebuild
28+
## Rebuilding a container
2729

28-
You can perform a full rebuild in {% data variables.product.prodname_vscode %}.
30+
You can rebuild a container within a codespace in the {% data variables.product.prodname_vscode_shortname %} web client or desktop application, or you can use {% data variables.product.prodname_cli %}.
31+
32+
### Rebuilding the dev container in the {% data variables.product.prodname_vscode_shortname %} web client or desktop application
2933

3034
{% data reusables.codespaces.command-palette %}
31-
1. Start typing "Rebuild" and select **Codespaces: Full Rebuild Container**.
35+
1. Start typing "Rebuild" and select **Codespaces: Rebuild Container** or **Codespaces: Full Rebuild Container**.
3236

3337
![Screenshot of the "Codespaces: Full Rebuild Container" option in the Command Palette.](/assets/images/help/codespaces/codespaces-rebuild-full.png)
3438

35-
## Persisting data over a full rebuild
39+
{% data reusables.codespaces.rebuilding-container-procedures %}
40+
41+
To perform a full rebuild with {% data variables.product.prodname_cli %}, you can use the `gh codespace rebuild --full` command.
42+
43+
## Persisting data over a rebuild
3644

37-
Any files and folders contained in the `/workspaces` directory of your codespace are always persisted over a rebuild. You do not need to change any settings or add any configuration to retain the contents of this directory over a full rebuild.
45+
{% data reusables.codespaces.workspaces-directory %}
3846

39-
If you want to preserve files outside the `/workspaces` directory over a full rebuild, you can create, at the desired location in the container, a symbolic link (symlink) to the persistent directory. For example, in your `/workspaces/.devcontainer` directory, you can create a `config` directory that will be preserved across a rebuild. You can then symlink the `config` directory and its contents as a `postCreateCommand` in your `devcontainer.json` file.
47+
If you want to preserve files outside the `/workspaces` directory over a rebuild, you can create, at the desired location in the container, a symbolic link (symlink) to the persistent directory. For example, in your `/workspaces/.devcontainer` directory, you can create a `config` directory that will be preserved across a rebuild. You can then symlink the `config` directory and its contents as a `postCreateCommand` in your `devcontainer.json` file.
4048

4149
```json
4250
{

content/codespaces/getting-started/deep-dive.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ When you create a codespace, various steps happen in the background before the c
4242

4343
When you create a codespace, a [shallow clone](https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/) is made of your repository, or of the template repository if you're creating a codespace from a template. The repository is cloned to a Linux virtual machine that is both dedicated and private to you. Having a dedicated VM ensures that you have the entire set of compute resources from that machine available to you. If necessary, this also allows you to have full root access to your container.
4444

45+
Your repository is cloned into the `/workspaces` directory in the codespace. For more information, see "[About the directory structure of a codespace](#about-the-directory-structure-of-a-codespace)" below.
46+
4547
### Step 2: Container is created
4648

4749
{% data variables.product.prodname_github_codespaces %} uses a container as the development environment. This container is created based on configurations that you can define in a `devcontainer.json` file and, optionally, a Dockerfile. If you create a codespace from {% data variables.product.company_short %}'s blank template, or from a repository with no `devcontainer.json` file, {% data variables.product.prodname_github_codespaces %} uses a default image, which has many languages and runtimes available. For more information, see "[AUTOTITLE](/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers)." For details of what the default image contains, see the [`devcontainers/images`](https://github.com/devcontainers/images/tree/main/src/universal) repository.
@@ -153,6 +155,18 @@ If you work on your codespaces in a JetBrains IDE, you can add plugins from the
153155

154156
1. Click **Install** beside the required plugin.
155157

158+
## About the directory structure of a codespace
159+
160+
{% data reusables.codespaces.workspaces-directory %} For more information on the `/tmp` directory, see "[AUTOTITLE](/codespaces/developing-in-codespaces/persisting-environment-variables-and-temporary-files#preventing-temporary-files-from-being-automatically-deleted)."
161+
162+
Clearing the directories outside `/workspaces` helps to ensure the rebuilt container is in the same state as it would be in a newly created codespace. If you're rebuilding a container to apply configuration changes to the codespace you're working in, you can be confident that any configuration changes you have made will work the same for users creating new codespaces with the same configuration. For more information, see "[AUTOTITLE](/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers)."
163+
164+
If you want to make changes to your codespace that will be more robust over rebuilds and across different codespaces, you have several options.
165+
166+
- To install programs and tools in all codespaces created from a repository, in your dev container configuration, you can use lifecycle command properties such as `postCreateCommand` to run custom installation commands, or you can choose from pre-written installation commands called "features." For more information, see the [dev containers specification](https://containers.dev/implementors/json_reference/#lifecycle-scripts) on the Development Containers website and "[AUTOTITLE](/codespaces/setting-up-your-project-for-codespaces/configuring-dev-containers/adding-features-to-a-devcontainer-file)."
167+
- To install tools or customize your setup in every codespace you create, such as configuring your `bash` profile, you can link {% data variables.product.prodname_github_codespaces %} with a dotfiles repository. The dotfiles repository is also cloned into the persistent `/workspaces` directory. For more information, see "[AUTOTITLE](/codespaces/customizing-your-codespace/personalizing-github-codespaces-for-your-account#dotfiles)."
168+
- If you want to preserve specific files over a rebuild, you can use a `devcontainer.json` file to create a symlink between the files and a persistent directory within `/workspaces`. For more information, see "[AUTOTITLE](/codespaces/developing-in-codespaces/rebuilding-the-container-in-a-codespace#persisting-data-over-a-rebuild)."
169+
156170
## Further reading
157171

158172
- "[AUTOTITLE](/codespaces/managing-codespaces-for-your-organization/enabling-github-codespaces-for-your-organization)"

content/codespaces/getting-started/the-codespace-lifecycle.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ When a codespace times out, your data is preserved from the last time your chang
4343

4444
You can rebuild your codespace to implement changes to your dev container configuration. For most uses, you can create a new codespace as an alternative to rebuilding a codespace. By default, when you rebuild your codespace, {% data variables.product.prodname_github_codespaces %} will reuse images from your cache to speed up the rebuild process. Alternatively, you can perform a full rebuild, which clears your cache and rebuilds the container with fresh images.
4545

46-
For more information, see "[AUTOTITLE](/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers#applying-configuration-changes-to-a-codespace)" and "[AUTOTITLE](/codespaces/codespaces-reference/performing-a-full-rebuild-of-a-container)."
46+
{% data reusables.codespaces.rebuild-note %}
47+
48+
For more information, see "[AUTOTITLE](/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers)" and "[AUTOTITLE](/codespaces/developing-in-codespaces/rebuilding-the-container-in-a-codespace)."
4749

4850
## Stopping a codespace
4951

content/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers.md

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ You can add a predefined dev container configuration either while working in a c
151151

152152
1. Follow the prompts to customize your definition.
153153
1. Click **OK**.
154-
1. If you are working in a codespace, apply your changes, by clicking **Rebuild now** in the message at the bottom right of the window. For more information about rebuilding your container, see "[Applying changes to your configuration](#applying-configuration-changes-to-a-codespace)."
154+
1. If you are working in a codespace, apply your changes by clicking **Rebuild now** in the pop-up at the bottom right of the window. For more information about rebuilding your container, see "[Applying configuration changes to a codespace](#applying-configuration-changes-to-a-codespace)."
155155

156156
![Screenshot of the message: "We've noticed a change to the dev container configuration." Below this is the "Rebuild Now" button.](/assets/images/help/codespaces/rebuild-prompt.png)
157157

@@ -227,31 +227,12 @@ You can define default interface settings for {% data variables.product.prodname
227227

228228
Changes to a configuration will be applied the next time you create a codespace. However, you can apply your changes to an existing codespace by rebuilding the container. You can do this within a codespace in the {% data variables.product.prodname_vscode_shortname %} web client or desktop application, or you can use {% data variables.product.prodname_cli %}.
229229

230+
{% data reusables.codespaces.rebuild-note %}
231+
230232
### Rebuilding the dev container in the {% data variables.product.prodname_vscode_shortname %} web client or desktop application
231233

232234
{% data reusables.codespaces.rebuild-command %}
233-
1. {% data reusables.codespaces.recovery-mode %}
234-
235-
![Screenshot of a message saying that the codespace is running in recovery mode. Below the message are buttons labeled "Cancel" and "View creation log."](/assets/images/help/codespaces/recovery-mode-error-message.png)
236-
237-
- To diagnose the error by reviewing the creation logs, click **View creation log**.
238-
- To fix the errors identified in the logs, update your `devcontainer.json` file.
239-
- To apply the changes, rebuild your container.
240-
241-
### Using {% data variables.product.prodname_cli %} to rebuild a dev container
242-
243-
If you've changed a dev container configuration outside of VS Code (for example, on {% data variables.product.prodname_dotcom_the_website %} or in a JetBrains IDE), you can use {% data variables.product.prodname_cli %} to rebuild the dev container for an existing codespace.
244-
245-
1. In a terminal, enter the following command.
246-
247-
```
248-
gh cs rebuild
249-
```
250-
251-
Your codespaces are listed.
252-
253-
1. Use the arrow keys on your keyboard to highlight the required codespace, then press <kbd>Enter</kbd>.
254-
235+
{% data reusables.codespaces.rebuilding-container-procedures %}
255236

256237
## Further reading
257238

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% tip %}
22

3-
**Tip:** You may occasionally want to perform a full rebuild to clear your cache and rebuild your container with fresh images. For more information, see "[AUTOTITLE](/codespaces/codespaces-reference/performing-a-full-rebuild-of-a-container)."
3+
**Tip:** You may occasionally want to perform a full rebuild to clear your cache and rebuild your container with fresh images. For more information, see "[AUTOTITLE](/codespaces/developing-in-codespaces/rebuilding-the-container-in-a-codespace#about-rebuilding-a-container)."
44

55
{% endtip %}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% note %}
2+
3+
**Note:** When you rebuild the container in a codespace, changes you have made outside the `/workspaces` directory are cleared. Changes you have made inside the `/workspaces` directory, which includes the clone of the repository or template from which you created the codespace, are preserved over a rebuild. For more information, see "[AUTOTITLE](/codespaces/getting-started/deep-dive#about-the-directory-structure-of-a-codespace)."
4+
5+
{% endnote %}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
1. {% data reusables.codespaces.recovery-mode %}
2+
3+
![Screenshot of a message saying that the codespace is running in recovery mode. Below the message are buttons labeled "Cancel" and "View creation log."](/assets/images/help/codespaces/recovery-mode-error-message.png)
4+
5+
- To diagnose the error by reviewing the creation logs, click **View creation log**.
6+
- To fix the errors identified in the logs, update your `devcontainer.json` file.
7+
- To apply the changes, rebuild your container.
8+
9+
### Using {% data variables.product.prodname_cli %} to rebuild a dev container
10+
11+
If you've changed a dev container configuration outside of {% data variables.product.prodname_vscode_shortname %} (for example, on {% data variables.product.prodname_dotcom_the_website %} or in a JetBrains IDE), you can use {% data variables.product.prodname_cli %} to rebuild the dev container for an existing codespace.
12+
13+
1. In a terminal, enter the following command.
14+
15+
```
16+
gh codespace rebuild
17+
```
18+
19+
Your codespaces are listed.
20+
21+
1. Use the arrow keys on your keyboard to highlight the required codespace, then press <kbd>Enter</kbd>.

0 commit comments

Comments
 (0)