Skip to content

Instantly share code, notes, and snippets.

@phawk

phawk/Dockerfile Secret

Created June 10, 2025 08:41
Show Gist options
  • Select an option

  • Save phawk/d6b03f56e033df4af01b2dbe05d53212 to your computer and use it in GitHub Desktop.

Select an option

Save phawk/d6b03f56e033df4af01b2dbe05d53212 to your computer and use it in GitHub Desktop.
Cursor background agent setup
# Use official Ruby 3.3.4 image as base
FROM ruby:3.3.4-bullseye
# Set environment variables
ENV RAILS_ENV=development
ENV RACK_ENV=development
ENV NODE_VERSION=16.14.2
ENV YARN_VERSION=1.22.19
# Set timezone to Europe/London
ENV TZ=Europe/London
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Install system dependencies and development tools
RUN apt-get update -qq && \
apt-get install -yqq \
build-essential \
libpq-dev \
libcurl4-openssl-dev \
curl \
gnupg2 \
lsb-release \
wget \
git \
vim \
postgresql \
postgresql-contrib \
redis-server \
sudo \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Set up PostgreSQL APT repository and install pgvector
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
echo "deb https://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
apt-get update -qq && \
apt-get install -yqq postgresql-13-pgvector && \
rm -rf /var/lib/apt/lists/*
# Install Node.js 16.14.2
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -y nodejs
# Install Yarn
RUN npm install -g yarn@$YARN_VERSION
# Install Bundler
RUN gem install bundler
# Create a non-root user
RUN useradd -m -s /bin/bash ubuntu && \
echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Fix gem installation permissions for ubuntu user
RUN chown -R ubuntu:ubuntu /usr/local/bundle && \
mkdir -p /home/ubuntu/.gem && \
chown -R ubuntu:ubuntu /home/ubuntu/.gem
# Set up PostgreSQL for the user
RUN service postgresql start && \
sudo -u postgres createuser --superuser ubuntu && \
sudo -u postgres createdb rapid_ruby_development && \
sudo -u postgres createdb rapid_ruby_test && \
# TODO: Uncomment this once we need pgvector
# sudo -u postgres psql -d rapid_ruby_development -c "CREATE EXTENSION IF NOT EXISTS vector;" && \
# sudo -u postgres psql -d rapid_ruby_test -c "CREATE EXTENSION IF NOT EXISTS vector;" && \
service postgresql stop
# Switch to the ubuntu user and set working directory to home
USER ubuntu
WORKDIR /home/ubuntu
# Create a startup script that starts services
RUN echo '#!/bin/bash' > /home/ubuntu/start-services.sh && \
echo 'sudo service postgresql start' >> /home/ubuntu/start-services.sh && \
echo 'sudo service redis-server start' >> /home/ubuntu/start-services.sh && \
echo 'exec "$@"' >> /home/ubuntu/start-services.sh && \
chmod +x /home/ubuntu/start-services.sh
# Default command to start services and keep container running
CMD ["/home/ubuntu/start-services.sh", "tail", "-f", "/dev/null"]
{
"build": {
"context": ".",
"dockerfile": "Dockerfile"
},
"install": ".cursor/setup.sh",
"terminals": [
{
"name": "rails-server",
"command": "bin/rails server -b 0.0.0.0 -p 3000",
"description": "Runs the Rails development server on port 3000"
},
{
"name": "tailwind-watch",
"command": "bundle exec tailwindcss:watch",
"description": "Watches and compiles Tailwind CSS changes"
},
{
"name": "solid_queue",
"command": "bundle exec solid_queue:start",
"description": "Runs the SolidQueue background job processor"
},
{
"name": "rails-console",
"command": "bundle exec rails console",
"description": "Runs the Rails console"
},
{
"name": "rspec",
"command": "bundle exec rspec",
"description": "Runs the RSpec tests"
}
]
}
# .cursor/setup.sh
# Set the Rails master key
export RAILS_MASTER_KEY=$RAPID_RUBY_MASTER_KEY
echo $RAPID_RUBY_MASTER_KEY > config/master.key
# Install dependencies
gem install bundler
bundle install
# Precompile assets
bundle exec rails assets:precompile || true
# Startup services
/home/ubuntu/start-services.sh
# Migrate database
bundle exec rails db:migrate
bundle exec rails db:migrate RAILS_ENV=test
# Assume unchange files in git for certain folders
git update-index --assume-unchanged .vscode/settings.json || true
git update-index --assume-unchanged .vscode/tasks.json || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment