Skip to content

Commit 853ed6f

Browse files
authored
Add vscode remote container development files (prebid#1481)
1 parent 1e9ecd4 commit 853ed6f

File tree

5 files changed

+136
-1
lines changed

5 files changed

+136
-1
lines changed

.devcontainer/Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# From https://github.com/microsoft/vscode-dev-containers/blob/master/containers/go/.devcontainer/Dockerfile
2+
ARG VARIANT=1
3+
FROM mcr.microsoft.com/vscode/devcontainers/go:${VARIANT}
4+
5+
# [Optional] Install a version of Node.js using nvm for front end dev
6+
ARG INSTALL_NODE="true"
7+
ARG NODE_VERSION="lts/*"
8+
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
9+
10+
# [Optional] Uncomment this section to install additional OS packages.
11+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
12+
&& apt-get -y install --no-install-recommends vim
13+
14+
# [Optional] Uncomment the next line to use go get to install anything else you need
15+
# RUN go get -x <your-dependency-or-tool>
16+
17+
# [Optional] Uncomment this line to install global node packages.
18+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

.devcontainer/devcontainer.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.112.0/containers/go
3+
{
4+
"name": "Go",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
"args": {
8+
// Update the VARIANT arg to pick a version of Go: 1, 1.15, 1.14
9+
"VARIANT": "1.14",
10+
// Options
11+
"INSTALL_NODE": "false",
12+
"NODE_VERSION": "lts/*",
13+
}
14+
},
15+
"containerEnv": {
16+
"GOPRIVATE": "${localEnv:GOPRIVATE}",
17+
},
18+
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
19+
20+
// Set *default* container specific settings.json values on container create.
21+
"settings": {
22+
"terminal.integrated.shell.linux": "/bin/bash",
23+
"go.useGoProxyToCheckForToolUpdates": false,
24+
"go.gopath": "/go",
25+
//"go.toolsGopath": "/tmp/go",
26+
},
27+
28+
// Add the IDs of extensions you want installed when the container is created.
29+
"extensions": [
30+
"golang.Go",
31+
"ms-azuretools.vscode-docker",
32+
"redhat.vscode-xml",
33+
"redhat.vscode-yaml",
34+
"eamodio.gitlens",
35+
],
36+
37+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
38+
"forwardPorts": [8000,8001,6060],
39+
40+
// Use 'postCreateCommand' to run commands after the container is created.
41+
"postCreateCommand": "mkdir ~/.ssh; ssh-keyscan github.com > ~/.ssh/known_hosts",
42+
43+
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
44+
"remoteUser": "vscode"
45+
}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ _obj
88
_test
99
.cover/
1010
.idea/
11-
.vscode/
1211

1312
# Architecture specific extensions/prefixes
1413
*.[568vq]
@@ -46,6 +45,7 @@ analytics/filesystem/testFiles/
4645
# static/version.txt
4746

4847
.idea/
48+
.vscode/
4949

5050
# autogenerated mac file
5151

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,8 @@ Want to [add an adapter](https://docs.prebid.org/prebid-server/developers/add-ne
5555
Report bugs, request features, and suggest improvements [on Github](https://github.com/prebid/prebid-server/issues).
5656

5757
Or better yet, [open a pull request](https://github.com/prebid/prebid-server/compare) with the changes you'd like to see.
58+
59+
## IDE Setup for PBS-Go development
60+
61+
The quickest way to start developing PBS-Go in a reproducible environment isolated from your host OS
62+
is by using this [VScode Remote Container Setup](devcontainer.md)

devcontainer.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
### vscode in-container development
3+
4+
The quickest way to get up and running with PBS-Go development in a reproducible environment isolated
5+
from your host OS is by loading the repository in a [Docker](https://docs.docker.com/get-docker/)
6+
container under [Visual Studio Code](https://code.visualstudio.com/).
7+
8+
This covers installing Go and necessary IDE plugins for Golang editing and debugging, and is
9+
all automated via the VSCode [.devcontainer](.devcontainer/) configuration. See
10+
[VSCode Remote Containers](https://code.visualstudio.com/docs/remote/containers) for more
11+
details about how to customize.
12+
13+
#### Setup
14+
15+
Install:
16+
17+
- [Docker](https://docs.docker.com/get-docker/)
18+
- [Visual Studio Code](https://code.visualstudio.com/)
19+
- [VSCode Remote Development Extension Pack](https://aka.ms/vscode-remote/download/extension)
20+
21+
Then:
22+
23+
- start VSCode and open repository
24+
- accept VSCode suggestion to _reopen in container_
25+
- VSCode will build a new container and install the IDE support and extensions in it
26+
27+
Optionally, to use your github ssh key for accessing non-public GitHub repositories:
28+
- Method 1: add your github ssh key to agent. This is needed after each OS restart.
29+
```sh
30+
ssh-add ~/.ssh/id_rsa # or your ssh key for github
31+
```
32+
- Method 2: map your ~/.ssh (or just the key) as a docker volume in .devcontainer.json
33+
34+
Feel free to customize .devcontainer.json if needed. You can add preset environment variables,
35+
other vscode extensions to preload and additional volume mounts.
36+
37+
#### Starting PBS-Go
38+
39+
- `Shift`-`Cmd`-`D` or `Run` icon brings up the `Launch prebid-server` panel with interactive
40+
debugger. Breakpoints can be set to stop execution.
41+
- CTRL-`\`` opens the terminal to start prebid-server non-interactively
42+
```sh
43+
go run main.go --alsologtostderr
44+
```
45+
- Create a pbs.yaml file if neccessary, with configuration overrides.
46+
47+
#### Testing
48+
49+
- Open any `*_test.go` file in editor
50+
- Individual test functions can be run directly by clicking the `run test`/`debug test` annotation
51+
above each test function.
52+
- At the top of the file you can see `run package tests | run file tests`
53+
- TIP: use `run package tests` at the top of the test file to quickly check code coverage:
54+
the open editors for files in the tested package will have lines highlighted in green (covered)
55+
and red (not covered)
56+
- CTRL-`\`` opens the terminal to run the test suite
57+
```sh
58+
./validate.sh
59+
```
60+
61+
#### Editing
62+
- Style, imports are automatically updated on save.
63+
- Editor can suggest correct names and
64+
65+
- Remote container commands popup by clicking on _Dev Container: Go_ at bottom left
66+
- `F1` -> type _rebuild container_ to restart with a fresh container
67+
- `F1` -> `^`-`\`` to toggle terminal

0 commit comments

Comments
 (0)