Skip to content

Commit

Permalink
Use Lando for Development.
Browse files Browse the repository at this point in the history
This significantly improves our startup experience, and has been in use
at Princeton for a while now.
  • Loading branch information
tpendragon committed Oct 19, 2020
1 parent 3b2d5d2 commit fc08f9f
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 271 deletions.
54 changes: 33 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
version: 2.1
jobs:
build:
machine: true
parameters:
gemfile:
description: "Gemfile to run"
Expand All @@ -12,32 +11,42 @@ jobs:
description: "Ruby version"
default: "2.6.5"
type: "string"
docker:
- image: circleci/ruby:<< parameters.ruby >>-node-browsers
environment:
RAILS_ENV: test
- image: postgres:10.6-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_DB: Valkyrie_gem_test
POSTGRES_HOST_AUTH_METHOD: trust
- image: samvera/fcrepo4:4.7.5
environment:
CATALINA_OPTS: "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
JAVA_OPTIONS: "-Djetty.http.port=8988"
- image: samvera/fcrepo4:5.1.0
environment:
CATALINA_OPTS: "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
JAVA_OPTIONS: "-Djetty.http.port=8998 -Dfcrepo.dynamic.jms.port=61618 -Dfcrepo.dynamic.stomp.port=61614"
- image: solr:7.7-alpine
command: bin/solr -cloud -noprompt -f -p 8994
environment:
BUNDLE_GEMFILE: << parameters.gemfile >>
POSTGRES_PORT: 5432
steps:
- checkout
- run:
name: Set ruby version to << parameters.ruby >>
command: |
rvm install << parameters.ruby >>
echo . $(rvm << parameters.ruby >> do rvm env --path) >> $BASH_ENV
- run:
shell: /bin/bash -l
name: Uninstall global Bundler
command: |
rvm use << parameters.ruby >>
rvm gemset use global
gem uninstall bundler -x
echo Uninstalled
name: Wait for solr
command: dockerize -wait tcp://localhost:8994 -timeout 1m
- run:
name: Install Docker Compose
name: Load config into solr
command: |
curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
chmod +x ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
- run:
name: Update bundler
command: gem install bundler -v 1.17.2
cd solr/config
zip -1 -r solr_config.zip ./*
curl -H "Content-type:application/octet-stream" --data-binary @solr_config.zip "http://localhost:8994/solr/admin/configs?action=UPLOAD&name=valkyrie"
curl -H 'Content-type: application/json' http://localhost:8994/api/collections/ -d '{create: {name: valkyrie-core-test, config: valkyrie, numShards: 1}}'
# Install Bundler
- run: gem install bundler -v '~> 2.0'
- restore_cache:
keys:
- bundle-{{ checksum "<< parameters.gemfile >>" }}-{{ checksum "valkyrie.gemspec" }}-<< parameters.ruby >>-6
Expand All @@ -57,9 +66,12 @@ jobs:
- run:
name: Run Rubocop
command: bundle exec rake rubocop
- run:
name: Set up database
command: bundle exec rake db:migrate
- run:
name: Run Specs
command: bundle exec rake docker:spec
command: bundle exec rspec spec
- store_artifacts:
path: coverage
destination: coverage
Expand Down
53 changes: 0 additions & 53 deletions .docker-stack/valkyrie-development/docker-compose.yml

This file was deleted.

53 changes: 0 additions & 53 deletions .docker-stack/valkyrie-test/docker-compose.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: valkyrie
services:
valkyrie_test_solr_7:
type: solr:7
portforward: 8994
core: valkyrie-core-test
config:
dir: solr/config
valkyrie_database:
type: postgres:10
portforward: 5433
valkyrie_fedora_4:
type: compose
app_mount: false
volumes:
fedora4:
services:
image: samvera/fcrepo4:4.7.5
command: /fedora-entrypoint.sh
volumes:
- fedora4:/data
ports:
- 8988:8080
portforward: true
valkyrie_fedora_5:
type: compose
app_mount: false
volumes:
fedora5:
services:
image: samvera/fcrepo4:5.1.0
command: /fedora-entrypoint.sh
volumes:
- fedora5:/data
ports:
- 8998:8080
portforward: true
66 changes: 19 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,53 +252,25 @@ config. If Fedora requires auth, you can also include that in the URL, e.g.:

## Installing a Development environment

### With Docker
The development and test stacks use fully contained virtual volumes and bind all services to different ports,
so they can be running at the same time without issue.

#### External Requirements
* [Docker](https://store.docker.com/search?offering=community&type=edition) version >= 17.09.0

### Dependency Setup (Mac OSX)
1. `brew install docker`
1. `brew install docker-machine`
1. `brew install docker-compose`

### Starting Docker (Mac OSX)
1. `docker-machine create default`
1. `docker-machine start default`
1. `eval "$(docker-machine env)"`

#### Starting the development mode dependencies
1. Start Solr, Fedora, and PostgreSQL with `rake docker:dev:daemon` (or `rake docker:dev:up` in a separate
shell to run them in the foreground)
1. Run `rake db:create db:migrate` to initialize the database
1. Develop!
1. Run `rake docker:dev:down` to stop the server stack
* Development servers maintain data between runs. To clean them out, run `rake docker:dev:clean`

#### To run the test suite with all dependencies in one go
1. `rake docker:spec`

#### To run the test suite manually
1. Start Solr, Fedora, and PostgreSQL with `rake docker:test:daemon` (or `rake docker:test:up` in a separate
shell to run them in the foreground)
1. Run `rake db:create db:migrate` to initialize the database
1. Run the gem's RSpec test suite with `rspec spec` or `rake`
1. Run `rake docker:test:down` to stop the server stack
* The test stack cleans up after itself on exit.

### Without Docker

#### External Requirements
* PostgreSQL with the uuid-ossp extension.
* Note: Enabling uuid-ossp requires database superuser privileges.
* From `psql`: `alter user [username] with superuser;`

#### To run the test suite
1. Start Solr and Fedora servers for testing with `rake server:test`
1. Run `rake db:create` (First time only)
1. Run `rake db:migrate`
For ease of development we use Lando to abstract away some complications of
using Docker containers for development.

### Running Tests

1. Install the latest released > 3.0 version of Lando from [here](https://github.com/lando/lando/releases).
2. `bundle install`
3. `bundle exec rake server:start`
4. `bundle exec rspec spec`

### Cleaning Data

1. `bundle exec rake server:clean`

### Stopping Servers

1. `bundle exec rake server:stop`

You can also run `lando poweroff` from anywhere.

## Acknowledgments

Expand Down
8 changes: 5 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require 'config/database_connection'
require 'active_record'
require 'rubocop/rake_task'
load 'tasks/dev.rake'
load 'tasks/docker.rake'

RSpec::Core::RakeTask.new(:spec)

Expand Down Expand Up @@ -37,8 +36,11 @@ namespace :db do

desc 'Create the database from db/config.yml for the current DATABASE_ENV'
task create: :configure_connection do
database = ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(@config)
database.create
begin
database = ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(@config)
database.create
rescue
end
puts "Database created"
end

Expand Down
13 changes: 3 additions & 10 deletions db/config.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
<% local = File.exist?('/tmp/.s.PGSQL.5432') && File.stat('/tmp/.s.PGSQL.5432').socket? %>
default: &default
adapter: postgresql
encoding: utf8
min_messages: warning
pool: <%= Integer(ENV.fetch("DB_POOL", 5)) %>
reaping_frequency: <%= Integer(ENV.fetch("DB_REAPING_FREQUENCY", 10)) %>
timeout: 5000
<% unless local %>
host: localhost
username: docker
password: d0ck3r
<% end %>
username: postgres
password:

development:
<<: *default
database: Valkyrie_gem_development
<% unless local %>
port: 5433
<% end %>

test:
<<: *default
database: Valkyrie_gem_test
<% unless local %>
port: 5434
<% end %>
port: <%= ENV["POSTGRES_PORT"] || 5433 %>
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
require 'webmock/rspec'
require 'timecop'

SOLR_TEST_URL = "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8984}/solr/blacklight-core-test"
SOLR_TEST_URL = "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8994}/solr/valkyrie-core-test"

ROOT_PATH = Pathname.new(Dir.pwd)
Dir[Pathname.new("./").join("spec", "support", "**", "*.rb")].sort.each { |file| require_relative file.gsub(/^spec\//, "") }
Expand Down
Loading

0 comments on commit fc08f9f

Please sign in to comment.