Playtime app to learn about different ways to use Elasticsearch with the elasticsearch-ruby
and elasticsearch-rails
gems.
This app will attempt to make several different queries that will query against a couple of simple models and hopefully shed some light on how configure and use Elasticsearch beyond the simplest of queries.
- Post(:title, :body)
- Author(:name, :hometown)
Elasticsearch's ruby client looks for ELASTICSEARCH_URL to specify where to point queries.
This should be set in .env.local
if you're using something other than the default localhost:9200
When we run our test server, the test cluster looks for several other environment variables (see elasticsearch-extensions gem for details). In this app, we leverage
TEST_CLUSTER_PORT (in spec/support/test_es_server.rb)
TEST_CLUSTER_LOGS (in circle.yml)
Note, that even after setting the TEST_CLUSTER_PORT for the test cluster, this does NOT set the proper port for
the Elasticsearch::Client which is automagically hooked to ActiveRecord::Base models - assuming the highest level
integration (include Elasticsearch::Model
). So don't forget to set ELASTICSEARCH_URL for test to match the
lTEST_CLUSTER_PORT (whose default is 9250). Check the .env
and .env.test
files included in this project.
Generated with Raygun.
To run the specs or fire up the server, be sure you have these installed (and running):
- Ruby 2.3 (see .ruby-version).
- PostgreSQL 9.x (
brew install postgresql
) with superuser 'postgres' with no password (createuser -s postgres
). - PhantomJS for Capybara and Javascript testing (
brew install phantomjs
). - Elasticsearch >= 2.0.x (
brew install elasticsearch
and start it up as a service (launchctl
)
After cloning, run ./bin/setup to install missing gems and prepare the database.
Note, rake db:sample_data
loads a small set of data for development. Check out
db/sample_data.rb for details.
To run all Ruby and Javascript specs.
$ ./bin/rake
Note: ./bin/rake
runs the springified version of rake (there's a ./bin/rspec
and ./bin/rails
too). You
can add ./bin
to your PATH too, then you'll always use the springified bins when they exist. See
rails/spring for additional information.
$ foreman start
$ open http://localhost:3000
Because this app is pretty new and mostly playtime, we only have master
and feature branches.
- Branch
master
is auto-deployed to production. - Create feature branches off of
development
using the naming convention(features|chores|bugs)/a-brief-description-######
, where ###### is the tracker id. - Rebase your branch before merging into
development
to produce clean merge bubbles. - Retain merge commits for multi-commit branches when merging into
development
(e.g.git merge --no-ff branchname
). - Craft atomic commits that make sense on their own and can be easily cherry-picked or reverted if necessary.
Generally speaking, follow the Ruby Style Guide. Additionally, these are other guidelines adopted by the team:
Always use double quotes for test/spec descriptions, unless the subject is a class/module.
describe SomeController do
context "when logged in as an admin" do
describe "#some_method" do
it "does some thing"
end
end
end
Coverage for the ruby specs:
$ COVERAGE=true rspec
Code coverage is reported to Code Climate on every CI build so there's a record of trending.
Guard is configured to run ruby and jasmine specs, and also listen for livereload connections.
$ bundle exec guard
$ gem install mailcatcher
$ mailcatcher
$ open http://localhost:1080/
Learn more at mailcatcher.me. And please don't add mailcatcher to the Gemfile.
This project is configured for continuous integration and deployment with CircleCI and Heroku.
Check out circle.yml and bin/deploy.sh for details.
Acceptance and Production are hosted on Heroku under the [email protected] account.
Several common features and operational parameters can be set using environment variables.
Required
SECRET_KEY_BASE
- Secret key base for verfying signed cookies. Should be 30+ random characters and secret!
Optional
HOSTNAME
- Canonical hostname for this application. Other incoming requests will be redirected to this hostname.BASIC_AUTH_PASSWORD
- Enable basic auth with this password.BASIC_AUTH_USER
- Set a basic auth username (not required, password enables basic auth).PORT
- Port to listen on (default: 3000).PUMA_WORKERS
- Number of puma workers to spawn (default: 1).MIN_THREADS
- Minimum threads per worker (default: 8).MAX_THREADS
- Maximum threads per worker (default: 16).DB_POOL
- Number of DB connections per pool (i.e. per worker) (default: MAX_THREADS or 5).
- Heroku for hosting.
- CircleCI for continuous integration and deployment.