Skip to content

Commit

Permalink
Merge pull request #85 from hyn/issue-47
Browse files Browse the repository at this point in the history
refactored to monolythic so working on the repo is easier in the future
  • Loading branch information
luceos committed Jun 7, 2016
2 parents c9b37bc + a3dd8db commit 2679872
Show file tree
Hide file tree
Showing 95 changed files with 2,958 additions and 22 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Expand Up @@ -3,9 +3,7 @@ language: php
sudo: true

php:
- 5.6
- 7.0
- hhvm

addons:
hosts:
Expand All @@ -19,20 +17,21 @@ install:
- travis_retry composer self-update
# clear composer cache, might speed up finding new tags
- travis_retry composer clear-cache
# include prestissimo which speeds up package download
- composer global require hirak/prestissimo
# set the global github token, so connections won't be cancelled
- composer config -g github-oauth.github.com $GITHUB_TOKEN
# create a new database for the hyn connection
- mysql -e "create database hyn;" -uroot
- mysql -e "grant all privileges on *.* to 'travis'@'localhost' with grant option;" -uroot
# create a new laravel project in the subfolder laravel (default composer behaviour)
- composer require laravel/laravel 5.1
- composer require laravel/laravel 5.2
# set global variables
- export DB_USERNAME=travis DB_DATABASE=hyn DB_PASSWORD= QUEUE_DRIVER=sync BUILD_DIR=$TRAVIS_BUILD_DIR

script:
- composer require "hyn/framework dev-master"
# run the script calling unit tests and so on
- ./scripts/travis.sh

after_success:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)
21 changes: 12 additions & 9 deletions composer.json
Expand Up @@ -15,9 +15,10 @@
"docs": "https://hyn.readme.io"
},
"require": {
"php": ">=5.5.9",
"hyn/framework": "*",
"hyn/webserver": "*"
"php": ">=7.0.0",
"laravel/framework": "~5.2.0",
"phpseclib/phpseclib": "^2.0",
"laracasts/presenter": "~0.2.0"
},
"suggest": {
"hyn/management-interface": "Provides a user interface for managing multi tenancy"
Expand All @@ -28,13 +29,15 @@
},
"autoload": {
"psr-4": {
"Hyn\\MultiTenant\\": "src/"
"Hyn\\Framework\\": "src/Framework/",
"Hyn\\MultiTenant\\": "src/Tenancy/",
"Hyn\\Webserver\\": "src/Webserver/"
}
},
"autoload-dev": {
"psr-4": {
"Hyn\\MultiTenant\\Tests\\": "tests/"
"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"minimum-stability": "stable"
}
}
18 changes: 18 additions & 0 deletions config/hyn.php
@@ -0,0 +1,18 @@
<?php

return [
'packages' => [
'multi-tenant' => [
'description' => 'Multi tenancy for Laravel 5.1+',
'service-provider' => 'Hyn\MultiTenant\MultiTenantServiceProvider',
],
'management-interface' => [
'description' => 'Interface for managing webserver and multi tenancy',
'service-provider' => 'Hyn\ManagementInterface\ManagementInterfaceServiceProvider',
],
'webserver' => [
'description' => 'Integration into and generation of configs for webservices',
'service-provider' => 'Hyn\Webserver\WebserverServiceProvider',
],
],
];
122 changes: 122 additions & 0 deletions config/webserver.php
@@ -0,0 +1,122 @@
<?php

/**
* All hyn-me/webserver related configuration options.
*
* @warning please be advised, read the documentation on http://hyn.me before editing
*
* None of the generated configurations will work as long as you don't add the paths to the corresponding webservice
* configuration file. See documentation for more info.
*/
return [
'webservers' => ['nginx', 'apache'],

/*
* If tenant files should belong to a certain user, set the `default-user` value to that username
* - true will generate a username automatically based on the website
* - <string> will use the specified existing username for the website
* - null will disable generating users
*/
'default-user' => true,

/*
* The group the tenant files should belong to
*/
'group' => 'www-data',

/*
* SSL
*/
'ssl' => [
'path' => storage_path('webserver/ssl'),
],
/*
* Logging specific settings
*/
'log' => [
// path where to store the webserver logs
'path' => storage_path('logs'),
],
/*
* Apache
*/
'apache' => [
'path' => storage_path('webserver/apache/'),
// class that runs functionality for this service
'class' => 'Hyn\Webserver\Generators\Webserver\Apache',
'enabled' => true,
'port' => [
'http' => 80,
'https' => 443,
],
// path to service daemon, used to verify service exists
'service' => '/etc/init.d/apache2',
// how to run actions for this service
'actions' => [
'configtest' => 'apache2ctl -t',
'reload' => 'apache2ctl graceful',
],
// system wide configuration directory
'conf' => [
// location for ubuntu 14.04 systems
'/etc/apache2/sites-enabled/',
],
// mask for auto-generated config file that includes the tenant configurations
'mask' => '%s.conf',
// include format using sprintf to include the location of the storage/webserver/apache directory
'include' => 'IncludeOptional %s*',
],
/*
* Nginx
*/
'nginx' => [
'path' => storage_path('webserver/nginx/'),
'class' => 'Hyn\Webserver\Generators\Webserver\Nginx',
'enabled' => true,
'port' => [
'http' => 80,
'https' => 443,
],
// path to service daemon, used to verify service exists
'service' => '/etc/init.d/nginx',
// how to run actions for this service
'actions' => [
'configtest' => '/etc/init.d/nginx configtest',
'reload' => '/etc/init.d/nginx reload',
],
'conf' => ['/etc/nginx/sites-enabled/'],
'mask' => '%s.conf',
'include' => 'include %s*;',
/*
* the nginx service depends on fpm
* during changes we will automatically trigger fpm as well
*/
'depends' => [
'fpm',
],
],
/*
* PHP FPM
*/
'fpm' => [
'path' => storage_path('webserver/fpm/'),
'class' => 'Hyn\Webserver\Generators\Webserver\Fpm',
'enabled' => true,
'conf' => ['/etc/php5/fpm/pool.d/'],
// path to service daemon, used to verify service exists
'service' => '/etc/init.d/php5-fpm',
// how to run actions for this service
'actions' => [
'configtest' => '/etc/init.d/php5-fpm -t',
'reload' => '/etc/init.d/php5-fpm reload',
],
'mask' => '%s.conf',
'include' => 'include=%s*;',
/*
* base modifier for fpm pool port
* @example if base is 9000, will generate pool file for website Id 5 with port 9005
* @info this port is used in Nginx configurations for the PHP proxy
*/
'port' => 9000,
],
];
@@ -0,0 +1,55 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Hyn\MultiTenant\Tenant\DatabaseConnection;

class HwsSslCertificatesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection(DatabaseConnection::systemConnectionName())->create('ssl_certificates', function (Blueprint $table) {
$table->bigIncrements('id');
// tenant owner
$table->bigInteger('tenant_id')->unsigned();

// certificate
$table->text('certificate');
// bundles
$table->text('authority_bundle');
// key
$table->text('key');

$table->boolean('wildcard')->default(false);

// date when certificate becomes usable as read from certificate
$table->timestamp('validates_at')->nullable();
// date of expiry as read from certificate
$table->timestamp('invalidates_at')->nullable();

// timestaps
$table->timestamps();
$table->softDeletes();

// relations
$table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade');

// index
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection(DatabaseConnection::systemConnectionName())->dropIfExists('ssl_certificates');
}
}
51 changes: 51 additions & 0 deletions database/migrations/2015_05_19_000001_hws_ssl_hostnames_table.php
@@ -0,0 +1,51 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Hyn\MultiTenant\Tenant\DatabaseConnection;

class HwsSslHostnamesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection(DatabaseConnection::systemConnectionName())->create('ssl_hostnames', function (Blueprint $table) {
$table->bigIncrements('id');
// certificate id
$table->bigInteger('ssl_certificate_id')->unsigned();
// domain relation
$table->bigInteger('hostname_id')->unsigned();

// certificate
$table->string('hostname');

// timestaps
$table->timestamps();
$table->softDeletes();

// index
$table->index('hostname');
$table->index('hostname_id');
$table->index('ssl_certificate_id');
// relations
$table->foreign('ssl_certificate_id')->references('id')->on('ssl_certificates')->onDelete('cascade');
// the set null constraint does not work on mariadb; let's just ignore that for now
// @TODO but fix support for set null in the future somehow
// $table->foreign('hostname_id')->references('id')->on('hostnames')->onDelete('set null');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection(DatabaseConnection::systemConnectionName())->dropIfExists('ssl_hostnames');
}
}
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Hyn\MultiTenant\Tenant\DatabaseConnection;

class HwsSslHostnamesDropHostnameId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection(DatabaseConnection::systemConnectionName())->table('ssl_hostnames', function (Blueprint $table) {
// domain relation
$table->dropColumn('hostname_id');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection(DatabaseConnection::systemConnectionName())->table('ssl_hostnames', function (Blueprint $table) {
// domain relation
$table->bigInteger('hostname_id')->unsigned();
});
}
}

0 comments on commit 2679872

Please sign in to comment.