diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..b6a250e --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,62 @@ +# Use a Ruby image >= 3.1, as required by some dependencies like recent nokogiri +FROM ruby:3.2-slim-bookworm + +# Prevent interactive prompts from apt +ENV DEBIAN_FRONTEND=noninteractive + +# Install system dependencies required for building gems with native extensions +# and for general development. +# - build-essential: For compiling native extensions +# - git: For cloning repos if needed, although VS Code handles the main clone +# - curl, wget: Useful general tools +# - libxml2-dev, libxslt1-dev: Needed by nokogiri gem +# - zlib1g-dev: Needed by many gems +# - sqlite3, libsqlite3-dev: Needed by some gems that might be transitively included +# - libssl-dev: Needed for secure connections, potentially by some gems +# - pkg-config: Build helper +# - make: Used by the Makefile in the repo +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + git \ + curl \ + wget \ + libxml2-dev \ + libxslt1-dev \ + zlib1g-dev \ + sqlite3 \ + libsqlite3-dev \ + libssl-dev \ + pkg-config \ + make \ + zsh \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + + +# (Optional but Recommended) Create a non-root user for development +# This matches the default user setup by Dev Containers 'automatic' creation +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # Add the new user to the sudo group to allow them to run commands with sudo + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(ALL\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + && rm -rf /var/lib/apt/lists/* + +# Set Zsh as the default shell for the non-root user +# Needs to be run as root, after the user is created and zsh is installed +RUN chsh -s $(which zsh) ${USERNAME} + +# Set the default working directory for subsequent commands and where the project code will be mounted +WORKDIR /workspaces + +# Switch to the non-root user +USER $USERNAME + +# The project code will be mounted into /workspaces by Dev Containers. +# Dependencies will be installed via postCreateCommand in devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..be25f55 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,53 @@ +// .devcontainer/devcontainer.json +{ + "name": "Fluent Plugin Datadog Dev", // A friendly name + // Specify the path to the custom Dockerfile + "build": { + "dockerfile": "Dockerfile" + }, + // Use the non-root user created in the Dockerfile + "remoteUser": "vscode", + // Set the workspace folder inside the container + "workspaceFolder": "/workspaces/fluent-plugin-datadog", + // Command to run after the container is created and the workspace is mounted. + // This installs the gem dependencies using Bundler. + "postCreateCommand": "bundle install && sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\"", + // Forward ports that might be useful (e.g., for testing Fluentd) + // Fluentd's default forward port is 24224. The repo's docker-compose also uses this. + "forwardPorts": [ + 24224 + ], + // Configuration specific to VS Code + "customizations": { + "vscode": { + "settings": { + // Optional: Configure Ruby environment settings if needed + "ruby.useBundler": true, + "ruby.lint": { + "rubocop": true + }, + "ruby.format": "rubocop", + // Add other Ruby or general settings here + // Configure VS Code's integrated terminal to use Zsh + "terminal.integrated.defaultProfile.linux": "zsh (2)", + "terminal.integrated.profiles.linux": { + "zsh (2)": { + "path": "zsh" + } + } + }, + // Specify VS Code extensions to install automatically + "extensions": [ + "rebornix.ruby", // Official Ruby extension + "bungcip.better-toml", // For TOML config files + "kaiinui.vscode-ruby-test-explorer", // If you want a test explorer UI + "dbaeumer.vscode-eslint", // If there are JS parts or linting + "redhat.vscode-yaml", // For YAML files (like the docker-compose) + "ms-azuretools.vscode-docker" // Useful for working with Docker inside VS Code + // Add any other extensions relevant to your workflow + ] + } + } + // Uncomment to connect as root instead of the remoteUser. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 93071b4..5c07e37 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,10 +14,17 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0 - bundler-cache: true + ruby-version: ${{ matrix.ruby-version }} + + - name: Configure Bundler to exclude development gems + run: bundle config set --local without development + + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + - name: Run tests run: bundle exec rake diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b08c771 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,36 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Fluentd with Plugin", + "type": "Ruby", + "request": "launch", + "program": "/usr/local/bin/bundle", + "args": [ + "exec", + "fluentd", + "-c", + "${workspaceFolder}/test/fluentd-test.conf", + "-p", + "${workspaceFolder}/lib/fluent/plugin" + ], + "cwd": "${workspaceFolder}", + "showDebuggerOutput": true, + "useBundler": true + }, + { + "name": "Debug Rake Tests", + "type": "Ruby", + "request": "launch", + "program": "/usr/local/bin/bundle", + "args": [ + "exec", + "rake", + "test" + ], + "cwd": "${workspaceFolder}", + "showDebuggerOutput": true, + "useBundler": true + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..440595e --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,54 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Install Dependencies", + "type": "shell", + "command": "bundle install", + "group": "build", + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [] + }, + { + "label": "Build Gem", + "type": "shell", + "command": "gem build fluent-plugin-datadog.gemspec", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [], + "dependsOn": ["Install Dependencies"] + }, + { + "label": "Run Tests", + "type": "shell", + "command": "bundle exec rake test", + "group": "test", + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [] + }, + { + "label": "Build and Test", + "dependsOn": [ + "Install Dependencies", + "Build Gem", + "Run Tests" + ], + "group": { + "kind": "build", + "isDefault": false + } + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 55c1fba..d46bc2a 100644 --- a/README.md +++ b/README.md @@ -156,3 +156,11 @@ To build a new version of this plugin and push it to RubyGems: `curl -u https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials`, it will ask for your password. +## Development Environment + +This repository includes the files to run it in a dev container in VS Code. To use it: + +1. Install VS Code and Docker. +2. Open the project in VS Code with the Dev Containers extension. + +VS Code will build and start the container automatically. diff --git a/fluent-plugin-datadog.gemspec b/fluent-plugin-datadog.gemspec index 9acb04d..8840cc4 100644 --- a/fluent-plugin-datadog.gemspec +++ b/fluent-plugin-datadog.gemspec @@ -25,12 +25,14 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "fluentd", [">= 1", "< 2"] spec.add_runtime_dependency "net-http-persistent", '~> 4.0.1' + spec.add_runtime_dependency "rake", "~> 12.0" + spec.add_runtime_dependency "test-unit", "~> 3.1" + spec.add_runtime_dependency "webmock", "~> 3.6.0" spec.add_development_dependency "bundler", "~> 2.1" - spec.add_development_dependency "test-unit", '~> 3.1' - spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "yajl-ruby", "~> 1.2" - spec.add_development_dependency 'webmock', "~> 3.6.0" + spec.add_development_dependency "ruby-debug-ide" + spec.add_development_dependency "debase" spec.metadata = { 'bug_tracker_uri' => 'https://github.com/DataDog/fluent-plugin-datadog/issues',