Skip to content

Commit a1509b8

Browse files
Add devcontainer.json (#1687)
Adds support for VS Code dev containers, which allows using the build environment in VS Code and Github Codespaces. See https://code.visualstudio.com/docs/remote/containers and https://github.com/features/codespaces for more information.
1 parent 752df03 commit a1509b8

File tree

7 files changed

+54
-12
lines changed

7 files changed

+54
-12
lines changed

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.5.0

.circleci/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ ENV NODE_VERSION=v10.16.3
2828
ENV NVM_VERSION=v0.35.0
2929
RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/${NVM_VERSION}/install.sh | bash
3030

31+
# Install Bazelisk as bazel to manage Bazel
32+
RUN go get github.com/bazelbuild/bazelisk && \
33+
mv $(which bazelisk) /usr/local/bin/bazel
34+
3135
# Clean up
3236
RUN apt-get autoremove -y && \
3337
apt-get remove -y wget \

.circleci/config.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ jobs:
8080
- generate
8181
- run: git diff --exit-code
8282
lint:
83-
docker:
84-
- image: golang:1.15
83+
executor: build-env
8584
working_directory: /src/grpc-gateway
8685
steps:
8786
- checkout
@@ -110,8 +109,7 @@ jobs:
110109
- setup_remote_docker
111110
- run: ./fuzzit.sh
112111
bazel:
113-
docker:
114-
- image: l.gcr.io/google/bazel:latest
112+
executor: build-env
115113
working_directory: /src/grpc-gateway
116114
steps:
117115
- checkout
@@ -162,8 +160,7 @@ jobs:
162160
- run: go mod vendor
163161
- run: curl -sL https://git.io/goreleaser | bash
164162
update-repositoriesbzl:
165-
docker:
166-
- image: l.gcr.io/google/bazel:latest
163+
executor: build-env
167164
working_directory: /src/grpc-gateway
168165
steps:
169166
- checkout

.devcontainer/devcontainer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"dockerFile": "../.circleci/Dockerfile",
3+
"overrideCommand": true,
4+
// Set *default* container specific settings.json values on container create.
5+
"settings": {
6+
"editor.formatOnSave": true,
7+
"terminal.integrated.shell.linux": "/bin/bash",
8+
"go.useGoProxyToCheckForToolUpdates": true,
9+
"go.useLanguageServer": true,
10+
"go.gopath": "/go",
11+
"go.goroot": "/usr/local/go",
12+
"go.toolsGopath": "/go/bin",
13+
"bazel.buildifierExecutable": "/go/bin/buildifier",
14+
"bazel.buildifierFixOnFormat": true,
15+
"bazel.enableCodeLens": true,
16+
},
17+
// Add the IDs of extensions you want installed when the container is created.
18+
"extensions": [
19+
"golang.Go",
20+
"bazelbuild.vscode-bazel",
21+
],
22+
"postCreateCommand": "cd $(mktemp -d) && GO111MODULE=on go get golang.org/x/tools/gopls@latest github.com/bazelbuild/buildtools/buildifier@latest && cd -",
23+
}

CONTRIBUTING.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ All submissions, including submissions by project members, require review.
2222

2323
### I want to regenerate the files after making changes
2424

25-
Great! It should be as simple as this (run from the root of the directory):
25+
#### Using Docker
26+
27+
It should be as simple as this (run from the root of the repository):
2628

2729
```bash
2830
docker run -v $(pwd):/src/grpc-gateway --rm docker.pkg.github.com/grpc-ecosystem/grpc-gateway/build-env:1.15 \
@@ -40,6 +42,25 @@ docker run -itv $(pwd):/grpc-gateway -w /grpc-gateway --entrypoint /bin/bash --r
4042
You may need to authenticate with GitHub to pull `docker.pkg.github.com/grpc-ecosystem/grpc-gateway/build-env`.
4143
You can do this by following the steps on the [GitHub Package docs](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages#authenticating-to-github-packages).
4244

45+
#### Using Visual Studio Code dev containers
46+
47+
This repo contains a `devcontainer.json` configuration that sets up the build environment in a container using
48+
[VS Code dev containers](https://code.visualstudio.com/docs/remote/containers). If you're using the dev container,
49+
you can run the commands directly in your terminal:
50+
51+
```shell
52+
$ make realclean && make examples && make testproto
53+
```
54+
55+
```shell
56+
$ bazel run :gazelle -- update-repos -from_file=go.mod -to_macro=repositories.bzl%go_repositories && \
57+
bazel run :gazelle && \
58+
bazel run :buildifier
59+
```
60+
61+
Note that the above listed docker commands will not work in the dev container, since volume mounts from
62+
nested docker container are not possible.
63+
4364
If this has resulted in some file changes in the repo, please ensure you check those in with your merge request.
4465

4566
### Making a release

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ $(OPENAPI_PLUGIN): $(OPENAPI_PLUGIN_SRC) $(OPENAPIV2_GO)
166166
$(EXAMPLE_SVCSRCS): $(GO_PLUGIN) $(GO_GRPC_PLUGIN) $(EXAMPLES)
167167
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --plugin=$(GO_GRPC_PLUGIN) --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. $(EXAMPLES)
168168
$(EXAMPLE_DEPSRCS): $(GO_PLUGIN) $(GO_GRPC_PLUGIN) $(EXAMPLE_DEPS)
169-
mkdir -p $(OUTPUT_DIR)
170-
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --plugin=$(GO_GRPC_PLUGIN) --go_out=paths=source_relative:$(OUTPUT_DIR) --go-grpc_out=paths=source_relative:$(OUTPUT_DIR) $(@:.pb.go=.proto)
171-
cp $(OUTPUT_DIR)/$@ $@ || cp $(OUTPUT_DIR)/$@ $@
169+
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --plugin=$(GO_GRPC_PLUGIN) --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. $(@:.pb.go=.proto)
172170

173171
$(RUNTIME_TEST_SRCS): $(GO_PLUGIN) $(GO_GRPC_PLUGIN) $(RUNTIME_TEST_PROTO)
174172
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --plugin=$(GO_GRPC_PLUGIN) --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. $(RUNTIME_TEST_PROTO)

WORKSPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ rules_proto_dependencies()
3131

3232
rules_proto_toolchains()
3333

34-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
35-
3634
http_archive(
3735
name = "io_bazel_rules_go",
3836
sha256 = "b725e6497741d7fc2d55fcc29a276627d10e43fa5d0bb692692890ae30d98d00",

0 commit comments

Comments
 (0)