Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add devcontainer #3123

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .devcontainer/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the same versions in third_party_release?

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
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ updates:
interval: "daily"
labels:
- "GHA"

- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: daily
85 changes: 85 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't used DevContainers before, but I imagine it would be possible to do this without relying on VS Code ?

Please correct me if I'm wrong, but I imagine we could simply exec into a running docker container as well and run CI tests from there ?

I would prefer if we not put in instructions that are IDE specific.


#### 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
Expand Down
6 changes: 4 additions & 2 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# 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 tests can be run inside
[devcontainer](../CONTRIBUTING.md#devcontainer-setup-for-project)
by invoking the script
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add a Dockerfile that creates a container with the current codebase and required dependencies to run the CI tests within that container ?

`./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.
Expand Down
Loading