From e0d4f5312c353f875b5dada717e4e2e33ce971d4 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Thu, 24 Sep 2020 10:39:24 +0100 Subject: [PATCH] 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. --- .bazelversion | 1 + .circleci/Dockerfile | 4 ++++ .circleci/config.yml | 6 ++---- .devcontainer/devcontainer.json | 23 +++++++++++++++++++++++ CONTRIBUTING.md | 23 ++++++++++++++++++++++- Makefile | 4 +--- WORKSPACE | 2 -- 7 files changed, 53 insertions(+), 10 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 4fdce4f7e02..1136d19526b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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 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 331f60dd904..b58a1d1c0a8 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/WORKSPACE b/WORKSPACE index e1dc4ffed8e..1dcbe22b77b 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 = "7b9bbe3ea1fccb46dcfa6c3f3e29ba7ec740d8733370e21cdc8937467b4a4349",