diff --git a/.devcontainer/Dockerfile.dev b/.devcontainer/Dockerfile.dev new file mode 100644 index 0000000000..6eec367f88 --- /dev/null +++ b/.devcontainer/Dockerfile.dev @@ -0,0 +1,28 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +FROM otel/cpp_format_tools + +ARG GRPC_VERSION=v1.55.0 +ARG PROTOBUF_VERSION=23.4 +ARG ABSEIL_CPP_VERSION=20240116.1 + +ENV PROTOBUF_VERSION=${PROTOBUF_VERSION} +ENV ABSEIL_CPP_VERSION=${ABSEIL_CPP_VERSION} + +COPY ci /opt/ci + +RUN apt update && apt install -y wget \ + ninja-build \ + libcurl4-openssl-dev \ + markdownlint + +RUN cd /opt/ci && bash setup_cmake.sh +RUN cd /opt/ci && bash setup_ci_environment.sh +RUN cd /opt && bash ci/setup_googletest.sh \ + && bash ci/setup_grpc.sh -r ${GRPC_VERSION} + +ADD https://github.com/bazelbuild/bazelisk/releases/download/v1.22.1/bazelisk-linux-amd64 /usr/local/bin + +RUN git config --global core.autocrlf input \ + && chmod +x /usr/local/bin/bazelisk-linux-amd64 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..8615497085 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.162.0/containers/javascript-node +{ + "name": "opentelemetry-cpp", + "build": { + "context": "..", + "dockerfile": "Dockerfile.dev", + "args": { + "GRPC_VERSION": "v1.55.0", + "PROTOBUF_VERSION": "23.4", + "ABSEIL_CPP_VERSION":"20240116.1" + } + }, + "settings": { + "terminal.integrated.shell.linux": "/bin/sh" + }, + "extensions": [ + "ms-vscode.cpptools", + "ms-azuretools.vscode-docker", + "ms-vscode.cpptools-extension-pack" + ], + + "remoteUser": "root" +} diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d907392962..5cfb4cb898 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,3 +6,8 @@ updates: interval: "daily" labels: - "GHA" + + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: daily diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 95b4e226f8..bf837f6bd1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,6 +60,91 @@ bazel build //examples/simple:example_simple bazel-bin/examples/simple/example_simple ``` +### DevContainer Setup for Project + +This guide provides instructions on how to set up and use the development +container (`devcontainer`) environment to streamline testing and development +for this project. With the DevContainer, you can work in a consistent environment +configured with all the necessary dependencies and tools. + +#### Prerequisites + +Before getting started, ensure you have the following installed: + +* **Docker**: DevContainers require Docker for containerization. +* **Visual Studio Code (VSCode)** with the **Remote - Containers** extension. + +#### Getting Started + +* **Open the Project in DevContainer**: + + Open the project in VSCode. When prompted to "Reopen in Container," select + this option. If you’re not prompted, you can manually open the container by + selecting **Remote-Containers: Reopen in Container** from the command palette + (`F1` or `Ctrl+Shift+P`). + +* **Container Setup**: + + The DevContainer environment will automatically build based on the configuration + files provided (e.g., `.devcontainer/devcontainer.json`). This setup will install + required dependencies, tools, and environment variables needed for the project. + +#### Available Commands + +Once inside the DevContainer, you can use the following commands to run tests +and CI workflows. + +##### 1. Run Tests with Bazelisk + +To run tests with Bazelisk using specific compilation options, use: + +```bash +bazelisk-linux-amd64 test --copt=-DENABLE_LOGS_PREVIEW +--test_output=errors --cache_test_results=no --copt=-DENABLE_TEST //exporters/otlp/... +``` + +###### Command Breakdown + +* `--copt=-DENABLE_LOGS_PREVIEW`: Enables preview logs. +* `--test_output=errors`: Shows only the errors in the test output. +* `--cache_test_results=no`: Forces Bazel to re-run tests without caching. +* `--copt=-DENABLE_TEST`: Enables testing capabilities for the target code. +* `//exporters/otlp/...`: Specifies the test target path. + +##### 2. Run CI Script + +You can also run the CI script provided to perform testing with the +following command as an +example: + +```bash +bash ci/do_ci.sh cmake.exporter.otprotocol.test +``` + +This command initiates the CI pipeline, executing tests specifically for the +**cmake.exporter.otprotocol** module. + +#### Troubleshooting + +If you encounter issues: + +* **Rebuild the DevContainer**: From the command palette, run + **Remote-Containers: Rebuild Container** to reinitialize the environment. +* **Check Bazelisk and CI Script Logs**: Inspect logs for any configuration or + dependency issues. + +#### Additional Notes + +* You can adjust compiler options (`--copt`) as needed to test additional flags + or enable/disable specific features. +* The test results will be displayed in the terminal within the DevContainer for + easy debugging. + +#### Resources + +* **Bazelisk Documentation**: [https://github.com/bazelbuild/bazelisk](https://github.com/bazelbuild/bazelisk) +* **VSCode DevContainer Documentation**: [https://code.visualstudio.com/docs/remote/containers](https://code.visualstudio.com/docs/remote/containers) + ## Pull Requests ### How to Send Pull Requests diff --git a/ci/README.md b/ci/README.md index 65bea032d7..39d9a19acc 100644 --- a/ci/README.md +++ b/ci/README.md @@ -1,7 +1,10 @@ # Building and running tests as a developer CI tests can be run on docker by invoking the script `./ci/run_docker.sh -./ci/do_ci.sh {TARGET}` where the targets are: +./ci/do_ci.sh {TARGET}`or inside +[devcontainer](../CONTRIBUTING.md#devcontainer-setup-for-project) +by invoking the script +`./ci/do_ci.sh {TARGET}` where the targets are: * `cmake.test`: build cmake targets and run tests. * `cmake.maintainer.test`: build with cmake and test, in maintainer mode. diff --git a/ci/run_docker.sh b/ci/run_docker.sh index d3b78c3af9..1f499e935e 100755 --- a/ci/run_docker.sh +++ b/ci/run_docker.sh @@ -7,7 +7,7 @@ set -e BUILD_IMAGE=opentelemetry-cpp-build docker image inspect "$BUILD_IMAGE" &> /dev/null || { - docker build -t "$BUILD_IMAGE" ci + docker build -t "$BUILD_IMAGE" -f .devcontainer/Dockerfile.dev . } if [[ $# -ge 1 ]]; then