From 502e33fd6630650a7179656031737a0b468fb652 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst Date: Wed, 23 Sep 2020 11:48:29 +0000 Subject: [PATCH] Add devcontainer.json 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. --- .bazelversion | 1 + .circleci/Dockerfile | 4 ++++ .circleci/config.yml | 9 +++------ .devcontainer/devcontainer.json | 23 +++++++++++++++++++++++ CONTRIBUTING.md | 23 ++++++++++++++++++++++- Makefile | 4 +--- WORKSPACE | 2 -- 7 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 .bazelversion create mode 100644 .devcontainer/devcontainer.json diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000000..1545d966571 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +3.5.0 diff --git a/.circleci/Dockerfile b/.circleci/Dockerfile index 41abfd204c3..9f5bf320944 100644 --- a/.circleci/Dockerfile +++ b/.circleci/Dockerfile @@ -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 \ diff --git a/.circleci/config.yml b/.circleci/config.yml index eb0d50e7150..3836b4c791d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -80,8 +80,7 @@ jobs: - generate - run: git diff --exit-code lint: - docker: - - image: golang:1.15 + executor: build-env working_directory: /src/grpc-gateway steps: - checkout @@ -110,8 +109,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 @@ -162,8 +160,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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000000..5c8a07c69c5 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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 -", +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e75ba9bd44d..31e60f2baa2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 \ @@ -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 diff --git a/Makefile b/Makefile index fc1f76938ac..7e122e1d618 100644 --- a/Makefile +++ b/Makefile @@ -166,9 +166,7 @@ $(OPENAPI_PLUGIN): $(OPENAPI_PLUGIN_SRC) $(OPENAPIV2_GO) $(EXAMPLE_SVCSRCS): $(GO_PLUGIN) $(GO_GRPC_PLUGIN) $(EXAMPLES) 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) $(EXAMPLE_DEPSRCS): $(GO_PLUGIN) $(GO_GRPC_PLUGIN) $(EXAMPLE_DEPS) - mkdir -p $(OUTPUT_DIR) - 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) - cp $(OUTPUT_DIR)/$@ $@ || cp $(OUTPUT_DIR)/$@ $@ + 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) $(RUNTIME_TEST_SRCS): $(GO_PLUGIN) $(GO_GRPC_PLUGIN) $(RUNTIME_TEST_PROTO) 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) diff --git a/WORKSPACE b/WORKSPACE index 1d74c7b9e8d..46da40becc2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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 = "b725e6497741d7fc2d55fcc29a276627d10e43fa5d0bb692692890ae30d98d00",