Skip to content

Commit

Permalink
Merge pull request #9 from richdynamix/release/2.0.0
Browse files Browse the repository at this point in the history
Release/2.0.0
  • Loading branch information
richdynamix authored Feb 23, 2019
2 parents 905b2bc + 5b8712e commit 2ebdf16
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 166 deletions.
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Arc

Bootstrap your new Laravel projects with package dependency installation and a highly configurable production ready Docker environment.
Bootstrap your new Laravel projects with a highly configurable production ready Docker environment.

## Overview

Arc is a simple Laravel package to add the ultimate docker environment for the majority of your applications. Built upon the amazing [ContinuousPipe Dockerfiles](https://github.com/continuouspipe/dockerfiles), this package will add the correct Dockerfile, Docker Compose and configurations into your Laravel project. Additionally, Arc will prompt you to install some package dependencies that are popular additions to any Laravel project.
Arc is a simple Laravel package to add the ultimate docker environment for the majority of your applications. Built upon the amazing [ContinuousPipe Dockerfiles](https://github.com/continuouspipe/dockerfiles), this package will add the correct Dockerfile, Docker Compose and configurations into your Laravel project.

The Docker configuration provides the following -

Expand Down Expand Up @@ -37,15 +37,7 @@ This package is intended for new Laravel >5.5 projects.
php artisan arc:install
```

The installer will ask if you would like to install the following packages. While some of these packages are not for every project they bring huge value to any project.

Package | Description
--- | ---
[barryvdh/laravel-ide-helper](https://github.com/barryvdh/laravel-ide-helper) | This package generates a file that your IDE understands, so it can provide accurate autocompletion. Generation is done based on the files in your project, so they are always up-to-date.
[ellipsesynergie/api-response](https://github.com/ellipsesynergie/api-response) | Simple package to handle response properly in your API. This package uses [Fractal](https://github.com/thephpleague/fractal) and is based on [Build APIs You Won't Hate](https://leanpub.com/build-apis-you-wont-hate) book.
[genealabs/laravel-model-caching](https://github.com/genealabs/laravel-model-caching) | A package that abstracts the caching process into the model and provides self-invalidating relationship (only eager-loading) caching, query caching and automatic use of cache tags for cache providers that support them (will flush entire cache for providers that don't)
[lord/laroute](https://github.com/aaronlord/laroute) | This package ports the routes over to JavaScript, and gives a bunch of very familiar helper functions to use.
[laravel/horizon](https://github.com/laravel/horizon) | Horizon provides a beautiful dashboard and code-driven configuration for your Laravel powered Redis queues. Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures.
Once complete the installer will remove Arc as a composer dependency.

#### Run the Container

Expand Down
103 changes: 7 additions & 96 deletions src/Console/InstallArc.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

class InstallArc extends Command
{
const PACKAGES = [
'barryvdh/laravel-ide-helper' => 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
'ellipsesynergie/api-response' => '',
'genealabs/laravel-model-caching' => '',
'lord/laroute' => 'Lord\Laroute\LarouteServiceProvider',
'laravel/horizon' => 'Laravel\Horizon\HorizonServiceProvider',
];

/**
* The name and signature of the console command.
*
Expand All @@ -27,7 +19,7 @@ class InstallArc extends Command
*
* @var string
*/
protected $description = 'Install Arc package dependencies';
protected $description = 'Install Arc';

/**
* Execute the console command.
Expand All @@ -36,45 +28,18 @@ class InstallArc extends Command
*/
public function handle()
{
$this->info('The following packages are suggested as development aids. Arc can install and configure these for you.');

$questions = $this->verifyPackageInstalls();
$this->disaplyConfirmation($questions);
$this->info('Configuring your project...');

if ($questions) {
$this->info('Installing...');
$this->runComposerInstall($this->getComposerCommand($questions));
}
$this->publishConfigs();

$this->publishConfigs($questions);
$this->configureEnv($questions);
}

/**
* @param $questions
* @return string
*/
private function getComposerCommand($questions): string
{
$composer = 'composer require ';
$cmd = '';
foreach ($questions as $question) {
if (strtolower($question['status']) === 'install') {
$cmd .= $question['package'] . ' ';
}
}

if (!empty($cmd)) {
return $composer.$cmd;
}

return '';
$this->info('Cleaning up and removing Arc...');
$this->runComposer( 'composer remove richdynamix/arc');
}

/**
* @param $cmd
*/
private function runComposerInstall($cmd): void
private function runComposer($cmd): void
{
if ($cmd) {
$process = new Process($cmd, null, array_merge($_SERVER, $_ENV), null, null);
Expand All @@ -84,63 +49,9 @@ private function runComposerInstall($cmd): void
}
}

/**
* @return array
*/
private function verifyPackageInstalls(): array
{
$questions = [];
$item = 0;
foreach (self::PACKAGES as $package => $provider) {
$questions[$item]['package'] = $package;
$questions[$item]['provider'] = $provider;
$status = $this->confirm("Would you like to install $package?") ? 'Install' : 'Not Installed';
$questions[$item]['status'] = $status;
++$item;
}
return $questions;
}

/**
* @param $questions
*/
private function disaplyConfirmation($questions): void
{
$headers = ['Package', 'Provider', 'Status'];
$this->table($headers, $questions);
}

/**
* @param $questions
*/
private function publishConfigs($questions): void
private function publishConfigs(): void
{
$this->info('Publishing Config...');
$this->call('vendor:publish', ['--provider' => 'Richdynamix\Arc\ArcServiceProvider']);

foreach ($questions as $question) {
if ($question['provider']) {
$this->call('vendor:publish', ['--provider' => $question['provider']]);
}
}
}

private function configureEnv($questions)
{
$packages = collect($questions);
$env = file_get_contents(base_path('tools/docker/usr/local/share/env/20-arc-env'));

$horizon = $packages->where('package', 'laravel/horizon')->first();
if ($horizon['status'] === 'Install') {
$oldHorizonConfig = 'START_HORIZON=${START_HORIZON:-false}';
$newHorizonConfig = 'START_HORIZON=${START_HORIZON:-true}';
$newEnv = str_replace($oldHorizonConfig, $newHorizonConfig, $env);

$oldQueueConfig = 'START_QUEUE=${START_QUEUE:-true}';
$newQueueConfig = 'START_QUEUE=${START_QUEUE:-false}';
$newEnv = str_replace($oldQueueConfig, $newQueueConfig, $newEnv);

file_put_contents(base_path('tools/docker/usr/local/share/env/20-arc-env'), $newEnv);
}
}
}
118 changes: 59 additions & 59 deletions tools/docker/etc/confd/templates/env/dotenv.tmpl
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
APP_NAME="{{ getenv "APP_NAME" }}";
APP_ENV="{{ getenv "APP_ENV" }}";
APP_KEY="{{ getenv "APP_KEY" }}";
APP_DEBUG="{{ getenv "APP_DEBUG" }}";
LOG_CHANNEL="{{ getenv "LOG_CHANNEL" }}";
APP_URL="{{ getenv "APP_URL" }}";

DB_CONNECTION="{{ getenv "DB_CONNECTION" }}";
DB_HOST="{{ getenv "DB_HOST" }}";
DB_PORT="{{ getenv "DB_PORT" }}";
DB_DATABASE="{{ getenv "DB_DATABASE" }}";
DB_USERNAME="{{ getenv "DB_USERNAME" }}";
DB_PASSWORD="{{ getenv "DB_PASSWORD" }}";

MAIL_DRIVER="{{ getenv "MAIL_DRIVER" }}";
MAIL_HOST="{{ getenv "MAIL_HOST" }}";
MAIL_PORT="{{ getenv "MAIL_PORT" }}";
MAIL_USERNAME="{{ getenv "MAIL_USERNAME" }}";
MAIL_PASSWORD="{{ getenv "MAIL_PASSWORD" }}";
MAIL_ENCRYPTION="{{ getenv "MAIL_ENCRYPTION" }}";

CACHE_DRIVER="{{ getenv "CACHE_DRIVER" }}";
SESSION_DRIVER="{{ getenv "SESSION_DRIVER" }}";
QUEUE_DRIVER="{{ getenv "QUEUE_DRIVER" }}";
SESSION_DRIVER="{{ getenv "SESSION_DRIVER" }}";
SESSION_LIFETIME="{{ getenv "SESSION_LIFETIME" }}";

REDIS_HOST="{{ getenv "REDIS_HOST" }}";
REDIS_PASSWORD="{{ getenv "REDIS_PASSWORD" }}";
REDIS_PORT="{{ getenv "REDIS_PORT" }}";

MIX_PUSHER_APP_KEY="{{ getenv "MIX_PUSHER_APP_KEY" }}";
MIX_PUSHER_APP_CLUSTER="{{ getenv "MIX_PUSHER_APP_CLUSTER" }}";

AUTHY_SECRET="{{ getenv "AUTHY_SECRET" }}";

STRIPE_MODEL="{{ getenv "STRIPE_MODEL" }}";
STRIPE_KEY="{{ getenv "STRIPE_KEY" }}";
STRIPE_SECRET="{{ getenv "STRIPE_SECRET" }}";

BRAINTREE_MODEL="{{ getenv "BRAINTREE_MODEL" }}";
BRAINTREE_ENV="{{ getenv "BRAINTREE_ENV" }}";
BRAINTREE_MERCHANT_ID="{{ getenv "BRAINTREE_MERCHANT_ID" }}";
BRAINTREE_PUBLIC_KEY="{{ getenv "BRAINTREE_PUBLIC_KEY" }}";
BRAINTREE_PRIVATE_KEY="{{ getenv "BRAINTREE_PRIVATE_KEY" }}";

BROADCAST_DRIVER="{{ getenv "BROADCAST_DRIVER" }}";
PUSHER_APP_ID="{{ getenv "PUSHER_APP_ID" }}";
PUSHER_KEY="{{ getenv "PUSHER_KEY" }}";
PUSHER_SECRET="{{ getenv "PUSHER_SECRET" }}";
PUSHER_APP_CLUSTER="{{ getenv "PUSHER_APP_CLUSTER" }}";

SENTRY_DSN="{{ getenv "SENTRY_DSN" }}";
LOGGLY_TOKEN="{{ getenv "LOGGLY_TOKEN" }}";

AWS_ACCESS_KEY_ID="{{ getenv "AWS_ACCESS_KEY_ID" }}";
AWS_SECRET_ACCESS_KEY="{{ getenv "AWS_SECRET_ACCESS_KEY" }}";
AWS_DEFAULT_REGION="{{ getenv "AWS_DEFAULT_REGION" }}";
AWS_BUCKET="{{ getenv "AWS_BUCKET" }}";
APP_NAME="{{ getenv "APP_NAME" }}"
APP_ENV="{{ getenv "APP_ENV" }}"
APP_KEY="{{ getenv "APP_KEY" }}"
APP_DEBUG="{{ getenv "APP_DEBUG" }}"
LOG_CHANNEL="{{ getenv "LOG_CHANNEL" }}"
APP_URL="{{ getenv "APP_URL" }}"

DB_CONNECTION="{{ getenv "DB_CONNECTION" }}"
DB_HOST="{{ getenv "DB_HOST" }}"
DB_PORT="{{ getenv "DB_PORT" }}"
DB_DATABASE="{{ getenv "DB_DATABASE" }}"
DB_USERNAME="{{ getenv "DB_USERNAME" }}"
DB_PASSWORD="{{ getenv "DB_PASSWORD" }}"

MAIL_DRIVER="{{ getenv "MAIL_DRIVER" }}"
MAIL_HOST="{{ getenv "MAIL_HOST" }}"
MAIL_PORT="{{ getenv "MAIL_PORT" }}"
MAIL_USERNAME="{{ getenv "MAIL_USERNAME" }}"
MAIL_PASSWORD="{{ getenv "MAIL_PASSWORD" }}"
MAIL_ENCRYPTION="{{ getenv "MAIL_ENCRYPTION" }}"

CACHE_DRIVER="{{ getenv "CACHE_DRIVER" }}"
SESSION_DRIVER="{{ getenv "SESSION_DRIVER" }}"
QUEUE_DRIVER="{{ getenv "QUEUE_DRIVER" }}"
SESSION_DRIVER="{{ getenv "SESSION_DRIVER" }}"
SESSION_LIFETIME="{{ getenv "SESSION_LIFETIME" }}"

REDIS_HOST="{{ getenv "REDIS_HOST" }}"
REDIS_PASSWORD="{{ getenv "REDIS_PASSWORD" }}"
REDIS_PORT="{{ getenv "REDIS_PORT" }}"

MIX_PUSHER_APP_KEY="{{ getenv "MIX_PUSHER_APP_KEY" }}"
MIX_PUSHER_APP_CLUSTER="{{ getenv "MIX_PUSHER_APP_CLUSTER" }}"

AUTHY_SECRET="{{ getenv "AUTHY_SECRET" }}"

STRIPE_MODEL="{{ getenv "STRIPE_MODEL" }}"
STRIPE_KEY="{{ getenv "STRIPE_KEY" }}"
STRIPE_SECRET="{{ getenv "STRIPE_SECRET" }}"

BRAINTREE_MODEL="{{ getenv "BRAINTREE_MODEL" }}"
BRAINTREE_ENV="{{ getenv "BRAINTREE_ENV" }}"
BRAINTREE_MERCHANT_ID="{{ getenv "BRAINTREE_MERCHANT_ID" }}"
BRAINTREE_PUBLIC_KEY="{{ getenv "BRAINTREE_PUBLIC_KEY" }}"
BRAINTREE_PRIVATE_KEY="{{ getenv "BRAINTREE_PRIVATE_KEY" }}"

BROADCAST_DRIVER="{{ getenv "BROADCAST_DRIVER" }}"
PUSHER_APP_ID="{{ getenv "PUSHER_APP_ID" }}"
PUSHER_KEY="{{ getenv "PUSHER_KEY" }}"
PUSHER_SECRET="{{ getenv "PUSHER_SECRET" }}"
PUSHER_APP_CLUSTER="{{ getenv "PUSHER_APP_CLUSTER" }}"

SENTRY_DSN="{{ getenv "SENTRY_DSN" }}"
LOGGLY_TOKEN="{{ getenv "LOGGLY_TOKEN" }}"

AWS_ACCESS_KEY_ID="{{ getenv "AWS_ACCESS_KEY_ID" }}"
AWS_SECRET_ACCESS_KEY="{{ getenv "AWS_SECRET_ACCESS_KEY" }}"
AWS_DEFAULT_REGION="{{ getenv "AWS_DEFAULT_REGION" }}"
AWS_BUCKET="{{ getenv "AWS_BUCKET" }}"
13 changes: 13 additions & 0 deletions tools/docker/usr/local/share/env/20-arc-env
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/bin/bash

DEVELOPMENT_MODE=${DEVELOPMENT_MODE:-true}
DEVELOPMENT_MODE="$(convert_to_boolean_string "$DEVELOPMENT_MODE")"
export DEVELOPMENT_MODE

COMPOSER_INSTALL_FLAGS="--no-interaction --optimize-autoloader --ignore-platform-reqs"

if [ -z "$DEVELOPMENT_MODE" ] || [ "$DEVELOPMENT_MODE" != 'true' ]; then
DEFAULT_COMPOSER_FLAGS="${DEFAULT_COMPOSER_FLAGS} --no-dev "
fi

export COMPOSER_INSTALL_FLAGS=${COMPOSER_INSTALL_FLAGS:-$COMPOSER_INSTALL_FLAGS}

START_MODE_CRON=${START_MODE_CRON:-true}
START_MODE_CRON="$(convert_to_boolean_string "$START_MODE_CRON")"
export START_MODE_CRON
Expand Down

0 comments on commit 2ebdf16

Please sign in to comment.