Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ cp .env.example .env
docker compose up
```

In another terminal, set up the database:
In another terminal, install JS dependencies and set up the databases:

```sh
# install node deps
docker compose exec web npm install

# create dev db, load schema, and seed
docker compose exec web bin/rails db:setup

# OR to drop an existing db first
# docker compose exec web bin/rails db:reset
# create test db, load schema, skip seeding
docker compose exec -e RAILS_ENV=test web bin/rails db:create db:schema:load
```

Open <http://localhost:3000>.
Expand Down Expand Up @@ -90,50 +94,48 @@ docker compose exec web bundle exec rspec

Docker and devcontainer environments can only run Cypress **headlessly** (no GUI). For the interactive runner, you need to run Cypress from your host machine.

#### Headless (Docker or devcontainer)
#### Inside a container (headless only)

Boots a test server and runs the full suite:
Cypress can only run headlessly inside a container — no GUI.

```sh
# from a devcontainer shell
npm run test:e2e

# from the host, against the running dev stack
docker compose exec web npm run test:e2e
```
Comment thread
jxjj marked this conversation as resolved.

#### Interactive (from host)
#### From Host (headless or interactive)

Runs Cypress from your host machine against a test Rails server in a throwaway container. The dev stack can keep running — the test server lives on a separate port so there's no conflict and no need to flip `RAILS_ENV`.

**One-time host setup:**

1. Install [Node.js](https://nodejs.org/) (version 22).
2. Install dependencies locally:
2. Install JS deps on the host:

```sh
npm install
```

**Each run:**
**Each run:** open two terminals.

1. Put Rails in test mode. In your `.env`, change:
Terminal 1 — start the test Rails server (container port 3000 → host 3001):

Comment thread
jxjj marked this conversation as resolved.
```sh
RAILS_ENV=test
```

(`USER_LOOKUP_SKELETON=1` is already the default.)

2. Start the stack:

```sh
docker compose up
```

3. In another terminal on your host, open Cypress:
```sh
docker compose run --rm -p 3001:3000 web npm run test:e2e:server
```

```sh
npx cypress open
```
Terminal 2 — run Cypress, pointed at port 3001:

Cypress will connect to the Rails server at <http://localhost:3000>.
```sh
# headless
npx cypress run --config baseUrl=http://localhost:3001

When you're done, set `RAILS_ENV=development` back in `.env` and restart the stack.
# interactive GUI
npx cypress open --config baseUrl=http://localhost:3001
```

## Deployment

Expand Down
12 changes: 8 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ services:
- CMD
- mysqladmin
- ping
- "-p${DB_PASSWORD}"
retries: 3
- "--password=${DB_PASSWORD}"
interval: 2s
timeout: 5s
retries: 10
start_period: 30s
volumes:
- db-data:/var/lib/mysql
ports:
- "3306:3306"
- "${FORWARD_DB_PORT:-3306}:3306"

web:
build:
Expand All @@ -33,18 +35,20 @@ services:
volumes:
- .:/app
- bundle_cache:/app/vendor/bundle
- cypress_cache:/home/${APP_USER:-vscode}/.cache/Cypress
env_file:
- .env
environment:
# Override .env's DB_HOST so the container connects to the db service, not localhost
DB_HOST: db
DB_PORT: 3306
ports:
- "3000:3000"
- "${APP_PORT:-3000}:3000"
depends_on:
db:
condition: service_healthy

volumes:
db-data:
bundle_cache:
cypress_cache:
11 changes: 5 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ ARG USER_UID=1000
ARG USER_GID=1000
ARG SKIP_BUNDLE_INSTALL=false

EXPOSE 3000

# Enable repositories and module streams
RUN dnf install -y dnf-plugins-core && \
dnf config-manager --set-enabled crb && \
Expand Down Expand Up @@ -50,8 +48,6 @@ RUN dnf groupinstall -y "Development Tools" && \
net-tools \
nodejs \
npm \
ruby \
ruby-devel \
libffi-devel \
git-credential-libsecret \
libyaml \
Expand All @@ -73,9 +69,9 @@ RUN dnf install -y epel-release && \
dnf clean all && \
rm -rf /var/cache/dnf

# Install Ruby from source
# Install Ruby from source via ruby-build (installed into /usr/local)
RUN git clone https://github.com/rbenv/ruby-build.git /tmp/ruby-build && \
/tmp/ruby-build/install.sh chdir=/tmp/ruby-build && \
PREFIX=/usr/local /tmp/ruby-build/install.sh && \
RUBY_CFLAGS="-std=gnu99" ruby-build ${RUBY_VERSION} /usr/local && \
rm -rf /tmp/ruby-build

Expand Down Expand Up @@ -119,6 +115,9 @@ RUN mkdir -p $APP_HOME && \
# Switch to non-root user
USER ${USERNAME}

# Pre-create Cypress cache dir so the named volume inherits vscode ownership
RUN mkdir -p /home/${USERNAME}/.cache/Cypress

# Copy Gemfile for bundle install
COPY --chown=${USERNAME}:${USERNAME} Gemfile Gemfile.lock ./

Expand Down
Loading
Loading