From 2f44cb2afd89f1e860686c2de25b0d5f4555bd00 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Thu, 10 Oct 2024 21:17:12 +0000 Subject: [PATCH] chore(dev): migrate docker-compose.yml settings to devcontainer.json - works with codespaces - does not need full paths for host home directory bind mounts --- .devcontainer/devcontainer.json | 53 ++++++++++++++++++++++++++------ .devcontainer/docker-compose.yml | 24 --------------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4bb77f8..7c0a3e5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,51 @@ { + // See https://containers.dev/implementors/json_reference/ + // User defined settings + "containerEnv": { + "TZ": "" + }, + // Fixed settings "name": "ddns-dev", - "dockerComposeFile": [ - "docker-compose.yml" - ], - "service": "vscode", - "runServices": [ - "vscode" - ], - "shutdownAction": "stopCompose", "postCreateCommand": "~/.windows.sh && go mod download && go mod tidy", + "dockerComposeFile": "docker-compose.yml", + "overrideCommand": true, + "service": "vscode", "workspaceFolder": "/workspace", - // "overrideCommand": "", + "mounts": [ + // Source code + { + "source": "../", + "target": "/workspace", + "type": "bind" + }, + // Zsh commands history persistence + { + "source": "${localEnv:HOME}/.zsh_history", + "target": "/root/.zsh_history", + "type": "bind" + }, + // Git configuration file + { + "source": "${localEnv:HOME}/.gitconfig", + "target": "/root/.gitconfig", + "type": "bind" + }, + // SSH directory for Linux, OSX and WSL + // On Linux and OSX, a symlink /mnt/ssh <-> ~/.ssh is + // created in the container. On Windows, files are copied + // from /mnt/ssh to ~/.ssh to fix permissions. + { + "source": "${localEnv:HOME}/.ssh", + "target": "/mnt/ssh", + "type": "bind" + }, + // Docker socket to access the host Docker server + { + "source": "/var/run/docker.sock", + "target": "/var/run/docker.sock", + "type": "bind" + } + ], "customizations": { "vscode": { "extensions": [ diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index e2ac932..a0e8372 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,27 +1,3 @@ -version: "3.7" - services: vscode: build: . - volumes: - - ../:/workspace - # Docker socket to access Docker server - - /var/run/docker.sock:/var/run/docker.sock - # SSH directory for Linux, OSX and WSL - # On Linux and OSX, a symlink /mnt/ssh <-> ~/.ssh is - # created in the container. On Windows, files are copied - # from /mnt/ssh to ~/.ssh to fix permissions. - - ~/.ssh:/mnt/ssh - # Shell history persistence - - ~/.zsh_history:/root/.zsh_history - # Git config - - ~/.gitconfig:/root/.gitconfig - environment: - - TZ= - cap_add: - # For debugging with dlv - - SYS_PTRACE - security_opt: - # For debugging with dlv - - seccomp:unconfined - entrypoint: [ "zsh", "-c", "while sleep 1000; do :; done" ]