Skip to content

Commit

Permalink
Add devcontainer.json (#1687) (#1691)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
johanbrandhorst authored Sep 24, 2020
1 parent c338af1 commit e0d4f53
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.5.0
4 changes: 4 additions & 0 deletions .circleci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ ENV NODE_VERSION=v10.16.3
ENV NVM_VERSION=v0.35.0
RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/${NVM_VERSION}/install.sh | bash

# Install Bazelisk as bazel to manage Bazel
RUN go get github.com/bazelbuild/bazelisk && \
mv $(which bazelisk) /usr/local/bin/bazel

# Clean up
RUN apt-get autoremove -y && \
apt-get remove -y wget \
Expand Down
6 changes: 2 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ jobs:
- setup_remote_docker
- run: ./fuzzit.sh
bazel:
docker:
- image: l.gcr.io/google/bazel:latest
executor: build-env
working_directory: /src/grpc-gateway
steps:
- checkout
Expand Down Expand Up @@ -141,8 +140,7 @@ jobs:
- run: go mod vendor
- run: curl -sL https://git.io/goreleaser | bash
update-repositoriesbzl:
docker:
- image: l.gcr.io/google/bazel:latest
executor: build-env
working_directory: /src/grpc-gateway
steps:
- checkout
Expand Down
23 changes: 23 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"dockerFile": "../.circleci/Dockerfile",
"overrideCommand": true,
// Set *default* container specific settings.json values on container create.
"settings": {
"editor.formatOnSave": true,
"terminal.integrated.shell.linux": "/bin/bash",
"go.useGoProxyToCheckForToolUpdates": true,
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go",
"go.toolsGopath": "/go/bin",
"bazel.buildifierExecutable": "/go/bin/buildifier",
"bazel.buildifierFixOnFormat": true,
"bazel.enableCodeLens": true,
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"golang.Go",
"bazelbuild.vscode-bazel",
],
"postCreateCommand": "cd $(mktemp -d) && GO111MODULE=on go get golang.org/x/tools/gopls@latest github.com/bazelbuild/buildtools/buildifier@latest && cd -",
}
23 changes: 22 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ All submissions, including submissions by project members, require review.

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

Great! It should be as simple as this (run from the root of the directory):
#### Using Docker

It should be as simple as this (run from the root of the repository):

```bash
docker run -v $(pwd):/src/grpc-gateway --rm docker.pkg.github.com/grpc-ecosystem/grpc-gateway/build-env:1.15 \
Expand All @@ -40,6 +42,25 @@ docker run -itv $(pwd):/grpc-gateway -w /grpc-gateway --entrypoint /bin/bash --r
You may need to authenticate with GitHub to pull `docker.pkg.github.com/grpc-ecosystem/grpc-gateway/build-env`.
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).

#### Using Visual Studio Code dev containers

This repo contains a `devcontainer.json` configuration that sets up the build environment in a container using
[VS Code dev containers](https://code.visualstudio.com/docs/remote/containers). If you're using the dev container,
you can run the commands directly in your terminal:

```shell
$ make realclean && make examples && make testproto
```

```shell
$ bazel run :gazelle -- update-repos -from_file=go.mod -to_macro=repositories.bzl%go_repositories && \
bazel run :gazelle && \
bazel run :buildifier
```

Note that the above listed docker commands will not work in the dev container, since volume mounts from
nested docker container are not possible.

If this has resulted in some file changes in the repo, please ensure you check those in with your merge request.

### Making a release
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ $(SWAGGER_PLUGIN): $(SWAGGER_PLUGIN_SRC) $(OPENAPIV2_GO)
$(EXAMPLE_SVCSRCS): $(GO_PLUGIN) $(EXAMPLES)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:. $(EXAMPLES)
$(EXAMPLE_DEPSRCS): $(GO_PLUGIN) $(EXAMPLE_DEPS)
mkdir -p $(OUTPUT_DIR)
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:$(OUTPUT_DIR) $(@:.pb.go=.proto)
cp $(OUTPUT_DIR)/$@ $@ || cp $(OUTPUT_DIR)/$@ $@
protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:. $(@:.pb.go=.proto)

$(RUNTIME_TEST_SRCS): $(GO_PLUGIN) $(RUNTIME_TEST_PROTO)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:. $(RUNTIME_TEST_PROTO)
Expand Down
2 changes: 0 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ rules_proto_dependencies()

rules_proto_toolchains()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_go",
sha256 = "7b9bbe3ea1fccb46dcfa6c3f3e29ba7ec740d8733370e21cdc8937467b4a4349",
Expand Down

0 comments on commit e0d4f53

Please sign in to comment.