chore(dev): update devcontainer definitions

This commit is contained in:
Quentin McGaw
2023-05-29 15:57:09 +00:00
parent aed235f52d
commit c2972f7bf6
3 changed files with 114 additions and 122 deletions

View File

@@ -9,17 +9,21 @@ It works on Linux, Windows and OSX.
- [VS code](https://code.visualstudio.com/download) installed - [VS code](https://code.visualstudio.com/download) installed
- [VS code remote containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) installed - [VS code remote containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) installed
- [Docker](https://www.docker.com/products/docker-desktop) installed and running - [Docker](https://www.docker.com/products/docker-desktop) installed and running
- If you don't use Linux or WSL 2, share your home directory `~/` and the directory of your project with Docker Desktop
- [Docker Compose](https://docs.docker.com/compose/install/) installed - [Docker Compose](https://docs.docker.com/compose/install/) installed
- Ensure your host has the following and that they are accessible by Docker:
- `~/.ssh` directory
- `~/.gitconfig` file (can be empty)
## Setup ## Setup
1. Create the following files on your host if you don't have them:
```sh
touch ~/.gitconfig ~/.zsh_history
```
Note that the development container will create the empty directories `~/.docker`, `~/.ssh` and `~/.kube` if you don't have them.
1. **For Docker on OSX or Windows without WSL**: ensure your home directory `~` is accessible by Docker.
1. Open the command palette in Visual Studio Code (CTRL+SHIFT+P). 1. Open the command palette in Visual Studio Code (CTRL+SHIFT+P).
1. Select `Remote-Containers: Open Folder in Container...` and choose the project directory. 1. Select `Remote-Containers: Open Folder in Container...` and choose the project directory.
1. For Docker running on Windows HyperV, if you want to use SSH keys, bind mount them at `/tmp/.ssh` by changing the `volumes` section in the [docker-compose.yml](docker-compose.yml).
## Customization ## Customization
@@ -29,13 +33,9 @@ You can make changes to the [Dockerfile](Dockerfile) and then rebuild the image.
```Dockerfile ```Dockerfile
FROM qmcgaw/godevcontainer FROM qmcgaw/godevcontainer
USER root
RUN apk add curl RUN apk add curl
USER vscode
``` ```
Note that you may need to use `USER root` to build as root, and then change back to `USER vscode`.
To rebuild the image, either: To rebuild the image, either:
- With VSCode through the command palette, select `Remote-Containers: Rebuild and reopen in container` - With VSCode through the command palette, select `Remote-Containers: Rebuild and reopen in container`
@@ -47,11 +47,11 @@ You can customize **settings** and **extensions** in the [devcontainer.json](dev
### Entrypoint script ### Entrypoint script
You can bind mount a shell script to `/home/vscode/.welcome.sh` to replace the [current welcome script](shell/.welcome.sh). You can bind mount a shell script to `/root/.welcome.sh` to replace the [current welcome script](shell/.welcome.sh).
### Publish a port ### Publish a port
To access a port from your host to your development container, publish a port in [docker-compose.yml](docker-compose.yml). To access a port from your host to your development container, publish a port in [docker-compose.yml](docker-compose.yml). You can also now do it directly with VSCode without restarting the container.
### Run other services ### Run other services

View File

@@ -1,82 +1,76 @@
{ {
"name": "gluetun-dev", "name": "gluetun-dev",
"dockerComposeFile": [ "dockerComposeFile": [
"docker-compose.yml" "docker-compose.yml"
], ],
"service": "vscode", "service": "vscode",
"runServices": [ "runServices": [
"vscode" "vscode"
], ],
"shutdownAction": "stopCompose", "shutdownAction": "stopCompose",
"postCreateCommand": "source ~/.windows.sh && go mod download && go mod tidy", "postCreateCommand": "~/.windows.sh && go mod download && go mod tidy",
"workspaceFolder": "/workspace", "workspaceFolder": "/workspace",
"extensions": [ // "overrideCommand": "",
"golang.go", "customizations": {
"eamodio.gitlens", // IDE Git information "vscode": {
"davidanson.vscode-markdownlint", "extensions": [
"ms-azuretools.vscode-docker", // Docker integration and linting "golang.go",
"shardulm94.trailing-spaces", // Show trailing spaces "eamodio.gitlens", // IDE Git information
"Gruntfuggly.todo-tree", // Highlights TODO comments "davidanson.vscode-markdownlint",
"bierner.emojisense", // Emoji sense for markdown "ms-azuretools.vscode-docker", // Docker integration and linting
"stkb.rewrap", // rewrap comments after n characters on one line "shardulm94.trailing-spaces", // Show trailing spaces
"vscode-icons-team.vscode-icons", // Better file extension icons "Gruntfuggly.todo-tree", // Highlights TODO comments
"github.vscode-pull-request-github", // Github interaction "bierner.emojisense", // Emoji sense for markdown
"redhat.vscode-yaml", // Kubernetes, Drone syntax highlighting "stkb.rewrap", // rewrap comments after n characters on one line
"bajdzis.vscode-database", // Supports connections to mysql or postgres, over SSL, socked "vscode-icons-team.vscode-icons", // Better file extension icons
"IBM.output-colorizer", // Colorize your output/test logs "github.vscode-pull-request-github", // Github interaction
"mohsen1.prettify-json", // Prettify JSON data "redhat.vscode-yaml", // Kubernetes, Drone syntax highlighting
"github.copilot", "bajdzis.vscode-database", // Supports connections to mysql or postgres, over SSL, socked
], "IBM.output-colorizer", // Colorize your output/test logs
"settings": { "github.copilot" // AI code completion
"files.eol": "\n", ],
"remote.extensionKind": { "settings": {
"ms-azuretools.vscode-docker": "workspace" "files.eol": "\n",
}, "remote.extensionKind": {
"editor.codeActionsOnSaveTimeout": 3000, "ms-azuretools.vscode-docker": "workspace"
"go.useLanguageServer": true, },
"[go]": { "go.useLanguageServer": true,
"editor.formatOnSave": true, "[go]": {
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.organizeImports": true, "source.organizeImports": true
}, }
// Optional: Disable snippets, as they conflict with completion ranking. },
"editor.snippetSuggestions": "none" "[go.mod]": {
}, "editor.codeActionsOnSave": {
"[go.mod]": { "source.organizeImports": true
"editor.formatOnSave": true, }
"editor.codeActionsOnSave": { },
"source.organizeImports": true, "gopls": {
}, "build.buildFlags": [
}, "-tags",
"gopls": { ""
"usePlaceholders": false, ],
"staticcheck": true "usePlaceholders": false,
}, "staticcheck": true
"go.autocompleteUnimportedPackages": true, },
"go.gotoSymbol.includeImports": true, "go.lintTool": "golangci-lint",
"go.gotoSymbol.includeGoroot": true, "go.lintOnSave": "package",
"go.lintTool": "golangci-lint", "editor.formatOnSave": true,
"go.buildOnSave": "workspace", "go.toolsEnvVars": {
"go.lintOnSave": "workspace", "CGO_ENABLED": "0"
"go.vetOnSave": "workspace", },
"editor.formatOnSave": true, "go.testEnvVars": {
"go.toolsEnvVars": { "CGO_ENABLED": "1"
"GOFLAGS": "-tags=", },
// "CGO_ENABLED": 1 // for the race detector "go.testFlags": [
}, "-v",
"gopls.env": { "-race"
"GOFLAGS": "-tags=" ],
}, "go.testTimeout": "10s",
"go.testEnvVars": { "go.coverOnSingleTest": true,
"": "" "go.coverOnSingleTestFile": true,
}, "go.coverOnTestPackage": true
"go.testFlags": [ }
"-v", }
// "-race" }
],
"go.testTimeout": "10s",
"go.coverOnSingleTest": true,
"go.coverOnSingleTestFile": true,
"go.coverOnTestPackage": true
}
} }

View File

@@ -1,30 +1,28 @@
version: "3.7" version: "3.7"
services: services:
vscode: vscode:
build: . build: .
devices: volumes:
- /dev/net/tun:/dev/net/tun - ../:/workspace
volumes: # Docker socket to access Docker server
- ../:/workspace - /var/run/docker.sock:/var/run/docker.sock
# Docker socket to access Docker server # SSH directory for Linux, OSX and WSL
- /var/run/docker.sock:/var/run/docker.sock # On Linux and OSX, a symlink /mnt/ssh <-> ~/.ssh is
# Docker configuration # created in the container. On Windows, files are copied
- ~/.docker:/root/.docker # from /mnt/ssh to ~/.ssh to fix permissions.
# SSH directory for Linux, OSX and WSL - ~/.ssh:/mnt/ssh
# On Linux and OSX, a symlink /mnt/ssh <-> ~/.ssh is # Shell history persistence
# created in the container. On Windows, files are copied - ~/.zsh_history:/root/.zsh_history
# from /mnt/ssh to ~/.ssh to fix permissions. # Git config
- ~/.ssh:/mnt/ssh - ~/.gitconfig:/root/.gitconfig
# Shell history persistence environment:
- ~/.zsh_history:/root/.zsh_history - TZ=
environment: cap_add:
- TZ= # For debugging with dlv
cap_add: - SYS_PTRACE
# For debugging with dlv - NET_ADMIN
# - SYS_PTRACE security_opt:
- NET_ADMIN # For debugging with dlv
security_opt: - seccomp:unconfined
# For debugging with dlv entrypoint: [ "zsh", "-c", "while sleep 1000; do :; done" ]
- seccomp:unconfined
entrypoint: zsh -c "while sleep 1000; do :; done"