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

Add documentation on container/image clean-up for self-hosted runners #207

Open
stuartleeks opened this issue Feb 7, 2023 · 1 comment

Comments

@stuartleeks
Copy link
Collaborator

As per the discussion here, it might be useful to include documentation that discusses approaches to cleaning up the containers/images from dev container builds.

On hosted agents this isn't an issue, but on private agents this maintenance is required to avoid running out of disk space.

@alexanderilyin
Copy link

image

.devcontainer/devcontainer.sh

#!/usr/bin/env bash

set -euxo pipefail

DEVCONTAINER_DIR=$(dirname $0)
WORKSPACE_FOLDER=$(dirname "${DEVCONTAINER_DIR}")

function cleanup()
{
    CONTAINER_ID=$(jq -r .containerId .devcontainer/up.json)
    docker rm -f "${CONTAINER_ID}"
}

trap cleanup EXIT

devcontainer --workspace-folder "${WORKSPACE_FOLDER}" build | jq . > "${DEVCONTAINER_DIR}/build.json"
devcontainer --workspace-folder "${WORKSPACE_FOLDER}" up | jq . > "${DEVCONTAINER_DIR}/up.json"
devcontainer exec --workspace-folder "${WORKSPACE_FOLDER}" "$@"

Example

$ .devcontainer/devcontainer.sh date
…
+ devcontainer --workspace-folder . build
…
+ devcontainer --workspace-folder . up
Thu Aug 10 05:04:59 UTC 2023
…
+ docker rm -f 8c679b4f2cf01a0c4683dd0cb804a9acb627127edb34c1e9f742d8863c49250d

.devcontainer/build.json

{
  "outcome": "success",
  "imageName": [
    "vsc-lorem-ipsum-388f8b1048b835a5024f54faadc273fc158a3c9e0c84d2cc5e6397577206cca4-features"
  ]
}

.devcontainer/up.json

{
  "outcome": "success",
  "containerId": "8c679b4f2cf01a0c4683dd0cb804a9acb627127edb34c1e9f742d8863c49250d",
  "remoteUser": "vscode",
  "remoteWorkspaceFolder": "/workspaces/lorem-ipsum"
}

.gitignore

.devcontainer/build.json
.devcontainer/up.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants