Skip to content

Commit 36766e7

Browse files
authored
Merge pull request #6687 from samvera/generate-valk-app
Make generated app use Valkyrie
2 parents 0be827b + 069bb98 commit 36766e7

16 files changed

+312
-96
lines changed

app/models/collection.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
# Provide plain collection model if not defined by the application.
4+
# Needed until Hyrax internals do not assume its existence.
5+
class ::Collection < Hyrax.config.collection_class; end unless '::Collection'.safe_constantize

app/models/file_set.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
# Provide plain file set model if not defined by the application.
4+
# Needed until Hyrax internals do not assume its existence.
5+
class ::FileSet < Hyrax.config.file_set_class; end unless '::FileSet'.safe_constantize

documentation/developing-your-hyrax-based-app.md

+76-59
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ A Hyrax-based application includes lots of dependencies. We provide a [Docker im
2929

3030
You can also try [Running Hyrax-based application in local VM](https://github.com/samvera/hyrax/wiki/Hyrax-Development-Guide#running-hyrax-based-application-in-local-vm) which uses Ubuntu.
3131

32+
During development, running only the dependent services in a container environment may be beneficial. This avoids potential headaches concerning file permissions and eases the use of debugging tools. The application generation instructions below use [Lando](https://lando.dev) to achieve this setup.
33+
3234
This document contains instructions specific to setting up an app with __Hyrax
3335
v5.0.0.rc2__. If you are looking for instructions on installing a different
3436
version, be sure to select the appropriate branch or tag from the drop-down
@@ -44,8 +46,8 @@ Prerequisites are required for both creating a Hyrax\-based app and contributing
4446
Hyrax requires the following software to work:
4547

4648
1. [Solr](http://lucene.apache.org/solr/) version >= 5.x (tested up to 8.11.1, which includes the log4j library update)
47-
1. [Fedora Commons](http://www.fedora-commons.org/) digital repository version >= 4.5.1 (tested up to 4.7.5)
48-
1. A SQL RDBMS (MySQL, PostgreSQL), though **note** that SQLite will be used by default if you're looking to get up and running quickly
49+
1. [Fedora Commons](http://www.fedora-commons.org/) digital repository version >= 4.7.6 (if not using the Valkyrie Postgres adapter)
50+
1. A SQL RDBMS ([PostgreSQL](https://www.postgresql.org) recommended)
4951
1. [Redis](http://redis.io/), a key-value store
5052
1. [ImageMagick](http://www.imagemagick.org/) with JPEG-2000 support
5153
1. [FITS](#characterization) (tested up to version 1.5.0 -- avoid version 1.1.0)
@@ -55,7 +57,12 @@ Hyrax requires the following software to work:
5557
**NOTE: The [Hyrax Development Guide](https://github.com/samvera/hyrax/wiki/Hyrax-Development-Guide) has instructions for installing Solr and Fedora in a development environment.**
5658

5759
### Characterization
60+
#### Servlet FITS
61+
FITS can be run as a web service. This has the benefit of improved performance by avoiding the slow startup time inherent to the local option below.
62+
63+
A container image is available for this purpose: [ghcr.io/samvera/fitsservlet](https://ghcr.io/samvera/fitsservlet)
5864

65+
#### Local FITS
5966
FITS can be installed on OSX using Homebrew by running the command: `brew install fits`
6067

6168
**OR**
@@ -122,34 +129,87 @@ NOTE: [nodejs](https://nodejs.org/en/) is preinstalled on most Mac computers and
122129

123130
NOTE: The steps need to be done in order to create a new Hyrax based app.
124131

132+
### Development Prerequisites
133+
134+
These instructions assume the use of [Lando](https://lando.dev) and [Docker](https://docker.io) to manage the backend services needed by your Hyrax application. Follow the Lando installation instructions before proceeding, or have alternate providers for the services listed in the generated `.lando.yml`:
135+
- Solr
136+
- Postgres
137+
- Redis
138+
- FITS servlet
139+
- Fedora (if not using Postgres)
140+
141+
### Generate the application
142+
125143
Generate a new Rails application using the template.
126144

127-
```
128-
rails _6.1.7.6_ new my_app -m https://raw.githubusercontent.com/samvera/hyrax/hyrax-v5.0.0.rc2/template.rb
145+
```shell
146+
rails _6.1.7.6_ new my_app --database=postgresql -m https://raw.githubusercontent.com/samvera/hyrax/hyrax-v5.0.0.rc2/template.rb
129147
```
130148

131149
Generating a new Rails application using Hyrax's template above takes cares of a number of steps for you, including:
132150

133151
* Adding Hyrax (and any of its dependencies) to your application `Gemfile`, to declare that Hyrax is a dependency of your application
134152
* Running `bundle install`, to install Hyrax and its dependencies
135153
* Running Hyrax's install generator, to add a number of files that Hyrax requires within your Rails app, including e.g. database migrations
154+
155+
### Start Services
156+
157+
Start the background services managed by Lando. The
158+
159+
```shell
160+
cd my_app
161+
lando start
162+
```
163+
164+
### Run Migrations/Seeds
165+
166+
This performs the following actions:
167+
136168
* Loading all of Hyrax's database migrations into your application's database
137-
* Loading Hyrax's default workflows into your application's database
138169
* Create default collection types (e.g. Admin Set, User Collection)
170+
* Loading Hyrax's default workflows into your application's database
171+
172+
```shell
173+
rails db:migrate
174+
rails db:seed
175+
```
139176

140-
### Start servers
177+
**NOTE**: You will want to run these commands the first time this code is deployed to a new environment as well.
141178

142-
To test-drive your new Hyrax application in development mode, spin up the servers that Hyrax needs (Solr, Fedora, and Rails):
179+
This creates the default administrative set -- into which all works will be deposited unless assigned to other administrative sets.
180+
This command also makes sure that Hyrax's built-in workflows are loaded for your application and available for the default administrative set.
181+
182+
### Generate a work type
183+
184+
Using Hyrax requires generating at least one type of repository object, or "work type." Hyrax allows you to generate the work types required in your application by using a Rails generator-based tool. You may generate one or more of these work types.
185+
186+
Pass a (CamelCased) model name to Hyrax's work generator to get started, e.g.:
143187

144188
```
145-
bin/rails hydra:server
189+
rails generate hyrax:work_resource MovingImage
190+
```
191+
192+
If your applications requires your work type to be namespaced, namespaces can be included by adding a slash to the model name which creates a new class called `MovingImage` within the `My` namespace:
193+
194+
```shell
195+
rails generate hyrax:work_resource My/MovingImage
196+
```
197+
198+
You may wish to [customize your work type](https://github.com/samvera/hyrax/wiki/Customizing-your-work-types) now that it's been generated.
199+
200+
### Start Hyrax web server
201+
202+
Test-drive your new Hyrax application in development mode:
203+
204+
```shell
205+
rails s
146206
```
147207

148208
And now you should be able to browse to [localhost:3000](http://localhost:3000/) and see the application.
149209

150210
Notes:
151211
* This web server is purely for development purposes. You will want to use a more fully featured [web server](https://github.com/samvera/hyrax/wiki/Hyrax-Management-Guide#web-server) for production-like environments.
152-
* You have the option to start each of these services individually. More information on [solr_wrapper](https://github.com/cbeer/solr_wrapper) and [fcrepo_wrapper](https://github.com/cbeer/fcrepo_wrapper) will help you set this up. Start rails with `rails s`.
212+
* For a fresh start, the data persisted in Lando can be wiped using `lando destroy`.
153213

154214
### Start background workers
155215

@@ -163,14 +223,10 @@ Many of the services performed by Hyrax are resource intensive, and therefore ar
163223

164224
Hyrax implements these jobs using the Rails [ActiveJob](http://edgeguides.rubyonrails.org/active_job_basics.html) framework, allowing you to choose the message queue system of your choice.
165225

166-
For initial development, it is recommended that you change the default ActiveJob adapter from `:async` to `:inline`. This adapter will execute jobs immediately (in the foreground) as they are received. This can be accomplished by adding the following to your `config/environments/development.rb`
226+
For initial development, it is recommended that you change the default ActiveJob adapter from `:async` to `:inline`. This adapter will execute jobs immediately (in the foreground) as they are received. This can be accomplished by modifying the `.env` file:
167227

168-
```
169-
class Application < Rails::Application
170-
# ...
171-
config.active_job.queue_adapter = :inline
172-
# ...
173-
end
228+
```dotenv
229+
HYRAX_ACTIVE_JOB_QUEUE=inline
174230
```
175231

176232
For testing, it is recommended that you use the [built-in `:test` adapter](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/TestAdapter.html) which stores enqueued and performed jobs, running only those configured to run during test setup. To do this, add the following to `config/environments/test.rb`:
@@ -185,54 +241,15 @@ end
185241

186242
**For production applications** you will want to use a more robust message queue system such as [Sidekiq](http://sidekiq.org/). The Hyrax Development Guide has a detailed walkthrough of [installing and configuring Sidekiq](https://github.com/samvera/hyrax/wiki/Using-Sidekiq-with-Hyrax).
187243

188-
### Create default administrative set
189-
190-
**After** Fedora and Solr are running, create the default administrative set -- into which all works will be deposited unless assigned to other administrative sets -- by running the following command:
191-
192-
```
193-
rails hyrax:default_admin_set:create
194-
```
195-
196-
This command also makes sure that Hyrax's built-in workflows are loaded for your application and available for the default administrative set.
197-
198-
**NOTE**: You will want to run this command the first time this code is deployed to a new environment as well.
199-
200-
### Generate a work type
201-
202-
Using Hyrax requires generating at least one type of repository object, or "work type." Hyrax allows you to generate the work types required in your application by using a Rails generator-based tool. You may generate one or more of these work types.
203-
204-
Pass a (CamelCased) model name to Hyrax's work generator to get started, e.g.:
205-
206-
```
207-
rails generate hyrax:work Work
208-
```
209-
210-
or
211-
212-
```
213-
rails generate hyrax:work MovingImage
214-
```
215-
216-
If your applications requires your work type to be namespaced, namespaces can be included by adding a slash to the model name which creates a new class called `MovingImage` within the `My` namespace:
217-
218-
```
219-
rails generate hyrax:work My/MovingImage
220-
```
221-
222-
You may wish to [customize your work type](https://github.com/samvera/hyrax/wiki/Customizing-your-work-types) now that it's been generated.
223-
224-
### Enable notifications
225-
226-
Hyrax 2+ uses a WebSocket-based user notifications system, which requires Redis. To enable user notifications, make sure that you have configured ActionCable to use Redis as the adapter in your application's `config/cable.yml`. E.g., for the `development` Rails environment:
244+
### Create an Admin User
227245

246+
To access all of Hyrax's features you must be signed in as a user in the `admin` role. The default role management system uses the `config/role_map.yml` file to assign users to roles. For example:
228247
```yaml
229248
development:
230-
adapter: redis
231-
url: redis://localhost:6379
249+
admin:
250+
232251
```
233252
234-
Note that the Hyrax Management Guide contains additional information on [how to configure ActionCable in production environments](https://github.com/samvera/hyrax/wiki/Hyrax-Management-Guide#notifications).
235-
236253
## Managing a Hyrax-based app
237254
238255
The [Hyrax Management Guide](https://github.com/samvera/hyrax/wiki/Hyrax-Management-Guide) provides tips for how to manage, customize, and enhance your Hyrax application, including guidance specific to:

lib/generators/hyrax/config_generator.rb

+12
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,23 @@ def configure_redis
3838
copy_file 'config/initializers/redis_config.rb'
3939
end
4040

41+
def configure_valkyrie
42+
copy_file 'config/initializers/1_valkyrie.rb'
43+
end
44+
4145
def configure_valkyrie_index
4246
copy_file 'config/valkyrie_index.yml'
4347
copy_file 'config/solr_wrapper_valkyrie_test.yml'
4448
end
4549

50+
def metadata_dir
51+
empty_directory 'config/metadata'
52+
end
53+
54+
def derivatives_file_services
55+
copy_file 'config/initializers/file_services.rb'
56+
end
57+
4658
def create_initializer_config_file
4759
copy_file 'config/initializers/hyrax.rb'
4860
end

lib/generators/hyrax/install_generator.rb

+23
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def qa_tables
141141
generate 'qa:local:tables'
142142
end
143143

144+
def inject_required_seeds
145+
insert_into_file 'db/seeds.rb' do
146+
'Hyrax::RequiredDataSeeder.new.generate_seed_data'
147+
end
148+
end
149+
144150
def install_assets
145151
generate "hyrax:assets"
146152
end
@@ -182,9 +188,26 @@ def riiif_image_server
182188
generate 'hyrax:riiif' unless options[:'skip-riiif']
183189
end
184190

191+
def insert_env_queue_adapter
192+
insert_into_file 'config/application.rb', after: /config\.load_defaults [0-9.]+$/ do
193+
"\n config.active_job.queue_adapter = ENV.fetch('HYRAX_ACTIVE_JOB_QUEUE') { 'async' }.to_sym\n"
194+
end
195+
end
196+
185197
def universalviewer_files
186198
rake('hyrax:universal_viewer:install')
187199
rake('yarn:install')
188200
end
201+
202+
def lando
203+
copy_file '.lando.yml'
204+
end
205+
206+
def dotenv
207+
copy_file '.env'
208+
gem_group :development, :test do
209+
gem 'dotenv-rails', '~> 2.8'
210+
end
211+
end
189212
end
190213
end

lib/generators/hyrax/models_generator.rb

+1-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def banner
1515
# Setup the database migrations
1616
def copy_migrations
1717
rake 'hyrax:install:migrations'
18+
rake 'valkyrie_engine:install:migrations'
1819
end
1920

2021
# Add behaviors to the user model
@@ -36,16 +37,6 @@ def inject_user_behavior
3637
end
3738
# rubocop:enable Metrics/MethodLength
3839

39-
def create_collection
40-
copy_file 'app/models/collection.rb', 'app/models/collection.rb'
41-
copy_file 'spec/models/collection_spec.rb', 'spec/models/collection_spec.rb' if rspec_installed?
42-
end
43-
44-
def create_file_set
45-
copy_file 'app/models/file_set.rb', 'app/models/file_set.rb'
46-
copy_file 'spec/models/file_set_spec.rb', 'spec/models/file_set_spec.rb' if rspec_installed?
47-
end
48-
4940
# Adds clamav initializtion
5041
def clamav
5142
generate 'hyrax:clamav'

lib/generators/hyrax/riiif_generator.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ def banner
1818

1919
def add_to_gemfile
2020
gem 'riiif', '~> 2.1'
21-
22-
Bundler.with_clean_env do
23-
run "bundle install"
24-
end
2521
end
2622

2723
def copy_initializer
@@ -32,6 +28,12 @@ def mount_route
3228
route "mount Riiif::Engine => 'images', as: :riiif if Hyrax.config.iiif_image_server?"
3329
end
3430

31+
def enable_riiif_in_hyrax_config
32+
insert_into_file 'config/initializers/hyrax.rb', before: /^ # config.iiif_image_server = false/ do
33+
" config.iiif_image_server = true\n"
34+
end
35+
end
36+
3537
def override_image_url_builder_in_hyrax_config
3638
insert_into_file 'config/initializers/hyrax.rb', before: /^ # config.iiif_image_url_builder/ do
3739
" config.iiif_image_url_builder = lambda do |file_id, base_url, size, format|\n" \

lib/generators/hyrax/templates/.env

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CH12N_TOOL=fits_servlet
2+
DATABASE_URL=postgresql://postgres@localhost:5437/hyrax-dev?pool=5
3+
FCREPO_URL=http://fedoraAdmin:fedoraAdmin@fcrepo:8989/fcrepo/rest
4+
FITS_SERVLET_URL=http://localhost:8085/fits
5+
HYRAX_ACTIVE_JOB_QUEUE=async
6+
REDIS_URL=redis://localhost:6384
7+
SOLR_URL=http://localhost:8988/solr/hyrax-dev
8+
VALKYRIE_METADATA_ADAPTER=pg_metadata
9+
VALKYRIE_STORAGE_ADAPTER=versioned_disk_storage
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: hyrax-app
2+
app_mount: false
3+
services:
4+
solr:
5+
app_mount: false
6+
type: solr:8
7+
portforward: 8988
8+
core: hyrax-dev
9+
config:
10+
dir: solr/conf
11+
database:
12+
app_mount: false
13+
type: postgres:15
14+
portforward: 5437
15+
creds:
16+
database: hyrax-dev
17+
redis:
18+
app_mount: false
19+
type: redis:6
20+
portforward: 6384
21+
persist: true
22+
fits:
23+
api: 3
24+
type: lando
25+
app_mount: false
26+
services:
27+
image: ghcr.io/samvera/fitsservlet:1.6.0
28+
command:
29+
- "catalina.sh"
30+
- "run"
31+
ports:
32+
- 8085:8080
33+
# fedora:
34+
# api: 3
35+
# type: lando
36+
# app_mount: false
37+
# volumes:
38+
# fedora6:
39+
# services:
40+
# image: fcrepo/fcrepo:6.4.0
41+
# command:
42+
# - "catalina.sh"
43+
# - "run"
44+
# volumes:
45+
# - fedora6:/data
46+
# ports:
47+
# - 8989:8080
48+
# environment:
49+
# 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 -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
50+
# JAVA_OPTS: "-Dfcrepo.dynamic.jms.port=61619 -Dfcrepo.dynamic.stomp.port=61615 -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"

0 commit comments

Comments
 (0)