diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index b3809f9..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "build": { - "args": { - "SDK_VERSION": "${localEnv:SDK_VERSION}" - }, - "dockerfile": "../${localEnv:DOCKER_FILE_PATH}" - }, - "initializeCommand": "docker volume create ${localEnv:VSCODE_CONTAINER_PROJECT}", - "name": "${localEnv:VSCODE_CONTAINER_PROJECT}", - "postCreateCommand": "sudo chown vscode ${containerWorkspaceFolder}", - "runArgs": [ - "--name", - "${localEnv:VSCODE_CONTAINER_PROJECT}" - ], - "workspaceFolder": "/mnt/${localEnv:VSCODE_CONTAINER_PROJECT}", - "workspaceMount": "source=${localEnv:VSCODE_CONTAINER_PROJECT},target=/mnt/${localEnv:VSCODE_CONTAINER_PROJECT},type=volume" -} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2eea525..541e1c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.env \ No newline at end of file +/projects/* +!/projects/.template \ No newline at end of file diff --git a/README.md b/README.md index c67e4c4..7569a6c 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ # VS Code Dev Container Playground -This repository keeps a minimal VS Code Dev Container setup that runs on top of Docker. With parameterized environment variables consumed by `.devcontainer/devcontainer.json`, the same workflow can prepare a baseline container environment for different development needs. +This repository provides a template-based workflow for VS Code Dev Containers. Shared settings live under `compose-base/`, and each local dev container is created by copying `projects/.template/` into `projects/`. ## Getting Started Prerequisites: Docker is available on the host, and VS Code has the `ms-vscode-remote.remote-containers` extension installed. 1. Download the repository (e.g., `git clone https://github.com/iplaylf2/vscode-container.git`). -2. Set the required environment variables (for example `VSCODE_CONTAINER_PROJECT`, `DOCKER_FILE_PATH`, `SDK_VERSION`). -3. Open the folder in VS Code and run `Dev Containers: Reopen in Container`. +2. Copy `projects/.template/` to `projects/`. +3. Edit `projects//docker-compose.yaml` as needed. +4. Set `VSCODE_CONTAINER_PROJECT` in the host environment that will launch VS Code. +5. Open `projects/` in VS Code and run `Dev Containers: Reopen in Container`. -After the container is created, VS Code reopens the workspace inside the container. When the volume is freshly created, that directory starts empty. +After the container is created, VS Code opens the workspace at `/mnt/${VSCODE_CONTAINER_PROJECT}`. The data lives in a Docker volume named `${VSCODE_CONTAINER_PROJECT}`. ## Configuration Notes -- `VSCODE_CONTAINER_PROJECT` controls both the Docker volume name and the `/mnt/` path inside the container. -- Keep `DOCKER_FILE_PATH` and `SDK_VERSION` as environment variables so switching Dockerfiles or toolchains only requires updating those values. -- The default container user is `vscode`; `postCreateCommand` ensures that account owns the workspace directory. +- `VSCODE_CONTAINER_PROJECT` provides the project identity (volume name and `/mnt/` path); it is an environment variable because `devcontainer.json` cannot pass variables into Docker Compose. diff --git a/compose-base/docker-compose.yaml b/compose-base/docker-compose.yaml new file mode 100644 index 0000000..8b4d962 --- /dev/null +++ b/compose-base/docker-compose.yaml @@ -0,0 +1,12 @@ +name: ${VSCODE_CONTAINER_PROJECT} + +services: + devcontainer: + build: + context: .. + volumes: + - devcontainer-workspace:/mnt/${VSCODE_CONTAINER_PROJECT} + +volumes: + devcontainer-workspace: + name: ${VSCODE_CONTAINER_PROJECT} diff --git a/projects/.template/.devcontainer/devcontainer.json b/projects/.template/.devcontainer/devcontainer.json new file mode 100644 index 0000000..fd933b5 --- /dev/null +++ b/projects/.template/.devcontainer/devcontainer.json @@ -0,0 +1,11 @@ +{ + "name": "${localEnv:VSCODE_CONTAINER_PROJECT}", + "dockerComposeFile": [ + "../../../compose-base/docker-compose.yaml", + "../docker-compose.yaml" + ], + "service": "devcontainer", + "workspaceFolder": "/mnt/${localEnv:VSCODE_CONTAINER_PROJECT}", + "postCreateCommand": "sudo chown vscode ${containerWorkspaceFolder}", + "overrideCommand": true +} diff --git a/projects/.template/docker-compose.yaml b/projects/.template/docker-compose.yaml new file mode 100644 index 0000000..3d8f540 --- /dev/null +++ b/projects/.template/docker-compose.yaml @@ -0,0 +1,9 @@ +services: + devcontainer: + # Base settings come from ../../compose-base/docker-compose.yaml via dockerComposeFile. + build: + # Pick the Dockerfile that matches your dev environment. + dockerfile: images/base/Dockerfile + args: + # Optional: toolchain version for Dockerfiles that accept SDK_VERSION. + SDK_VERSION: 0