Skip to content
Draft
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
1 change: 0 additions & 1 deletion .dockerdev/.bashrc

This file was deleted.

7 changes: 0 additions & 7 deletions .dockerdev/.pryrc

This file was deleted.

26 changes: 0 additions & 26 deletions .dockerdev/.psqlrc

This file was deleted.

1 change: 0 additions & 1 deletion .dockerdev/Aptfile

This file was deleted.

67 changes: 0 additions & 67 deletions .dockerdev/Dockerfile

This file was deleted.

25 changes: 3 additions & 22 deletions .github/workflows/system_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,7 @@ jobs:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
CI: true
DATABASE_URL: postgres://postgres:postgres@localhost:5432
CHROME_URL: http://localhost:3000
RAILS_ENV: test
services:
postgres:
image: postgres:13.0
env:
POSTGRES_PASSWORD: postgres
ports: ["5432:5432"]
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:5.0-alpine
ports: ["6379:6379"]
options: --health-cmd="redis-cli ping" --health-interval 1s --health-timeout 3s --health-retries 30
chrome:
image: browserless/chrome:1.31-chrome-stable
ports: ["3000:3000"]
options: -e CONNECTION_TIMEOUT=600000
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
Expand All @@ -42,9 +25,10 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.1
- name: Install PostgreSQL client
- name: Install libsqlite3
run: |
sudo apt-get -yqq install libpq-dev
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Bundle install
run: |
bundle config path /home/runner/bundle
Expand All @@ -69,8 +53,5 @@ jobs:
- name: Run RSpec
run: |
bundle exec rails db:prepare
bundle exec rails g anycable:download --bin-path=./bin
bundle exec rails webpacker:compile
./bin/anycable-go --host "0.0.0.0" &
export CABLE_URL="ws://$(hostname):8080/cable"
bundle exec rspec --tag type:system
17 changes: 3 additions & 14 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@ jobs:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
CI: true
DATABASE_URL: postgres://postgres:postgres@localhost:5432
RAILS_ENV: test
services:
postgres:
image: postgres:11.1
ports: ["5432:5432"]
env:
POSTGRES_PASSWORD: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:5.0-alpine
ports: ["6379:6379"]
options: --health-cmd="redis-cli ping" --health-interval 1s --health-timeout 3s --health-retries 30
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
Expand All @@ -37,9 +25,10 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.1
- name: Install PostgreSQL client
- name: Install libsqlite3
run: |
sudo apt-get -yqq install libpq-dev
sudo apt-get update
sudo apt-get install libsqlite3-dev
- name: Bundle install
run: |
bundle config path /home/runner/bundle
Expand Down
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ ruby '3.0.1'

gem 'rails', '~> 6.1'
gem 'webpacker', '6.0.0.beta.6'
gem 'pg', '~> 1.0'
gem 'sqlite3', '~> 1.4'
gem 'puma', '~> 4.1'
gem 'redis', '~> 4.0'
gem 'anycable', '> 1.0.99'
gem 'anycable-rails', '> 1.0.99'

Expand All @@ -21,6 +20,10 @@ group :development, :test do
gem 'pry-byebug'
gem 'pry-rails'
gem 'rspec-rails', '~> 4.0.0'

# Rack-based AnyCable server implementation
gem 'anycable-rack-server', '~> 0.4.0'
gem 'msgpack', '~> 1.4'
end

group :development do
Expand Down
15 changes: 11 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ GEM
anycable-core (1.1.0.rc1)
anyway_config (>= 2.1.0)
google-protobuf (>= 3.13)
anycable-rack-server (0.4.0)
anycable (> 1.0.99, < 2.0)
anyway_config (>= 2.1.0)
connection_pool (~> 2.2)
websocket (~> 1.2)
anycable-rails (1.1.0.rc1.1)
actioncable (>= 6)
anycable-core (> 1.0.99, < 2.0)
Expand All @@ -101,6 +106,7 @@ GEM
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
concurrent-ruby (1.1.8)
connection_pool (2.2.5)
crass (1.0.6)
cuprite (0.13)
capybara (>= 2.1, < 4)
Expand Down Expand Up @@ -156,7 +162,6 @@ GEM
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
pg (1.2.3)
procto (0.0.3)
pry (0.13.1)
coderay (~> 1.1)
Expand Down Expand Up @@ -206,7 +211,6 @@ GEM
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.2.5)
regexp_parser (2.1.1)
rexml (3.2.4)
rspec-core (3.10.1)
Expand Down Expand Up @@ -263,6 +267,7 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
standard (1.0.4)
rubocop (= 1.11.0)
rubocop-performance (= 1.10.1)
Expand All @@ -289,6 +294,7 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
websocket (1.2.9)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -301,22 +307,23 @@ PLATFORMS

DEPENDENCIES
anycable (> 1.0.99)
anycable-rack-server (~> 0.4.0)
anycable-rails (> 1.0.99)
bootsnap (>= 1.4.2)
capybara
cuprite
listen
msgpack (~> 1.4)
nanoid
pg (~> 1.0)
pry-byebug
pry-rails
puma (~> 4.1)
rails (~> 6.1)
redis (~> 4.0)
rspec-rails (~> 4.0.0)
rubocop-rails
rubocop-rspec
ruby-next (>= 0.10.0)
sqlite3 (~> 1.4)
standard (~> 1.0)
test-prof
turbo-rails
Expand Down
2 changes: 2 additions & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server: bundle exec rails s -p 3000
assets: bundle exec bin/webpack-dev-server
43 changes: 11 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,38 @@ This repository contains the code for AnyCable Rails demo application and its di

## Installation

This app has a Docker-first configuration based one the [Ruby on Whales post](https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development).
This branch has a minimal number of dependencies to make it easier to run the project locally: SQLite instead of Postgres, no Redis, no Docker.

You need:

- `docker` and `docker-compose` installed.

For MacOS just use [official app](https://docs.docker.com/engine/installation/mac/).

- [`dip`](https://github.com/bibendi/dip) installed.

Run the following command to build images and provision the application:
You need Ruby and NodeJS installed on your local machine (and maybe some common system deps for such gems as nokogiri and sqlite3).

```sh
dip provision
bundle install
yarn install
bin/setup
```

## Running

You can start Rails server along with AnyCable by running:
You can start Rails server by running:

```sh
dip up rails anycable
bundle exec rails s
```

Then go to [http://localhost:3000/](http://localhost:3000/) and see the application in action.

## Debugging

If you want to run Rails server and/or with debugging capabilites, run the following commands:

```sh
# for Rails server
dip rails s

# for AnyCable
dip anycable
```

## Testing

We separate unit and system specs and provide convenient Dip commands to run them:
We use RSpec for testing:

```sh
# only unit tests
dip rspec

# only system tests
dip rspec system
bundle exec rspec
```

**NOTE:** System tests require Chrome browser to be installed on your machine (no other software required).

## Resources

- [Ruby on Whales](https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development)—learn about the Docker development setup used for this application.
- [RuboCoping with legacy](https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard)—this is how we configure RuboCop.
- [Evil Front](https://evilmartians.com/chronicles/evil-front-part-3)—some frontend ideas are borrowed from this post.
- [Ruby Next](https://evilmartians.com/chronicles/ruby-next-make-all-rubies-quack-alike)—we're using the edge Ruby syntax!
Expand Down
1 change: 1 addition & 0 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
require_relative "config/environment"

run Rails.application
Rails.application.load_server
12 changes: 10 additions & 2 deletions config/anycable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ default: &default
rpc_host: "127.0.0.1:50051"
# Whether to enable gRPC level logging or not
log_grpc: false
# Use Redis to broadcast messages to AnyCable server
broadcast_adapter: redis
# Use HTTP adapter for a quick start (since redis gem is not present in the project)
broadcast_adapter: http
# Use the same channel name for WebSocket server, e.g.:
# $ anycable-go --redis-channel="__anycable__"
redis_channel: "__anycable__"

development:
<<: *default
embedded: true
http_broadcast_url: "http://localhost:3000/_anycable_rack_broadcast"

test:
<<: *default
http_broadcast_url: "http://localhost:3023/_anycable_rack_broadcast"

production:
<<: *default
# Use Redis in production
broadcast_adapter: redis
Loading