diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..ff6fbb99 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,5 @@ +# base development image on .NET 7.0 +FROM mcr.microsoft.com/devcontainers/dotnet:0-7.0-bullseye AS build + +# fetch the .NET 6.0 SDK for use in testing +COPY --from=mcr.microsoft.com/dotnet/sdk:6.0 /usr/share/dotnet/shared /usr/share/dotnet/shared \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..dc30419a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,16 @@ +{ + "name": "NRedisStack (.NET)", + + "dockerComposeFile": "docker-compose.yml", + "service": "devcontainer", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "customizations": { + "vscode": { + "extensions": [ + "ms-dotnettools.csharp", + "ms-dotnettools.csdevkit", + "ms-dotnettools.vscodeintellicode-csharp" + ] + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..2af542a2 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,39 @@ +--- +version: "3.8" +services: + devcontainer: + build: + context: . + dockerfile: Dockerfile + volumes: + - ../..:/workspaces:cached + networks: + - redis + command: sleep infinity + environment: + REDIS: "redis-stack-edge:6379" # default targeted Redis version + REDIS__7_2_0: "redis-stack-7.2.0:6379" + REDIS__6_2_6: "redis-stack-6.2.6:6379" + REDIS__edge: "redis-stack-edge:6379" + + redis-stack-7.2.0: + image: redis/redis-stack-server:7.2.0-RC3 + restart: unless-stopped + networks: + - redis + + redis-stack-6.2.6: + image: redis/redis-stack-server:6.2.6-v9 + restart: unless-stopped + networks: + - redis + + redis-stack-edge: + image: redis/redis-stack-server:edge + restart: unless-stopped + networks: + - redis + +networks: + # defines shared network for communicating with Redis + redis: diff --git a/.github/wordlist.txt b/.github/wordlist.txt index 69a237fb..2f52fbd0 100644 --- a/.github/wordlist.txt +++ b/.github/wordlist.txt @@ -1,6 +1,8 @@ cli codecov Codecov +Dev +DevContainer dotnet firsttimersonly github diff --git a/.vscode/settings.json b/.vscode/settings.json index b26a2359..079dbf34 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "dotnet-test-explorer.testArguments": "/p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info", - "dotnet-test-explorer.testProjectPath": "**/*NRedisStack.Tests.csproj" + "dotnet-test-explorer.testProjectPath": "**/*NRedisStack.Tests.csproj", + "dotnet.defaultSolution": "NRedisStack.sln" } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0542bb3a..68c52359 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -38,8 +38,13 @@ "problemMatcher": "$msCompile" }, { - "label": "test", + "label": "test 6.2.6", "dependsOn": [], + "options": { + "env": { + "REDIS": "${env:REDIS__6_2_6}" + } + }, "command": "dotnet", "type": "process", "args": [ @@ -49,6 +54,54 @@ "/p:CoverletOutputFormat=lcov", "/p:CoverletOutput=./lcov.info" ], + "problemMatcher": "$msCompile" + }, + { + "label": "test 7.2.0", + "dependsOn": [], + "options": { + "env": { + "REDIS": "${env:REDIS__7_2_0}" + } + }, + "command": "dotnet", + "type": "process", + "args": [ + "test", + "${workspaceFolder}/tests/NRedisStack.Tests/NRedisStack.Tests.csproj", + "/p:CollectCoverage=true", + "/p:CoverletOutputFormat=lcov", + "/p:CoverletOutput=./lcov.info" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "test edge", + "dependsOn": [], + "options": { + "env": { + "REDIS": "${env:REDIS__edge}" + } + }, + "command": "dotnet", + "type": "process", + "args": [ + "test", + "${workspaceFolder}/tests/NRedisStack.Tests/NRedisStack.Tests.csproj", + "/p:CollectCoverage=true", + "/p:CoverletOutputFormat=lcov", + "/p:CoverletOutput=./lcov.info" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "test all", + "dependsOrder": "sequence", + "dependsOn": [ + "test 6.2.6", + "test 7.2.0", + "test edge" + ], "problemMatcher": "$msCompile", "group": { "kind": "test", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9cb9846a..e3b2a3ba 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,11 +34,67 @@ Here's how to get started with your code contribution: 2. Do the changes in your fork 3. Write your tests -4. Use the `docker run -p 6379:6379 -it redis/redis-stack-server:edge` as your local environment for running the functional tests. -5. Make sure your tests pass using `dotnet test' +4. Use the `docker run -p 6379:6379 -it redis/redis-stack-server:edge` as your local environment for running the functional tests. You can also use Development Container as described below. +5. Make sure your tests pass using `dotnet test` 6. Push your changes to GitHub 7. Open a pull request +## Development Container + +Development Containers are an easy way to define and setup a reproducible development environment by using containers. +NRedisStack provides a [development container environment](https://containers.dev/) that can be used to get running relatively fast without focusing on the different Redis deployments. + +The development container comes packed with .NET 6 and 7, required by the testing suite, as well as the currently supported Redis versions that are run as part of the CI pipeline. + +Development containers are supported in a few [editors](https://containers.dev/supporting#editors) or by using the [`devcontainer-cli` tool](https://github.com/devcontainers/cli). + +This guide explains how to use the existing development container setup for this project. + +### Prerequisites + +Before you start, make sure you have the following installed: + +- [Visual Studio Code](https://code.visualstudio.com/) +- [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code + +### Steps to Use the Existing Development Container Setup + +1. **Clone the Project:** Start by cloning the project's repository to your local machine using Git. + +2. **Install Prerequisites:** Ensure you have Visual Studio Code and the Dev Containers extension installed. + +3. **Open in Development Container:** + + a. Open the cloned project directory using Visual Studio Code. + + b. VS Code should detect the `.devcontainer` folder and the associated configuration files. + + c. You will likely see a notification suggesting reopening the project in a development container: + ![devcontainer notification](./docs/devcontainerNotification.png) + + Click on this notification or press `Ctrl + Shift + P` (or `Cmd + Shift + P` on Mac) and type _"Dev Containers: Reopen in Container"_. Select the suggestion that appears. + + d. Visual Studio Code will build the Docker image according to the configuration and start a container using the specified setup. + +4. **Develop Inside the DevContainer:** + + You're now working within the development container environment. Access extensions, dependencies, and settings specified in `devcontainer.json`. Edit code, use the integrated terminal, and run commands as usual. + +5. **Save and Commit:** + + Changes made within the development container will be saved to your local repository. Use Git within the container to manage changes, create branches, commit, and push code. + +6. **Stop the DevContainer:** + + Close the development container by clicking the "Close Remote Connection" button in the bottom-left corner of the VS Code window. This stops the container while preserving changes. + +7. **Resume Work:** + + Reopen the project in the development container to work on it again using the same steps. + +By using the existing `.devcontainer` setup, you benefit from a consistent development environment tailored to the project's requirements. For specific configuration details or issues, consult the project documentation or ask maintainers for assistance. + + ## Testing Call `dotnet test` to run all tests diff --git a/docs/devcontainerNotification.png b/docs/devcontainerNotification.png new file mode 100644 index 00000000..5bfd86a7 Binary files /dev/null and b/docs/devcontainerNotification.png differ diff --git a/tests/NRedisStack.Tests/RedisFixture.cs b/tests/NRedisStack.Tests/RedisFixture.cs index 8ae470f2..f971d04f 100644 --- a/tests/NRedisStack.Tests/RedisFixture.cs +++ b/tests/NRedisStack.Tests/RedisFixture.cs @@ -4,17 +4,18 @@ namespace NRedisStack.Tests { public class RedisFixture : IDisposable { - - - // Set the enviroment variable to specify your own alternet host and port: - string redis = Environment.GetEnvironmentVariable("REDIS") ?? "localhost:6379"; - public RedisFixture() => Redis = ConnectionMultiplexer.Connect($"{redis}"); + public RedisFixture() + { + // Set the enviroment variable to specify your own alternet host and port: + var redisConnectionString = Environment.GetEnvironmentVariable("REDIS") ?? "localhost:6379"; + Redis = ConnectionMultiplexer.Connect(redisConnectionString); + } public void Dispose() { Redis.Close(); } - public ConnectionMultiplexer Redis { get; private set; } + public ConnectionMultiplexer Redis { get; } } } \ No newline at end of file