Skip to content

Commit

Permalink
fix issues with production docker on startup, also solves problems ar…
Browse files Browse the repository at this point in the history
…ound single tenant instantiation (#1590)
  • Loading branch information
orangewolf authored Oct 9, 2019
1 parent 9a9ff02 commit 0f0b5d9
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ before_install:

before_script:
- bundle exec rake db:create
- bundle exec chromedriver-update 74.0.3729.6
- bundle exec chromedriver-update 76.0.3809.68

before_deploy:
- git clean -dxf; rm -rf vendor/bundle
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ COPY --chown=app . $APP_HOME
RUN /sbin/setuser app bash -l -c "set -x && \
(bundle check || bundle install) && \
bundle exec rake assets:precompile DB_ADAPTER=nulldb && \
mv ./public/assets ./public/assets.new"
mv ./public/assets ./public/assets-new"

CMD ["/sbin/my_init"]
15 changes: 14 additions & 1 deletion Dockerfile.base
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
FROM phusion/passenger-ruby25:1.0.2

RUN apt-get update -qq && \
apt-get install -y build-essential libpq-dev nodejs libreoffice imagemagick unzip ghostscript libsasl2-dev libpq-dev postgresql-client tzdata && \
apt-get install -y \
build-essential \
ghostscript \
imagemagick \
libpq-dev \
libpq-dev nodejs \
libreoffice \
libsasl2-dev \
netcat \
postgresql-client \
rsync \
tzdata \
unzip \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Jump In: [![Slack Status](http://slack.samvera.org/badge.svg)](http://slack.samv
* [On AWS](#on-aws)
* [With Docker](#with-docker)
* [With Vagrant](#with-vagrant)
* [Single Tenant Mode](#single-tenancy)
* [Switching accounts](#switching-accounts)
* [Development dependencies](#development-dependencies)
* [Postgres](#postgres)
Expand Down Expand Up @@ -63,7 +64,8 @@ The full spec suite can be run in docker locally. There are several ways to do t
docker-compose exec web rake
```

### For development
### With out Docker
#### For development

```bash
solr_wrapper
Expand All @@ -74,7 +76,7 @@ bin/setup
DISABLE_REDIS_CLUSTER=true bundle exec sidekiq
DISABLE_REDIS_CLUSTER=true bundle exec rails server -b 0.0.0.0
```
### For testing
#### For testing

See the [Hyku Development Guide](https://github.com/samvera/hyku/wiki/Hyku-Development-Guide) for how to run tests.

Expand Down Expand Up @@ -104,6 +106,12 @@ docker-compose up -d

The [samvera-vagrant project](https://github.com/samvera-labs/samvera-vagrant) provides another simple way to get started "kicking the tires" of Hyku (and [Hyrax](http://hyr.ax/)), making it easy and quick to spin up Hyku. (Note that this is not for production or production-like installations.) It requires [VirtualBox](https://www.virtualbox.org/) and [Vagrant](https://www.vagrantup.com/).

## Single Tenant Mode

Much of the default configuration in Hyku is set up to use multi-tenant mode. This default mode allows Hyku users to run the equivielent of multiple Hyrax installs on a single set of resources. However, sometimes the subdomain splitting mutli-headed complexity is simply not needed. If this is the case, then single tenant mode is for you. Single tenant mode will not show the tenant sign up page, or any of the tenant management screens. Instead it shows a single Samvera instance at what ever domain is pointed at the application.

To enable single tenant, in your settings.yml file change multitenancy/enabled to `false` or set `SETTINGS__MULTITENANCY__ENABLED=false` in your `docker-compose.yml` and `docker-compose.production.yml` configs. After changinig this setting, run the seeds to prepopulate the single tenant.

## Switching accounts

The recommend way to switch your current session from one account to another is by doing:
Expand All @@ -116,7 +124,7 @@ AccountElevator.switch!('repo.example.com')

### Postgres

Hydra-in-a-Box supports multitenancy using the `apartment` gem. `apartment` works best with a postgres database.
Hyku supports multitenancy using the `apartment` gem. `apartment` works best with a postgres database.

## Importing
### from CSV:
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ApplicationController < ActionController::Base
def require_active_account!
return unless Settings.multitenancy.enabled
return if devise_controller?

raise Apartment::TenantNotFound, "No tenant for #{request.host}" unless current_account.persisted?
end

Expand All @@ -53,7 +52,15 @@ def admin_host?

def current_account
@current_account ||= Account.from_request(request)
@current_account ||= Account.single_tenant_default
@current_account ||= if Settings.multitenancy.enabled
Account.new do |a|
a.build_solr_endpoint
a.build_fcrepo_endpoint
a.build_redis_endpoint
end
else
Account.single_tenant_default
end
end

# Add context information to the lograge entries
Expand Down
4 changes: 3 additions & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ def self.from_request(request)

# @return [Account] a placeholder account using the default connections configured by the application
def self.single_tenant_default
Account.new do |a|
@single_tenant_default ||= Account.find_by(cname: 'single.tenant.default')
@single_tenant_default ||= Account.new do |a|
a.build_solr_endpoint
a.build_fcrepo_endpoint
a.build_redis_endpoint
end
@single_tenant_default
end

# @return [Boolean] whether this Account is the global tenant in a multitenant environment
Expand Down
5 changes: 5 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
Hyrax::Workflow::WorkflowImporter.load_workflows
errors = Hyrax::Workflow::WorkflowImporter.load_errors
abort("Failed to process all workflows:\n #{errors.join('\n ')}") unless errors.empty?

unless Settings.multitenancy.enabled
single_tenant_default = Account.new(name: 'Single Tenenat', cname: 'single.tenant.default', tenant: 'single')
CreateAccount.new(single_tenant_default).save
end
17 changes: 2 additions & 15 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ volumes:
assets:

networks:
external:
internal:

services:
Expand Down Expand Up @@ -79,7 +78,6 @@ services:
expose:
- 8983
volumes:
- .:/app
- solr:/opt/solr/server/solr
networks:
internal:
Expand All @@ -93,6 +91,7 @@ services:
volumes:
- fcrepo:/data
environment:
# - JAVA_OPTS=-Dfcrepo.modeshape.configuration="classpath:/config/jdbc-postgresql-s3/repository.json" -Dfcrepo.postgresql.host="db" -Dfcrepo.postgresql.username="postgres" -Dfcrepo.postgresql.password="DatabaseFTW" -Daws.accessKeyId="REPLACE_WITH_AWS_ID" -Daws.secretKey="REPLACE_WITH_AWS_SECRET_KEY" -Daws.bucket="REPLACE_WITH_BUCKET_NAME"
- JAVA_OPTS=${JAVA_OPTS} -Dfcrepo.modeshape.configuration="classpath:/config/file-simple/repository.json" -Dfcrepo.object.directory="/data/objects" -Dfcrepo.binary.directory="/data/binaries"
networks:
internal:
Expand All @@ -106,16 +105,7 @@ services:
networks:
internal:

base:
image: hyku/base:latest
build:
context: .
dockerfile: Dockerfile.base
env_file:
- .env

app:
build: .
image: hyku/main:latest
env_file:
- .env
Expand All @@ -124,6 +114,7 @@ services:
- FEDORA_URL=http://fcrepo:8080/fcrepo/rest
- IN_DOCKER=true
- LD_LIBRARY_PATH=/opt/fits/tools/mediainfo/linux
- PASSENGER_APP_ENV=production
- RAILS_CACHE_STORE_URL=memcache
- RAILS_LOG_TO_STDOUT=true
- REDIS_HOST=redis
Expand All @@ -140,16 +131,12 @@ services:
volumes:
- app:/home/app/webapp/tmp/uploads
- assets:/home/app/webapp/public/assets
- .:/home/app/webapp
networks:
internal:

web:
extends:
service: app
environment:
- VIRTUAL_PORT=80
- VIRTUAL_HOST=hyku.docker
depends_on:
- db
- solr
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ volumes:
assets:

networks:
external:
internal:

services:
Expand All @@ -34,7 +33,7 @@ services:
- zookeeper_cluster

solr:
image: solr:7.1
image: solr:7.5
command: solr -c -f -z zoo1:2181
depends_on:
- zoo1
Expand Down
2 changes: 2 additions & 0 deletions ops/nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ fi

if [[ $PASSENGER_APP_ENV == "production" ]] || [[ $PASSENGER_APP_ENV == "staging" ]]
then
/bin/bash -l -c 'chown -R app:app /home/app/webapp/tmp' # mounted volume may have wrong permissions
/bin/bash -l -c 'chown -R app:app /home/app/webapp/public/assets' # mounted volume may have wrong permissions
/sbin/setuser app /bin/bash -l -c 'cd /home/app/webapp && rsync -a public/assets-new/ public/assets/'
fi

Expand Down
23 changes: 0 additions & 23 deletions spec/features/edit_file_spec.rb

This file was deleted.

6 changes: 3 additions & 3 deletions spec/models/solr_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
allow(ActiveFedora::SolrService.instance).to receive(:conn)
.and_return(double(options: af_options))
allow(RSolr).to receive(:connect)
.with("read_timeout" => 120,
"open_timeout" => 120,
"url" => "http://example.com/solr/")
.with(hash_including("read_timeout" => 120,
"open_timeout" => 120,
"url" => "http://example.com/solr/"))
.and_return(result)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@

config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
Account.destroy_all
CreateSolrCollectionJob.new.without_account('hydra-test') if ENV['IN_DOCKER']
end

config.before(:each) do |example|
# Pass `:clean' to destroy objects in fedora/solr and start from scratch
ActiveFedora::Cleaner.clean! if example.metadata[:clean]

if example.metadata[:type] == :feature && Capybara.current_driver != :rack_test
DatabaseCleaner.strategy = :truncation
else
Expand Down

0 comments on commit 0f0b5d9

Please sign in to comment.