Skip to content

Commit e0d4f53

Browse files
Add devcontainer.json (#1687) (#1691)
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 c338af1 commit e0d4f53

File tree

7 files changed

+53
-10
lines changed

7 files changed

+53
-10
lines changed

.bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.5.0

.circleci/Dockerfile

+4
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

+2-4
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ jobs:
9595
- setup_remote_docker
9696
- run: ./fuzzit.sh
9797
bazel:
98-
docker:
99-
- image: l.gcr.io/google/bazel:latest
98+
executor: build-env
10099
working_directory: /src/grpc-gateway
101100
steps:
102101
- checkout
@@ -141,8 +140,7 @@ jobs:
141140
- run: go mod vendor
142141
- run: curl -sL https://git.io/goreleaser | bash
143142
update-repositoriesbzl:
144-
docker:
145-
- image: l.gcr.io/google/bazel:latest
143+
executor: build-env
146144
working_directory: /src/grpc-gateway
147145
steps:
148146
- checkout

.devcontainer/devcontainer.json

+23
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

+22-1
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

+1-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ $(SWAGGER_PLUGIN): $(SWAGGER_PLUGIN_SRC) $(OPENAPIV2_GO)
176176
$(EXAMPLE_SVCSRCS): $(GO_PLUGIN) $(EXAMPLES)
177177
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:. $(EXAMPLES)
178178
$(EXAMPLE_DEPSRCS): $(GO_PLUGIN) $(EXAMPLE_DEPS)
179-
mkdir -p $(OUTPUT_DIR)
180-
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:$(OUTPUT_DIR) $(@:.pb.go=.proto)
181-
cp $(OUTPUT_DIR)/$@ $@ || cp $(OUTPUT_DIR)/$@ $@
179+
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:. $(@:.pb.go=.proto)
182180

183181
$(RUNTIME_TEST_SRCS): $(GO_PLUGIN) $(RUNTIME_TEST_PROTO)
184182
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:. $(RUNTIME_TEST_PROTO)

WORKSPACE

-2
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 = "7b9bbe3ea1fccb46dcfa6c3f3e29ba7ec740d8733370e21cdc8937467b4a4349",

0 commit comments

Comments
 (0)