Skip to content

Commit 3c4abfc

Browse files
PatrickTulskiepetergoldstein
authored andcommitted
Create a devcontainer setup
1 parent 93c59a7 commit 3c4abfc

5 files changed

Lines changed: 183 additions & 0 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM ruby:3.4-bullseye
2+
3+
# Install dependencies
4+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
5+
&& apt-get -y install --no-install-recommends \
6+
build-essential \
7+
git \
8+
libsasl2-dev \
9+
libsasl2-modules \
10+
sasl2-bin \
11+
libevent-dev \
12+
libmemcached-tools \
13+
curl \
14+
procps \
15+
wget \
16+
bash \
17+
&& apt-get clean -y \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Setup non-root user with sudo access
21+
ARG USERNAME=vscode
22+
ARG USER_UID=1000
23+
ARG USER_GID=$USER_UID
24+
25+
RUN groupadd --gid $USER_GID $USERNAME \
26+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
27+
&& apt-get update \
28+
&& apt-get install -y sudo \
29+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
30+
&& chmod 0440 /etc/sudoers.d/$USERNAME
31+
32+
RUN sudo chown -R $USERNAME:$USERNAME /usr/local/bundle
33+
34+
# Install utilities
35+
RUN gem install bundler
36+
37+
WORKDIR /workspace
38+
39+
# Switch to non-root user
40+
USER $USERNAME

.devcontainer/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Dalli Development Container
2+
3+
This directory contains configuration for a development container that provides a consistent environment for working on Dalli.
4+
5+
## Features
6+
7+
- Ruby 3.2 environment with all necessary dependencies
8+
- Memcached 1.6.34 installed with SASL and TLS support, matching the GitHub Actions CI environment
9+
- Configuration for testing, including SASL authentication setup
10+
- VS Code extensions for Ruby development
11+
12+
## Setup Process
13+
14+
When the container is built and started, the following setup occurs:
15+
16+
1. The container is built with necessary dependencies but without memcached
17+
2. The `setup.sh` script runs after the container is created which:
18+
- Installs memcached 1.6.34 using the same script used in GitHub Actions
19+
- Configures SASL authentication for testing
20+
- Sets up environment variables needed for tests
21+
- Installs gem dependencies
22+
23+
## Running Tests
24+
25+
Once the container is running, you can run tests with:
26+
27+
```bash
28+
bundle exec rake test
29+
```
30+
31+
To run specific test files:
32+
33+
```bash
34+
bundle exec ruby -Ilib:test test/path/to/test_file.rb
35+
```
36+
37+
## Troubleshooting
38+
39+
If you encounter issues with tests:
40+
41+
1. Verify memcached is running: `ps aux | grep memcached`
42+
2. Check memcached version: `memcached -h | head -1`
43+
3. Verify SASL is configured: `cat /usr/lib/sasl2/memcached.conf`
44+
4. Try restarting memcached: `sudo service memcached restart`
45+
5. Check logs for any errors: `sudo journalctl -u memcached`
46+
47+
## Port Forwarding
48+
49+
The following memcached ports are forwarded for testing:
50+
- 11211 - Default memcached port
51+
- 11212-11215 - Additional ports used by tests
52+
53+
## Environment Variables
54+
55+
- `RUN_SASL_TESTS=1` - Enables SASL authentication tests

.devcontainer/devcontainer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "Ruby Dalli Development",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspace",
6+
"customizations": {
7+
"vscode": {
8+
"extensions": [
9+
"rebornix.ruby",
10+
"castwide.solargraph",
11+
"kaiwood.endwise",
12+
"misogi.ruby-rubocop"
13+
],
14+
"settings": {
15+
"ruby.useBundler": true,
16+
"ruby.format": "rubocop",
17+
"editor.formatOnSave": true,
18+
"ruby.useLanguageServer": true,
19+
"ruby.lint": {
20+
"rubocop": {
21+
"useBundler": true
22+
}
23+
},
24+
"terminal.integrated.defaultProfile.linux": "bash"
25+
}
26+
}
27+
},
28+
"forwardPorts": [
29+
11211,
30+
11212,
31+
11213,
32+
11214,
33+
11215
34+
],
35+
"postCreateCommand": "chmod +x .devcontainer/setup.sh && .devcontainer/setup.sh",
36+
"waitFor": "postCreateCommand",
37+
"remoteUser": "vscode"
38+
}

.devcontainer/docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
volumes:
9+
- ..:/workspace:cached
10+
command: sleep infinity

.devcontainer/setup.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Setting up Dalli development environment..."
5+
6+
# Install memcached using the script from scripts directory
7+
echo "Installing memcached..."
8+
cd /workspace
9+
export MEMCACHED_VERSION=1.6.34
10+
chmod +x scripts/install_memcached.sh
11+
scripts/install_memcached.sh
12+
13+
# Clean up memcached installation files
14+
echo "Cleaning up memcached installation files..."
15+
rm -f memcached-${MEMCACHED_VERSION}.tar.gz
16+
rm -rf memcached-${MEMCACHED_VERSION}
17+
18+
# Create symlink for memcached-tool if needed
19+
if [ ! -f /usr/local/bin/memcached-tool ]; then
20+
echo "Creating symlink for memcached-tool..."
21+
sudo ln -sf /usr/share/memcached/scripts/memcached-tool /usr/local/bin/memcached-tool
22+
fi
23+
24+
echo "Setting up environment variables..."
25+
# Ensure test environment is properly configured
26+
cat >> ~/.bashrc << EOF
27+
28+
# Dalli test environment
29+
export RUN_SASL_TESTS=1
30+
EOF
31+
32+
# Fix permissions
33+
sudo chown -R vscode:vscode /usr/local/bundle
34+
echo "Installing dependencies..."
35+
cd /workspace
36+
bundle install
37+
38+
echo "Environment setup complete!"
39+
echo "You can now run tests with: bundle exec rake test"
40+
echo "To run a specific test file: bundle exec ruby -Ilib:test test/integration/test_fork.rb"

0 commit comments

Comments
 (0)