Skip to content

Commit 6ba190c

Browse files
rosielAlan Stanleyajstanleyajstanleynigelgbanks
authored
CrayFits as part of Crayfish (#178)
Co-authored-by: Alan Stanley <[email protected]> Co-authored-by: ajstanley <vagrant@claw> Co-authored-by: Alan Stanley <[email protected]> Co-authored-by: Nigel Banks <[email protected]> Co-authored-by: Alexander O'Neill <[email protected]>
1 parent ac8752a commit 6ba190c

22 files changed

+737
-0
lines changed

CrayFits/.env

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the later taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
#
13+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
14+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
15+
16+
###> symfony/framework-bundle ###
17+
APP_ENV=dev
18+
APP_SECRET=5273c9fd27359cc05a2f653521d8add0
19+
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
20+
#TRUSTED_HOSTS='^localhost|example\.com$'
21+
###< symfony/framework-bundle ###
22+
23+
###> doctrine/doctrine-bundle ###
24+
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
25+
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
26+
# Configure your db driver and server_version in config/packages/doctrine.yaml
27+
DATABASE_URL=mysql://db_user:[email protected]:3306/db_name
28+
###< doctrine/doctrine-bundle ###
29+
FITS_WEBSERVICE_URI=http://localhost:8080/fits/
30+
31+
32+
###> nelmio/cors-bundle ###
33+
CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$
34+
###< nelmio/cors-bundle ###

CrayFits/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# CrayFits
2+
3+
## Introduction
4+
5+
[FITS][1] as a microservice.
6+
7+
## Requirements
8+
9+
* Tomcat
10+
* [Composer][2]
11+
12+
## Installation
13+
14+
### Install FITS webservice
15+
16+
* Download the latest `fits.zip` and `fits.war` from
17+
[https://projects.iq.harvard.edu/fits/downloads](https://projects.iq.harvard.edu/fits/downloads).
18+
You may need to install a zip library to unzip the file.
19+
* Copy the `.war` file to your Tomcat webapps directory and test.
20+
* Edit the Tomcat `conf/catalina.properties` file by adding the
21+
following two lines to the bottom of the file:
22+
```properties
23+
fits.home=/\<path-to-fits>/fits
24+
shared.loader=/\<path-to-fits>/fits/lib/*.jar
25+
```
26+
* Restart Tomcat.
27+
* Test the webservice with:
28+
```bash
29+
curl -k -F datafile="@/path/to/myfile.jpg" http://[tomcat_domain]:[tomcat_port]/fits/examine
30+
```
31+
(note: the ‘@’ is required.)
32+
33+
### Install CrayFITS microservice
34+
35+
* Clone this repository somewhere in your web root.
36+
* `$ cd /path/to/CrayFits` and run `$ composer install`
37+
* For production, configure your web server appropriately (e.g. add a VirtualHost for CrayFits in Apache)
38+
39+
To run the microservice on the Symfony Console, enter:
40+
```bash
41+
php bin/console server:start *:8050
42+
```
43+
in the microservice root folder.
44+
45+
The server is stopped with:
46+
```bash
47+
php bin/console server:stop
48+
```
49+
On a production machine you'd probably want to configure an additional
50+
port in Apache.
51+
52+
Note: The location of the FITS webserver is stored in the `.env` file in the
53+
root dir of the Symfony app. This will have to be reconfigured if the FITS
54+
server is anywhere other than `localhost:8080/fits`
55+
56+
57+
#### Optional: Configure Alpaca to accept derivative requests from Islandora.
58+
59+
To use Alpaca as an interface to this microservice, configure
60+
an [`islandora-connector-derivative`](https://github.com/Islandora/Alpaca#islandora-connector-derivative)
61+
appropriate to your installation of CrayFits.
62+
63+
[1]: https://projects.iq.harvard.edu/fits
64+
[2]: https://getcomposer.org/download/
65+
66+

CrayFits/bin/console

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
use Symfony\Component\Debug\Debug;
8+
9+
if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
10+
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
11+
}
12+
13+
set_time_limit(0);
14+
15+
require dirname(__DIR__).'/vendor/autoload.php';
16+
17+
if (!class_exists(Application::class)) {
18+
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
19+
}
20+
21+
$input = new ArgvInput();
22+
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
23+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
24+
}
25+
26+
if ($input->hasParameterOption('--no-debug', true)) {
27+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
28+
}
29+
30+
require dirname(__DIR__).'/config/bootstrap.php';
31+
32+
if ($_SERVER['APP_DEBUG']) {
33+
umask(0000);
34+
35+
if (class_exists(Debug::class)) {
36+
Debug::enable();
37+
}
38+
}
39+
40+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
41+
$application = new Application($kernel);
42+
$application->run($input);

CrayFits/composer.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"type": "project",
3+
"license": "proprietary",
4+
"require": {
5+
"ext-ctype": "*",
6+
"ext-iconv": "*",
7+
"guzzlehttp/guzzle": "^6.3",
8+
"monolog/monolog": "^1.24",
9+
"symfony/console": "^4.4",
10+
"symfony/dotenv": "^4.4",
11+
"symfony/flex": "^1.1",
12+
"symfony/framework-bundle": "^4.4",
13+
"symfony/monolog-bundle": "^3.3",
14+
"symfony/yaml": "^4.4"
15+
},
16+
"config": {
17+
"preferred-install": {
18+
"*": "dist"
19+
},
20+
"sort-packages": true,
21+
"allow-plugins": {
22+
"symfony/flex": true
23+
}
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"App\\": "src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"App\\Tests\\": "tests/"
33+
}
34+
},
35+
"replace": {
36+
"paragonie/random_compat": "2.*",
37+
"symfony/polyfill-ctype": "*",
38+
"symfony/polyfill-iconv": "*",
39+
"symfony/polyfill-php71": "*",
40+
"symfony/polyfill-php70": "*",
41+
"symfony/polyfill-php56": "*"
42+
},
43+
"scripts": {
44+
"auto-scripts": {
45+
"cache:clear": "symfony-cmd",
46+
"assets:install %PUBLIC_DIR%": "symfony-cmd"
47+
},
48+
"post-install-cmd": [
49+
"@auto-scripts"
50+
],
51+
"post-update-cmd": [
52+
"@auto-scripts"
53+
],
54+
"test": [
55+
"@check"
56+
]
57+
},
58+
"conflict": {
59+
"symfony/symfony": "*"
60+
},
61+
"extra": {
62+
"symfony": {
63+
"allow-contrib": false,
64+
"require": "^4.4"
65+
}
66+
}
67+
}

CrayFits/config/bootstrap.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Symfony\Component\Dotenv\Dotenv;
4+
5+
require dirname(__DIR__).'/vendor/autoload.php';
6+
7+
// Load cached env vars if the .env.local.php file exists
8+
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
9+
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
10+
$_ENV += $env;
11+
} elseif (!class_exists(Dotenv::class)) {
12+
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
13+
} else {
14+
// load all the .env files
15+
(new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
16+
}
17+
18+
$_SERVER += $_ENV;
19+
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
20+
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
21+
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

CrayFits/config/bundles.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
5+
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
6+
];

CrayFits/config/packages/cache.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
framework:
2+
cache:
3+
# Put the unique name of your app here: the prefix seed
4+
# is used to compute stable namespaces for cache keys.
5+
#prefix_seed: your_vendor_name/app_name
6+
7+
# The app cache caches to the filesystem by default.
8+
# Other options include:
9+
10+
# Redis
11+
#app: cache.adapter.redis
12+
#default_redis_provider: redis://localhost
13+
14+
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
15+
#app: cache.adapter.apcu
16+
17+
# Namespaced pools use the above "app" backend by default
18+
#pools:
19+
#my.dedicated.cache: ~
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
router:
3+
strict_requirements: true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
framework:
2+
secret: '%env(APP_SECRET)%'
3+
#default_locale: en
4+
#csrf_protection: true
5+
#http_method_override: true
6+
7+
# Enables session support. Note that the session will ONLY be started if you read or write from it.
8+
# Remove or comment this section to explicitly disable session support.
9+
session:
10+
handler_id: ~
11+
cookie_secure: auto
12+
cookie_samesite: lax
13+
14+
#esi: true
15+
#fragments: true
16+
php_errors:
17+
log: true

CrayFits/config/packages/routing.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
router:
3+
strict_requirements: ~
4+
utf8: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
test: true
3+
session:
4+
storage_id: session.storage.mock_file
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
router:
3+
strict_requirements: true

CrayFits/config/routes.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# config/routes.yaml
2+
3+
app_fits_exec:
4+
path: /
5+
controller: App\Controller\FitsController::generate_fits

CrayFits/config/services.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is the entry point to configure your own services.
2+
# Files in the packages/ subdirectory configure your dependencies.
3+
4+
# Put parameters here that don't need to change on each machine where the app is deployed
5+
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
6+
parameters:
7+
8+
services:
9+
# default configuration for services in *this* file
10+
_defaults:
11+
autowire: true # Automatically injects dependencies in your services.
12+
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
13+
14+
# makes classes in src/ available to be used as services
15+
# this creates a service per class whose id is the fully-qualified class name
16+
App\:
17+
resource: '../src/*'
18+
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
19+
20+
# controllers are imported separately to make sure services can be injected
21+
# as action arguments even if you don't extend any base controller class
22+
App\Controller\:
23+
resource: '../src/Controller'
24+
tags: ['controller.service_arguments']
25+
26+
# add more service definitions when explicit configuration is needed
27+
# please note that last definitions always *replace* previous ones

0 commit comments

Comments
 (0)