Skip to content

Commit

Permalink
CrayFits as part of Crayfish (#178)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
6 people committed Nov 1, 2023
1 parent ac8752a commit 6ba190c
Show file tree
Hide file tree
Showing 22 changed files with 737 additions and 0 deletions.
34 changes: 34 additions & 0 deletions CrayFits/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# In all environments, the following files are loaded if they exist,
# the later taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=5273c9fd27359cc05a2f653521d8add0
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS='^localhost|example\.com$'
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=mysql://db_user:[email protected]:3306/db_name
###< doctrine/doctrine-bundle ###
FITS_WEBSERVICE_URI=http://localhost:8080/fits/


###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$
###< nelmio/cors-bundle ###
66 changes: 66 additions & 0 deletions CrayFits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# CrayFits

## Introduction

[FITS][1] as a microservice.

## Requirements

* Tomcat
* [Composer][2]

## Installation

### Install FITS webservice

* Download the latest `fits.zip` and `fits.war` from
[https://projects.iq.harvard.edu/fits/downloads](https://projects.iq.harvard.edu/fits/downloads).
You may need to install a zip library to unzip the file.
* Copy the `.war` file to your Tomcat webapps directory and test.
* Edit the Tomcat `conf/catalina.properties` file by adding the
following two lines to the bottom of the file:
```properties
fits.home=/\<path-to-fits>/fits
shared.loader=/\<path-to-fits>/fits/lib/*.jar
```
* Restart Tomcat.
* Test the webservice with:
```bash
curl -k -F datafile="@/path/to/myfile.jpg" http://[tomcat_domain]:[tomcat_port]/fits/examine
```
(note: the ‘@’ is required.)

### Install CrayFITS microservice

* Clone this repository somewhere in your web root.
* `$ cd /path/to/CrayFits` and run `$ composer install`
* For production, configure your web server appropriately (e.g. add a VirtualHost for CrayFits in Apache)

To run the microservice on the Symfony Console, enter:
```bash
php bin/console server:start *:8050
```
in the microservice root folder.

The server is stopped with:
```bash
php bin/console server:stop
```
On a production machine you'd probably want to configure an additional
port in Apache.

Note: The ___location of the FITS webserver is stored in the `.env` file in the
root dir of the Symfony app. This will have to be reconfigured if the FITS
server is anywhere other than `localhost:8080/fits`


#### Optional: Configure Alpaca to accept derivative requests from Islandora.

To use Alpaca as an interface to this microservice, configure
an [`islandora-connector-derivative`](https://github.com/Islandora/Alpaca#islandora-connector-derivative)
appropriate to your installation of CrayFits.

[1]: https://projects.iq.harvard.edu/fits
[2]: https://getcomposer.org/download/


42 changes: 42 additions & 0 deletions CrayFits/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;

if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
}

set_time_limit(0);

require dirname(__DIR__).'/vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

require dirname(__DIR__).'/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
67 changes: 67 additions & 0 deletions CrayFits/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"type": "project",
"license": "proprietary",
"require": {
"ext-ctype": "*",
"ext-iconv": "*",
"guzzlehttp/guzzle": "^6.3",
"monolog/monolog": "^1.24",
"symfony/console": "^4.4",
"symfony/dotenv": "^4.4",
"symfony/flex": "^1.1",
"symfony/framework-bundle": "^4.4",
"symfony/monolog-bundle": "^3.3",
"symfony/yaml": "^4.4"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true,
"allow-plugins": {
"symfony/flex": true
}
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
],
"test": [
"@check"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "^4.4"
}
}
}
21 changes: 21 additions & 0 deletions CrayFits/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
$_ENV += $env;
} elseif (!class_exists(Dotenv::class)) {
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
// load all the .env files
(new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
}

$_SERVER += $_ENV;
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
6 changes: 6 additions & 0 deletions CrayFits/config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
];
19 changes: 19 additions & 0 deletions CrayFits/config/packages/cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
framework:
cache:
# Put the unique name of your app here: the prefix seed
# is used to compute stable namespaces for cache keys.
#prefix_seed: your_vendor_name/app_name

# The app cache caches to the filesystem by default.
# Other options include:

# Redis
#app: cache.adapter.redis
#default_redis_provider: redis://localhost

# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
#app: cache.adapter.apcu

# Namespaced pools use the above "app" backend by default
#pools:
#my.dedicated.cache: ~
3 changes: 3 additions & 0 deletions CrayFits/config/packages/dev/routing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework:
router:
strict_requirements: true
17 changes: 17 additions & 0 deletions CrayFits/config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
framework:
secret: '%env(APP_SECRET)%'
#default_locale: en
#csrf_protection: true
#http_method_override: true

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
handler_id: ~
cookie_secure: auto
cookie_samesite: lax

#esi: true
#fragments: true
php_errors:
log: true
4 changes: 4 additions & 0 deletions CrayFits/config/packages/routing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
router:
strict_requirements: ~
utf8: true
4 changes: 4 additions & 0 deletions CrayFits/config/packages/test/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
test: true
session:
storage_id: session.storage.mock_file
3 changes: 3 additions & 0 deletions CrayFits/config/packages/test/routing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework:
router:
strict_requirements: true
5 changes: 5 additions & 0 deletions CrayFits/config/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# config/routes.yaml

app_fits_exec:
path: /
controller: App\Controller\FitsController::generate_fits
27 changes: 27 additions & 0 deletions CrayFits/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:

services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
Loading

0 comments on commit 6ba190c

Please sign in to comment.