diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..54fd96f5 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,42 @@ +# Use Ruby 3.3 as specified in the test matrix +FROM ruby:3.3 + +# Install dependencies +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends \ + git \ + build-essential \ + libssl-dev \ + libreadline-dev \ + zlib1g-dev \ + redis-tools \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Create a non-root user +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 \ + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +# Set the default user +USER $USERNAME + +# Set working directory +WORKDIR /workspaces/resque-scheduler + +# Install bundler +RUN gem install bundler + +# Set environment variables for the test matrix configuration +ENV REDIS_VERSION=latest +ENV RESQUE=master +ENV RUFUS_SCHEDULER=3.6 +ENV RACK_VERSION=3 +ENV COVERAGE=1 diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 00000000..f6fed9af --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,111 @@ +# Dev Container for Resque Scheduler + +This dev container is configured to match the GitHub Actions test matrix with the following configuration: + +- **Ruby version**: 3.3 +- **Resque version**: master (from git) +- **Rufus-scheduler**: 3.6 +- **Redis version**: latest +- **Rack version**: 3 + +## Getting Started + +1. Open this repository in VS Code +2. When prompted, click "Reopen in Container" (or run the command "Dev Containers: Reopen in Container") +3. Wait for the container to build and start +4. Once inside the container, dependencies will be automatically installed via `bundle install` + +## Running Tests + +To run the full test suite: + +```bash +bundle exec rake +``` + +To run a specific test file: + +```bash +bundle exec ruby test/scheduler_test.rb +``` + +To run tests with verbose output: + +```bash +VERBOSE=1 bundle exec rake +``` + +To run tests matching a specific pattern: + +```bash +PATTERN='test/scheduler_*_test.rb' bundle exec rake +``` + +## Testing with Different Configurations + +If you want to test with different versions, you can modify the environment variables and reinstall dependencies: + +```bash +# Example: Test with rufus-scheduler 3.4 +export RUFUS_SCHEDULER=3.4 +bundle install + +# Run tests +bundle exec rake + +# Reset to original configuration +export RUFUS_SCHEDULER=3.6 +bundle install +``` + +## Available Environment Variables + +The following environment variables are set to match the test matrix: + +- `REDIS_VERSION`: latest +- `RESQUE`: master +- `RUFUS_SCHEDULER`: 3.6 +- `RACK_VERSION`: 3 +- `COVERAGE`: 1 + +## Services + +### Redis +Redis is available at `redis://redis:6379` or via `localhost:6379` from within the container. + +To connect to Redis CLI: + +```bash +redis-cli -h redis +``` + +## Troubleshooting + +### Bundle Install Issues + +If you encounter issues with bundle install, try: + +```bash +bundle config set --local build.redis --with-cflags="-Wno-error=implicit-function-declaration" +bundle install +``` + +### Redis Connection Issues + +Make sure Redis is running: + +```bash +redis-cli -h redis ping +``` + +Should return `PONG`. + +### Rebuilding the Container + +If you need to rebuild the container from scratch: + +1. Run "Dev Containers: Rebuild Container" from the command palette +2. Or delete the container and volume manually: + ```bash + docker-compose -f .devcontainer/docker-compose.yml down -v + ``` diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..b5396c0c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,41 @@ +{ + "name": "Resque Scheduler Dev Container", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/resque-scheduler", + + // Features to add to the dev container + "features": { + "ghcr.io/devcontainers/features/git:1": {} + }, + + // Configure tool-specific properties + "customizations": { + "vscode": { + "extensions": [ + "rebornix.ruby" + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "bash" + } + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally + "forwardPorts": [6379], + + // Use 'postCreateCommand' to run commands after the container is created + "postCreateCommand": "bundle install", + + // Set environment variables for the test matrix + "containerEnv": { + "REDIS_VERSION": "latest", + "RESQUE": "master", + "RUFUS_SCHEDULER": "3.6", + "RACK_VERSION": "3", + "COVERAGE": "1" + }, + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root + "remoteUser": "vscode" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..ea7e0cf6 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,31 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - ../..:/workspaces:cached + working_dir: /workspaces/resque-scheduler + command: sleep infinity + environment: + REDIS_VERSION: "latest" + RESQUE: "master" + RUFUS_SCHEDULER: "3.6" + RACK_VERSION: "3" + COVERAGE: "1" + REDIS_URL: "redis://redis:6379" + depends_on: + - redis + # Runs app on the same network as the redis container, allows "forwardPorts" in devcontainer.json function + network_mode: service:redis + + redis: + image: redis:latest + restart: unless-stopped + ports: + - "6379:6379" + volumes: + - redis-data:/data + +volumes: + redis-data: