Skip to content

Commit

Permalink
Changed to using .yml files for config (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank authored Nov 23, 2016
1 parent b32455f commit b9d9ca2
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 85 deletions.
13 changes: 0 additions & 13 deletions .env.example

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data/logs/*
data/sessions/*
!data/sessions/.gitkeep
/vendor/
.env
/app/config/parameters.yml
composer.phar
phinx.yml
.DS_Store
Expand Down
100 changes: 60 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,10 @@ You should have [Composer](http://getcomposer.org) installed and available. If y

You will need to navigate to the URL in a browser, authenticate with GitHub, and generate the access token.

6. From the same directory, run `vendor/bin/phinx init` to generate a `phinx.yml` file.
7. Edit `/var/www/phinx.yml`:

In the `paths` section, set the `migrations` value to:

```{.yaml}
migrations: %%PHINX_CONFIG_DIR%%/data/migrations
```
In the `development` section, set the following MySQL credentials:
```{.yaml}
name: scotchbox
user: root
pass: root
```
6. [Configure Phinx](#phinx-configuration)
9. Run `vendor/bin/phinx migrate` to run the database migrations.
10. Copy `.env.example` to `.env`
11. Create a new Github Application at <https://github.com/settings/applications/new>
- Set the **Homepage** and **Authorization callback URL** to <http://mentoring.dev>
10. Update your `.env` file and set the `GITHUB_API_KEY` and `GITHUB_API_SECRET` to the Client ID and Client Secret for your app.
10. Copy `app/config/parameters.yml.dist` to `app/config/parameters.yml` and configure for your setup
11. [Configure Github](#github)
13. Visit <http://mentoring.dev> in your browser!

#### Running Without Vagrant
Expand All @@ -67,43 +49,71 @@ Steps:

127.0.0.1 www.mentoring.dev mentoring.dev

3. Change directory to the directory where you cloned the project in step 1 and run `composer install`
4. Copy `.env.example` to `.env`
5. From the same directory, run `vendor/bin/phinx init` to generate a `phinx.yml` file.
6. Edit `./phinx.yml`'s development section (lines 19-21) with the following values for MySQL.
4. Copy `app/config/parameters.yml.dist` to `app/config/parameters.yml` and configure for your setup
5. [Configure Phinx](#phinx-configuration)
8. Run `vendor/bin/phinx migrate` to run the database migrations.
9. [Configure Github](#github)
11. To run using PHP's built-in server, navigate to the root of the project and run:

php -S mentoring.dev:8080 -t public public/index.php

12. Visit <http://mentoring.dev:8080> in your browser!

### Phinx Configuration

We use [Phinx](https://phinx.org/) for managing our database migrations. It provides a programmatic way for handling
table and data changes. It does require some initial setup however.

1. From the root project directory, run `vendor/bin/phinx init` to generate a `phinx.yml` file.
2. Edit `./phinx.yml`'s development section (lines 19-21) with the following values for MySQL.

```{.yaml}
name: mentoring
user: mentoring
pass: vagrant
```
To use sqlite, in `./phinx.yml` change change the adapter to `sqlite` (line 17) the name (line 19) to `data/mentoring.db`. In `.env` change `DB_DRIVER` to `pdo_sqlite` on line 1.
To use sqlite, in `./phinx.yml` change change the adapter to `sqlite` (line 17) the name (line 19) to `data/mentoring.db`.
7. Edit `./phinx.yml`'s `paths.migrations` value (line 2) to:
3. Edit `./phinx.yml`'s `paths.migrations` value (line 2) to:
```
%%PHINX_CONFIG_DIR%%/data/migrations
```
8. Run `vendor/bin/phinx migrate` to run the database migrations.
9. Create a new Github Application at <https://github.com/settings/applications/new>
- Set the **Homepage** and **Authorization callback URL** to <http://mentoring.dev:8080>
10. Update your `.env` file and set the `GITHUB_API_KEY` and `GITHUB_API_SECRET` to the Client ID and Client Secret for your app.
11 To run using PHP's built-in server, navigate to the root of the project and run:
php -S mentoring.dev:8080 -t public public/index.php
12. Visit <http://mentoring.dev:8080> in your browser!
### App Configuration
All configuration is store in `app/config/parameters.yml`. The app ships with a `.dist` version that you will need to
copy/paste into the above path. You can then edit it to your needs.
#### Github
The application uses Github for authentication. If you are developing or working
on features that require a user login, you will need to set up a new Github Application
to generate a secret and a key.
### Email in Development
Instructions for doing this are available at <https://github.com/settings/applications/new>.
Before you start the VM, you need to change your .env file. To use mailcatcher, you'll want the following config:
Set the **Homepage** and **Authorization callback URL** to <http://mentoring.dev:8080> or <http://mentoring.dev>, depending on how you set up your `hosts` file.
MAIL_HOST=0.0.0.0
MAIL_PORT=1025
Once you have that completed, you will need to add them to the `parameters.yml` file, like this:
```{.yaml}
github:
api_key: 'keyfromgithub'
api_secret: 'secretfromgithub'
```

#### Email in Development

Before you start the VM, you need to change your `parameters.yml` file. To use mailcatcher, you'll want the following config:

```{.yaml}
mail:
host: '0.0.0.0'
port: 1025
```

Mailcatcher is installed in the VM, but to use it you need to ssh into the VM and execute the following command to start the mail server:

Expand All @@ -112,3 +122,13 @@ Mailcatcher is installed in the VM, but to use it you need to ssh into the VM an
You can then view all emails being sent out by the app in your host machine's browser at the following address:

`http://192.168.56.101:1080`

#### Database Configuration

This app uses the [Doctrine DBAL](http://silex.sensiolabs.org/doc/master/providers/doctrine.html) as it's underlying
database layer, so you can configure the database using the options in the Silex documentation.

Explicitly, we support MySQL and it's dialect of SQL. Others may work, like SQLite for development environments, but
most of the code is written with MySQL in mind.

You can configure the database settings under the `database:` key.
16 changes: 16 additions & 0 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
database:
driver: 'pdo_mysql'
host: 'localhost'
dbname: 'scotchbox'
user: 'root'
password: 'root'

mail:
host: 'localhost'
port: 25
username: ''
password: ''

github:
api_key: 'changeme'
api_secret: 'changeme'
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"swiftmailer/swiftmailer": "^5.4",
"symfony/config": "^3.1",
"symfony/security-csrf": "^3.1",
"mockery/mockery": "^0.9.5"
"mockery/mockery": "^0.9.5",
"rpodwika/yaml-config-service-provider": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "4.6.*",
Expand Down
43 changes: 41 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 3 additions & 26 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,17 @@

use Silex\Application;
use Silex\Provider;
use Dotenv\Dotenv;

$dotenv = new Dotenv(__DIR__ . '/../');
$dotenv->load();

$mySqlOptions = [
'driver' => 'pdo_mysql',
'host' => getenv('DB_HOSTNAME'),
'dbname' => getenv('DB_DBNAME'),
'user' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
];

$sqliteOptions = [
'driver' => 'pdo_sqlite',
'path' => 'data/mentoring.db',
];

$dbOptions = (getenv('DB_DRIVER') == 'pdo_mysql' ? $mySqlOptions : $sqliteOptions);

$app = new Application();
$app['debug'] = true;

$app->register(new \Rpodwika\Silex\YamlConfigServiceProvider(__DIR__ . '/../app/config/parameters.yml'));
$app->register(new Provider\SessionServiceProvider());
$app->register(new Provider\ServiceControllerServiceProvider());
$app->register(new Provider\RoutingServiceProvider());

$app->register(new Provider\SwiftmailerServiceProvider(), [
'swiftmailer.options' => [
'host' => getenv('MAIL_HOST') ?: 'localhost',
'port' => getenv('MAIL_PORT') ?: 25,
'username' => getenv('MAIL_USERNAME') ?: '',
'password' => getenv('MAIL_PASSWORD') ?: '',
],
'swiftmailer.options' => $app['config']['mail'],
'swiftmailer.use_spool' => false
]);

Expand Down Expand Up @@ -70,7 +47,7 @@
]);

$app->register(new Silex\Provider\DoctrineServiceProvider(), [
'db.options' => $dbOptions
'db.options' => $app['config']['database'],
]);

$taxonomyServiceProvider = new \Mentoring\Taxonomy\ServiceProvider\TaxonomyServiceProvider();
Expand Down
4 changes: 2 additions & 2 deletions src/Mentoring/Auth/Controller/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ protected function getUserEmails(Github $provider, AccessToken $token)

public function githubAction(Application $app, Request $request)
{
$clientID = getenv('GITHUB_API_KEY');
$clientSecret = getenv('GITHUB_API_SECRET');
$clientID = $app['config']['github']['api_key'];
$clientSecret = $app['config']['github']['api_secret'];
$code = $request->query->get('code');

$redirectUri = $request->getScheme() . '://' .$request->getHost();
Expand Down

0 comments on commit b9d9ca2

Please sign in to comment.