Skip to content

Commit

Permalink
push config to installer tool for heroku apps
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpk committed Feb 1, 2020
1 parent ead2046 commit e432bfa
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
2 changes: 0 additions & 2 deletions app/Http/Controllers/HerokuController.php
Expand Up @@ -20,7 +20,6 @@ public static function authURL() {
$params = [
'response_type' => 'code',
'client_id' => env('HEROKU_CLIENT_ID'),
'redirect_uri' => route('heroku-oauth-redirect'),
'state' => $state,
'scope' => 'identity',
];
Expand Down Expand Up @@ -52,7 +51,6 @@ public function callback() {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'authorization_code',
'code' => request('code'),
'redirect_uri' => route('heroku-oauth-redirect'),
'client_id' => env('HEROKU_CLIENT_ID'),
'client_secret' => env('HEROKU_CLIENT_SECRET'),
]));
Expand Down
29 changes: 28 additions & 1 deletion app/Http/Controllers/Setup/Controller.php
Expand Up @@ -150,7 +150,7 @@ public function register_heroku_app() {
return response()->json(['error' => 'invalid app URL']);
$app_name = $match[1];

$ch = curl_init('https://meetable.org/register.php');
$ch = curl_init('https://meetable.org/heroku/register.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'name' => session('setup.app_name'),
Expand Down Expand Up @@ -242,8 +242,19 @@ public function save_config() {
}, $lines);
$heroku = implode("\n", $lines);

$heroku_app = false;
if(preg_match('~//([^\.]+)\.herokuapp\.com~', session('setup.app_url'), $match)) {
$heroku_app = $match[1];
}

session([
'setup.heroku_config' => $heroku,
'setup.heroku_app' => $heroku_app,
]);

return view('setup/heroku-config', [
'config' => $heroku,
'heroku_app' => $heroku_app,
]);
} else {

Expand All @@ -259,6 +270,22 @@ public function save_config() {
}
}

public function push_heroku_config() {
// Push the config to the configure tool and redirect there
$ch = curl_init('https://meetable.org/heroku/configure.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'app_name' => session('setup.heroku_app'),
'config' => session('setup.heroku_config'),
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = json_decode(curl_exec($ch), true);
return redirect($data['url']);
}

public function heroku_config_complete() {
return view('setup/heroku-config-complete');
}

// This is run after the environment is created so that the database settings are loaded
public function create_database() {
// Only allow this to run if the database has not already been created
Expand Down
27 changes: 27 additions & 0 deletions resources/views/setup/heroku-config-complete.blade.php
@@ -0,0 +1,27 @@
@extends('setup/layout')

@section('content')
<section class="section">

<article class="message">
<div class="message-header">
<p>Heroku Configuration</p>
</div>
<div class="message-body content">

<p>Congrats! Everything is ready and you'll be taken to your new website shortly!</p>

<a href="/" class="button is-primary is-loading">Continue</a>

</div>
</article>

</section>
<script>
setTimeout(function(){
window.location = "/";
}, 8*1000);
</script>
@endsection
16 changes: 13 additions & 3 deletions resources/views/setup/heroku-config.blade.php
Expand Up @@ -8,15 +8,25 @@
<p>Heroku Configuration</p>
</div>
<div class="message-body content">
<p>You'll need to set the following config entries for the Heroku app. You can either run the commands below, or paste the values into the application settings manually.</p>

@if($heroku_app)
<p>You'll need to set the following config entries for the Heroku app. You can run the commands below, paste the values into the application settings manually, or the installer can set these in your Heroku account automatically.</p>
@else
<p>You'll need to set the following config entries for the Heroku app. You can run the commands below or paste the values into the application settings manually.</p>
@endif

<div class="field">
<textarea class="textarea is-small" style="font-family: monospace;" rows="12">{{ $config }}</textarea>
</div>

<p>Click the button below only after you've finished setting all the config entries.</p>
@if($heroku_app)
<a href="{{ route('setup.push-heroku-config') }}" class="button is-primary">Set These For Me</a>
<a href="{{ route('setup.create-database') }}" class="button">I've Set These Myself</a>
@else
<p>Click the button below only after you've finished setting all the config entries.</p>
<a href="{{ route('setup.create-database') }}" class="button is-primary">I've Set These</a>
@endif

<a href="/setup/database" class="button is-primary">Continue</a>
</div>
</article>

Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Expand Up @@ -15,7 +15,9 @@
Route::get('/setup/auth-settings', 'Setup\Controller@auth_settings')->name('setup.auth-settings');
Route::post('/setup/auth-settings', 'Setup\Controller@save_auth_settings')->name('setup.save-auth-settings');
Route::get('/setup/save', 'Setup\Controller@save_config')->name('setup.save-config');
Route::get('/setup/push-heroku-config', 'Setup\Controller@push_heroku_config')->name('setup.push-heroku-config');
Route::get('/setup/database', 'Setup\Controller@create_database_error')->name('setup.create-database');
Route::get('/setup/heroku-complete', 'Setup\Controller@heroku_config_complete')->name('setup.heroku-config-complete');

} else {

Expand All @@ -27,6 +29,7 @@
Route::get('/setup/save', 'Setup\Controller@redirect_after_complete');
## Create the database here
Route::get('/setup/database', 'Setup\Controller@create_database')->name('setup.create-database');
Route::get('/setup/heroku-complete', 'Setup\Controller@heroku_config_complete')->name('setup.heroku-config-complete');
######


Expand Down

0 comments on commit e432bfa

Please sign in to comment.