Skip to content

Commit 2211e78

Browse files
Add a devcontainer for developing
1 parent 04f4e01 commit 2211e78

File tree

4 files changed

+225
-0
lines changed

4 files changed

+225
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Use Ruby 3.3 as specified in the test matrix
2+
FROM ruby:3.3
3+
4+
# Install dependencies
5+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6+
&& apt-get -y install --no-install-recommends \
7+
git \
8+
build-essential \
9+
libssl-dev \
10+
libreadline-dev \
11+
zlib1g-dev \
12+
redis-tools \
13+
&& apt-get clean \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Create a non-root user
17+
ARG USERNAME=vscode
18+
ARG USER_UID=1000
19+
ARG USER_GID=$USER_UID
20+
21+
RUN groupadd --gid $USER_GID $USERNAME \
22+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
23+
&& apt-get update \
24+
&& apt-get install -y sudo \
25+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
26+
&& chmod 0440 /etc/sudoers.d/$USERNAME
27+
28+
# Set the default user
29+
USER $USERNAME
30+
31+
# Set working directory
32+
WORKDIR /workspaces/resque-scheduler
33+
34+
# Install bundler
35+
RUN gem install bundler
36+
37+
# Set environment variables for the test matrix configuration
38+
ENV REDIS_VERSION=latest
39+
ENV RESQUE=master
40+
ENV RUFUS_SCHEDULER=3.6
41+
ENV RACK_VERSION=3
42+
ENV COVERAGE=1

.devcontainer/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Dev Container for Resque Scheduler
2+
3+
This dev container is configured to match the GitHub Actions test matrix with the following configuration:
4+
5+
- **Ruby version**: 3.3
6+
- **Resque version**: master (from git)
7+
- **Rufus-scheduler**: 3.6
8+
- **Redis version**: latest
9+
- **Rack version**: 3
10+
11+
## Getting Started
12+
13+
1. Open this repository in VS Code
14+
2. When prompted, click "Reopen in Container" (or run the command "Dev Containers: Reopen in Container")
15+
3. Wait for the container to build and start
16+
4. Once inside the container, dependencies will be automatically installed via `bundle install`
17+
18+
## Running Tests
19+
20+
To run the full test suite:
21+
22+
```bash
23+
bundle exec rake
24+
```
25+
26+
To run a specific test file:
27+
28+
```bash
29+
bundle exec ruby test/scheduler_test.rb
30+
```
31+
32+
To run tests with verbose output:
33+
34+
```bash
35+
VERBOSE=1 bundle exec rake
36+
```
37+
38+
To run tests matching a specific pattern:
39+
40+
```bash
41+
PATTERN='test/scheduler_*_test.rb' bundle exec rake
42+
```
43+
44+
## Testing with Different Configurations
45+
46+
If you want to test with different versions, you can modify the environment variables and reinstall dependencies:
47+
48+
```bash
49+
# Example: Test with rufus-scheduler 3.4
50+
export RUFUS_SCHEDULER=3.4
51+
bundle install
52+
53+
# Run tests
54+
bundle exec rake
55+
56+
# Reset to original configuration
57+
export RUFUS_SCHEDULER=3.6
58+
bundle install
59+
```
60+
61+
## Available Environment Variables
62+
63+
The following environment variables are set to match the test matrix:
64+
65+
- `REDIS_VERSION`: latest
66+
- `RESQUE`: master
67+
- `RUFUS_SCHEDULER`: 3.6
68+
- `RACK_VERSION`: 3
69+
- `COVERAGE`: 1
70+
71+
## Services
72+
73+
### Redis
74+
Redis is available at `redis://redis:6379` or via `localhost:6379` from within the container.
75+
76+
To connect to Redis CLI:
77+
78+
```bash
79+
redis-cli -h redis
80+
```
81+
82+
## Troubleshooting
83+
84+
### Bundle Install Issues
85+
86+
If you encounter issues with bundle install, try:
87+
88+
```bash
89+
bundle config set --local build.redis --with-cflags="-Wno-error=implicit-function-declaration"
90+
bundle install
91+
```
92+
93+
### Redis Connection Issues
94+
95+
Make sure Redis is running:
96+
97+
```bash
98+
redis-cli -h redis ping
99+
```
100+
101+
Should return `PONG`.
102+
103+
### Rebuilding the Container
104+
105+
If you need to rebuild the container from scratch:
106+
107+
1. Run "Dev Containers: Rebuild Container" from the command palette
108+
2. Or delete the container and volume manually:
109+
```bash
110+
docker-compose -f .devcontainer/docker-compose.yml down -v
111+
```

.devcontainer/devcontainer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "Resque Scheduler Dev Container",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspaces/resque-scheduler",
6+
7+
// Features to add to the dev container
8+
"features": {
9+
"ghcr.io/devcontainers/features/git:1": {}
10+
},
11+
12+
// Configure tool-specific properties
13+
"customizations": {
14+
"vscode": {
15+
"extensions": [
16+
"rebornix.ruby"
17+
],
18+
"settings": {
19+
"terminal.integrated.defaultProfile.linux": "bash"
20+
}
21+
}
22+
},
23+
24+
// Use 'forwardPorts' to make a list of ports inside the container available locally
25+
"forwardPorts": [6379],
26+
27+
// Use 'postCreateCommand' to run commands after the container is created
28+
"postCreateCommand": "bundle install",
29+
30+
// Set environment variables for the test matrix
31+
"containerEnv": {
32+
"REDIS_VERSION": "latest",
33+
"RESQUE": "master",
34+
"RUFUS_SCHEDULER": "3.6",
35+
"RACK_VERSION": "3",
36+
"COVERAGE": "1"
37+
},
38+
39+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root
40+
"remoteUser": "vscode"
41+
}

.devcontainer/docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
volumes:
7+
- ../..:/workspaces:cached
8+
working_dir: /workspaces/resque-scheduler
9+
command: sleep infinity
10+
environment:
11+
REDIS_VERSION: "latest"
12+
RESQUE: "master"
13+
RUFUS_SCHEDULER: "3.6"
14+
RACK_VERSION: "3"
15+
COVERAGE: "1"
16+
REDIS_URL: "redis://redis:6379"
17+
depends_on:
18+
- redis
19+
# Runs app on the same network as the redis container, allows "forwardPorts" in devcontainer.json function
20+
network_mode: service:redis
21+
22+
redis:
23+
image: redis:latest
24+
restart: unless-stopped
25+
ports:
26+
- "6379:6379"
27+
volumes:
28+
- redis-data:/data
29+
30+
volumes:
31+
redis-data:

0 commit comments

Comments
 (0)