diff --git a/README.md b/README.md index 54928630..47bdc2da 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,47 @@ # Starting a dev environment + To begin development, you must do three things: 1. Install the `vagrant-hostmanager` plugin: `vagrant plugin install vagrant-hostmanager` -2. Install the "vagrant-bindfs" plugin: `vagrant plugin install vagrant-bindfs` +2. Install the `vagrant-bindfs` plugin: `vagrant plugin install vagrant-bindfs` 3. Create the directory `pony.fm.files` in the repository's parent directory 4. Run `vagrant up` from the folder in which you cloned the repository -Once everything is up and running, you'll be able to access the site at http://ponyfm-dev.poni/. You can access the MySQL database by logging into **192.168.33.11:3306** with the username of **homestead** and the password of **secret**. The pony.fm database is named **homestead**. +5. Run `vagrant ssh`, `cd /vagrant`, and `php artisan poni:setup`. + +6. Follow the instructions in the "Asset pipeline" section below to set that up. + +Once everything is up and running, you'll be able to access the site at [http://ponyfm-dev.poni/](http://ponyfm-dev.poni/). You can access the MySQL database by logging into **192.168.33.11:3306** with the username **homestead** and the password **secret**. Pony.fm's database is named **homestead**. # Asset pipeline -Pony.fm uses gulp to mange its asset pipeline. **Important** due to everything being awful, you must run npm and gulp from your host machine and not the VM. You must first have it installed globally: -> npm install -g gulp + +Pony.fm uses [gulp](http://gulpjs.com/) to mange its asset pipeline. + +**Important:** Run `npm` and `gulp` from your host machine and not within the VM. You must first have it installed globally: + + npm install -g gulp And then install all of the required local packages by invoking: -> npm install + + npm install Finally, build all of the scripts by executing: -> gulp build + + gulp build During development, you should make a point to run "gulp watch". You can do this simply by executing: -> gulp watch -This will watch and compile the .less and .coffee files in real time. + gulp watch + +This will watch and compile the `.less` and `.coffee` files in real time. # Configuring the servers -Pony.fm uses nginx, php-fpm, redis, and MySQL. You can modify the configuration of these services by locating the appropriate config file in the "vagrant" folder. Once modified, you must reload the configuration by running the appropriate shell script (**reload-config.sh**) or bat files (**reload-config.bat** and **reload-config.vmware.bat**). These scripts simply tell Vagrant to run "copy-and-restart-config.sh" on the VM. -If you need to change any other configuration file on the VM - copy the entire file over into the vagrant folder, make your changes, and update the "copy-and-restart-config.sh" script to copy the modified config back into the proper folder. All potential configuration requirements should be represented in the vagrant folder **and never only on the VM itself** as changes will not be preserved. +Pony.fm uses nginx, php-fpm, redis, and MySQL. You can modify the configuration of these services by locating the appropriate config file in the `vagrant` folder. Once modified, you must reload the configuration by running the appropriate shell script (`reload-config.sh`) or bat files (`reload-config.bat` and `reload-config.vmware.bat`). These scripts simply tell Vagrant to run `copy-and-restart-config.sh` on the VM. -**NOTE:** currently, Redis' configuration is not reloaded by the "copy-and-restart-config.sh" +If you need to change any other configuration file on the VM - copy the entire file over into the vagrant folder, make your changes, and update the `copy-and-restart-config.sh` script to copy the modified config back into the proper folder. All potential configuration requirements should be represented in the `vagrant` folder **and never only on the VM itself** as changes will not be preserved. + +**NOTE:** currently, Redis's configuration is not reloaded by the `copy-and-restart-config.sh` diff --git a/app/Console/Commands/BootstrapLocalEnvironment.php b/app/Console/Commands/BootstrapLocalEnvironment.php new file mode 100644 index 00000000..4eb46f41 --- /dev/null +++ b/app/Console/Commands/BootstrapLocalEnvironment.php @@ -0,0 +1,43 @@ +call('key:generate'); + $this->call('poni:api-setup'); + } +} diff --git a/app/Console/Commands/PoniverseApiSetup.php b/app/Console/Commands/PoniverseApiSetup.php new file mode 100644 index 00000000..86c4b91b --- /dev/null +++ b/app/Console/Commands/PoniverseApiSetup.php @@ -0,0 +1,97 @@ +output->getFormatter()->setStyle('bold', new OutputFormatterStyle(null, null, ['bold'])); + + $this->comment('Sign in with your Poniverse account! Your password won\'t be stored locally.'); + $this->line(''); + $this->comment('This sets up your Poniverse API credentials, which are necessary for Pony.fm\'s integration with Poniverse to work.'); + $this->line(''); + $this->comment('If you don\'t have a Poniverse account, create one at: https://poniverse.net/register'); + $username = $this->ask('Your Poniverse username'); + $password = $this->secret('Your Poniverse password'); + + // log in + $client = new Client(['base_uri' => 'https://api.poniverse.net/v1/dev/']); + + try { + $response = $client->post('api-credentials', [ + 'headers' => ['accept' => 'application/json'], + 'auth' => [$username, $password], + 'query' => ['app' => 'Pony.fm'] + ]); + + } catch (ClientException $e) { + if ($e->getResponse()->getStatusCode() === 401) { + $this->error('Incorrect username or password! Please try again.'); + exit(); + + } else { + var_dump($e->getResponse()->getBody()); + throw $e; + } + } + + $json = json_decode($response->getBody()); + $clientId = $json->id; + $clientSecret = $json->secret; + + // save new key to .env + $this->setEnvironmentVariable('PONI_CLIENT_ID', $this->laravel['config']['poniverse.client_id'], $clientId); + $this->setEnvironmentVariable('PONI_CLIENT_SECRET', $this->laravel['config']['poniverse.secret'], $clientSecret); + + $this->info('Client ID and secret set!'); + } + + + protected function setEnvironmentVariable($key, $oldValue, $newValue) { + $path = base_path('.env'); + + if (file_exists($path)) { + file_put_contents($path, str_replace( + "$key=" . $oldValue, "$key=" . $newValue, file_get_contents($path) + )); + } else { + $this->error('Please run `vagrant up`!'); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ebb5d5ef..de25ac98 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -19,6 +19,8 @@ class Kernel extends ConsoleKernel \App\Console\Commands\ClassifyMLPMA::class, \App\Console\Commands\RebuildTags::class, \App\Console\Commands\FixYearZeroLogs::class, + \App\Console\Commands\BootstrapLocalEnvironment::class, + \App\Console\Commands\PoniverseApiSetup::class, ]; /** diff --git a/composer.json b/composer.json index 8b8ea866..fed982dc 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "codescale/ffmpeg-php": "2.7.0", "kriswallsmith/assetic": "1.2.*@dev", "intouch/laravel-newrelic": "*", - "barryvdh/laravel-ide-helper": "^2.1" + "barryvdh/laravel-ide-helper": "^2.1", + "guzzlehttp/guzzle": "~6.0" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index 46e3e19d..d5427467 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "9079e8e598ee7e2caa54fdc23e02e0c1", - "content-hash": "de0cc2821022365e5f198a9e5ba3be3f", + "hash": "eddd67b3d3ba03070bfe8291aa666997", + "content-hash": "1a6fea0657cdd4d6a80389865fff8ad6", "packages": [ { "name": "barryvdh/laravel-ide-helper", @@ -324,6 +324,177 @@ ], "time": "2014-12-20 21:24:13" }, + { + "name": "guzzlehttp/guzzle", + "version": "6.1.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "66fd14b4d0b8f2389eaf37c5458608c7cb793a81" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/66fd14b4d0b8f2389eaf37c5458608c7cb793a81", + "reference": "66fd14b4d0b8f2389eaf37c5458608c7cb793a81", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "~1.0", + "guzzlehttp/psr7": "~1.1", + "php": ">=5.5.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0", + "psr/log": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.1-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2015-09-08 17:36:26" + }, + { + "name": "guzzlehttp/promises", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "97fe7210def29451ec74923b27e552238defd75a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/97fe7210def29451ec74923b27e552238defd75a", + "reference": "97fe7210def29451ec74923b27e552238defd75a", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2015-08-15 19:37:21" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/4ef919b0cf3b1989523138b60163bbcb7ba1ff7e", + "reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2015-08-15 19:32:36" + }, { "name": "intouch/laravel-newrelic", "version": "2.0.0", @@ -1098,6 +1269,55 @@ ], "time": "2015-02-03 12:10:50" }, + { + "name": "psr/http-message", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2015-05-04 20:22:00" + }, { "name": "psr/log", "version": "1.0.0", diff --git a/resources/environments/.env.local b/resources/environments/.env.local index 85eaebee..f0f884bf 100644 --- a/resources/environments/.env.local +++ b/resources/environments/.env.local @@ -18,7 +18,7 @@ MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null -PONI_CLIENT_ID=AAopdYDbn6JarV0Wo025gYQNxS1VXcj8GCa0raSC -PONI_CLIENT_SECRET=cxlA1jgGRZEPp8hg4VNB5v2gx7aY6DUtJSwUUHzT +PONI_CLIENT_ID= +PONI_CLIENT_SECRET= PONYFM_DATASTORE=/vagrant-files diff --git a/vagrant/install.sh b/vagrant/install.sh index faf76bd7..65075e29 100755 --- a/vagrant/install.sh +++ b/vagrant/install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash echo "Running apt-get update..." -sudo apt-get -qq update +#sudo apt-get -qq update echo "Installing tagging tools..." sudo apt-get -qq install -y AtomicParsley flac vorbis-tools imagemagick @@ -35,3 +35,6 @@ cp "/vagrant/resources/environments/.env.local" "/vagrant/.env" php artisan migrate php artisan db:seed + +echo "Now - if you haven't already, SSH into the VM and run \`php artisan poni:setup\`!" +echo "See the README for more details."