-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vscode remote container development files
Why: The vscode Golang plugin enforces style, identifies errors and has a remote debugger. Developing in a container isolates the dev environment from the host machine.
- Loading branch information
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# From https://github.com/microsoft/vscode-dev-containers/blob/master/containers/go/.devcontainer/Dockerfile | ||
ARG VARIANT=1 | ||
FROM mcr.microsoft.com/vscode/devcontainers/go:${VARIANT} | ||
|
||
# [Optional] Install a version of Node.js using nvm for front end dev | ||
ARG INSTALL_NODE="true" | ||
ARG NODE_VERSION="lts/*" | ||
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi | ||
|
||
# [Optional] Uncomment this section to install additional OS packages. | ||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
&& apt-get -y install --no-install-recommends vim | ||
|
||
# [Optional] Uncomment the next line to use go get to install anything else you need | ||
# RUN go get -x <your-dependency-or-tool> | ||
|
||
# [Optional] Uncomment this line to install global node packages. | ||
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: | ||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.112.0/containers/go | ||
{ | ||
"name": "Go", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"args": { | ||
// Update the VARIANT arg to pick a version of Go: 1, 1.15, 1.14 | ||
"VARIANT": "1.14", | ||
// Options | ||
"INSTALL_NODE": "false", | ||
"NODE_VERSION": "lts/*", | ||
} | ||
}, | ||
"containerEnv": { | ||
"GOPRIVATE": "${localEnv:GOPRIVATE}", | ||
}, | ||
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], | ||
|
||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"terminal.integrated.shell.linux": "/bin/bash", | ||
"go.useGoProxyToCheckForToolUpdates": false, | ||
"go.gopath": "/go", | ||
//"go.toolsGopath": "/tmp/go", | ||
}, | ||
|
||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"golang.Go", | ||
"ms-azuretools.vscode-docker", | ||
"redhat.vscode-xml", | ||
"redhat.vscode-yaml", | ||
"eamodio.gitlens", | ||
], | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
"forwardPorts": [8000,8001,6060], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
"postCreateCommand": "mkdir ~/.ssh; ssh-keyscan github.com > ~/.ssh/known_hosts", | ||
|
||
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "vscode" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
### vscode in-container development | ||
|
||
The quickest way to get up and running with PBS-Go development in a reproducible environment isolated | ||
from your host OS is by loading the repository in a [Docker](https://docs.docker.com/get-docker/) | ||
container under [Visual Studio Code](https://code.visualstudio.com/). | ||
|
||
This covers installing Go and necessary IDE plugins for Golang editing and debugging, and is | ||
all automated via the VSCode [.devcontainer](.devcontainer/) configuration. See | ||
[VSCode Remote Containers](https://code.visualstudio.com/docs/remote/containers) for more | ||
details about how to customize. | ||
|
||
#### Setup | ||
|
||
Install: | ||
|
||
- [Docker](https://docs.docker.com/get-docker/) | ||
- [Visual Studio Code](https://code.visualstudio.com/) | ||
- [VSCode Remote Development Extension Pack](https://aka.ms/vscode-remote/download/extension) | ||
|
||
Then: | ||
|
||
- start VSCode and open repository | ||
- accept VSCode suggestion to _reopen in container_ | ||
- VSCode will build a new container, install the IDE support in it and | ||
|
||
Optionally, to use your github ssh key for accessing non-public GitHub repositories: | ||
- Method 1: add your github ssh key to agent. This is needed after each OS restart. | ||
```sh | ||
ssh-add ~/.ssh/id_rsa # or your ssh key for github | ||
``` | ||
- Method 2: map your ~/.ssh (or just the key) as a docker volume in .devcontainer.json | ||
|
||
#### Starting PBS-Go | ||
|
||
- `Shift`-`Cmd`-`D` or `Run` icon brings up the `Launch prebid-server` panel with interactive | ||
debugger. Breakpoints can be set to stop execution. | ||
- CTRL-`\`` opens the terminal to start prebid-server non-interactively | ||
```sh | ||
go run main.go --alsologtostderr | ||
``` | ||
- Create a pbs.yaml file if neccessary, with configuration overrides. | ||
|
||
#### Testing | ||
|
||
- Open any `*_test.go` file in editor | ||
- Individual test functions can be run directly by clicking the `run test`/`debug test` annotation | ||
above each test function. | ||
- At the top of the file you can see `run package tests | run file tests` | ||
- TIP: use `run package tests` at the top of the test file to quickly check code coverage: | ||
the open editors for files in the tested package will have lines highlighted in green (covered) | ||
and red (not covered) | ||
- CTRL-`\`` opens the terminal to run the test suite | ||
```sh | ||
./validate.sh | ||
``` | ||
|
||
#### Editing | ||
- Style, imports are automatically updated on save. | ||
- Editor can suggest correct names and | ||
|
||
- Remote container commands popup by clicking on _Dev Container: Go_ at bottom left | ||
- `F1` -> type _rebuild container_ to restart with a fresh container | ||
- `F1` -> `^`-`\`` to toggle terminal |