From d4e2129ca2603b23e880c25ce9d76797cf7dfba0 Mon Sep 17 00:00:00 2001 From: Lewis Cowles Date: Tue, 28 Jan 2020 19:58:52 +0000 Subject: [PATCH] Heroku button --- .env.example | 2 + Procfile | 1 + README.md | 2 + app.json | 101 +++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 3 ++ composer.lock | 49 ++++++++++++++++++++++- heroku.yml | 3 ++ lib/helpers.php | 24 +++++++++-- public/.htaccess | 3 ++ public/index.php | 2 +- 10 files changed, 183 insertions(+), 7 deletions(-) create mode 100644 Procfile create mode 100644 app.json create mode 100644 heroku.yml create mode 100644 public/.htaccess diff --git a/.env.example b/.env.example index 2a4cde5..b654f54 100644 --- a/.env.example +++ b/.env.example @@ -19,3 +19,5 @@ GITHUB_CLIENT_SECRET= TWITTER_CLIENT_ID= TWITTER_CLIENT_SECRET= + +REDIS_URL=tcp://127.0.0.1:6379 diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..48aab52 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: vendor/bin/heroku-php-apache2 public/ diff --git a/README.md b/README.md index 90091e6..3b1fdb0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ IndieLogin ========== +[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) + IndieLogin enables users to sign in with their domain name by linking their domain name to existing authentication providers. diff --git a/app.json b/app.json new file mode 100644 index 0000000..a7bb633 --- /dev/null +++ b/app.json @@ -0,0 +1,101 @@ +{ + "name": "Indielogin", + "description": "Deploy Indielogin to heroku", + "repository": "https://github.com/aaronpk/indielogin.com", + "logo": "https://github.com/aaronpk/indielogin.com/raw/master/public/icons/android-chrome-512x512.png", + "website": "https://indielogin.com", + "keywords": ["indielogin", "nginx", "php", "indieauth"], + "addons": [ + "heroku-redis", + { + "plan": "cleardb:ignite" + } + ], + "env": { + "BASE_URL": { + "description": "The base URL of your application including port", + "value": "", + "required": false + }, + "APP_NAME": { + "description": "The application name", + "value": "IndieLogin.com", + "required": false + }, + "DB_HOST": { + "description": "MySQL database Host (include port if necesarry)", + "value": "", + "required": false + }, + "DB_USER": { + "description": "MySQL database username", + "value": "", + "required": false + }, + "DB_PASS": { + "description": "MySQL database password", + "value": "", + "required": false + }, + "DB_NAME": { + "description": "MySQL database name", + "value": "", + "required": false + }, + "HTTP_USER_AGENT": { + "description": "User Agent", + "value": "Indielogin (heroku)" + }, + "GITHUB_CLIENT_ID": { + "description": "Client ID for GitHub API requests", + "value": "", + "required": false + }, + "GITHUB_CLIENT_SECRET": { + "description": "Client Secret for GitHub API requests", + "value": "", + "required": false + }, + "TWITTER_CLIENT_ID": { + "description": "Client ID for Twitter API requests", + "value": "", + "required": false + }, + "TWITTER_SECRET_SECRET": { + "description": "Client Secret for Twitter API requests", + "value": "", + "required": false + }, + "MAILGUN_KEY": { + "description": "Mailgun Key for sending emails", + "value": "", + "required": false + }, + "MAILGUN_DOMAIN": { + "description": "Mailgun Domain to send emails from", + "value": "", + "required": false + }, + "MAILGUN_FROM": { + "description": "Mailgun From email address", + "value": "", + "required": false + }, + "PGP_VERIFICATION_API": { + "description": "PGP Verification API URL", + "value": "", + "required": false + } + }, + "formation": { + "web": { + "quantity": 1, + "size": "free" + } + }, + "buildpacks": [ + { + "url": "heroku/php" + } + ] +} diff --git a/composer.json b/composer.json index 94b47ad..b6136d9 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,9 @@ "michelf/php-markdown": "^1.8", "vlucas/phpdotenv": "^4.1" }, + "require-dev": { + "heroku/heroku-buildpack-php": "*" + }, "autoload": { "psr-4": { "App\\": "app/" diff --git a/composer.lock b/composer.lock index f37e61a..1879ee0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1b6b6fb8d951a7f1bef5dff12fe39417", + "content-hash": "0cdf878dd690d689cd26dec7435029be", "packages": [ { "name": "abraham/twitteroauth", @@ -2055,7 +2055,52 @@ "time": "2018-05-29T16:53:08+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "heroku/heroku-buildpack-php", + "version": "v169", + "source": { + "type": "git", + "url": "https://github.com/heroku/heroku-buildpack-php.git", + "reference": "e87b635929a8b51c6f2d459cde1a241e478d3d04" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/heroku/heroku-buildpack-php/zipball/e87b635929a8b51c6f2d459cde1a241e478d3d04", + "reference": "e87b635929a8b51c6f2d459cde1a241e478d3d04", + "shasum": "" + }, + "bin": [ + "bin/heroku-hhvm-apache2", + "bin/heroku-hhvm-nginx", + "bin/heroku-php-apache2", + "bin/heroku-php-nginx" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "David Zuelke", + "email": "dz@heroku.com" + } + ], + "description": "Toolkit for starting a PHP application locally, with or without foreman, using the same config for PHP/HHVM and Apache2/Nginx as on Heroku", + "homepage": "https://github.com/heroku/heroku-buildpack-php", + "keywords": [ + "apache", + "apache2", + "foreman", + "heroku", + "hhvm", + "nginx", + "php" + ], + "time": "2020-01-26T11:19:01+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/heroku.yml b/heroku.yml new file mode 100644 index 0000000..2b8f79b --- /dev/null +++ b/heroku.yml @@ -0,0 +1,3 @@ +build: + docker: + web: Dockerfile \ No newline at end of file diff --git a/lib/helpers.php b/lib/helpers.php index 6d7674a..2f1e49c 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -17,13 +17,29 @@ } function initdb() { - if(!empty(getenv('DB_HOST'))) { - ORM::configure('mysql:host=' . getenv('DB_HOST') . ';dbname=' . getenv('DB_NAME')); - ORM::configure('username', getenv('DB_USER')); - ORM::configure('password', getenv('DB_PASS')); + $db_env = array_filter( + [ + getenv('DATABASE_URL'), + getenv('JAWSDB'), + getenv('CLEARDB_DATABASE_URL') + ], function($val) { return !empty($val); } + ); + if(!empty($db_env)) { + $mysql = parse_url(current($db_env)); + setupDB($mysql['host'], $mysql['user'], $mysql['pass'], basename($mysql['path']), @$mysql['port']); + } elseif(!empty(getenv('DB_HOST'))) { + setupDB(getenv('DB_HOST'), getenv('DB_USER'), getenv('DB_PASS'), getenv('DB_NAME'), getenv('DB_PORT')); } } +function setupDB($host, $user, $pass, $dbname, $port='') { + $portstr = strlen($port) > 0 ? ":${port}" : ''; + ORM::configure("mysql:host=${host};dbname=${dbname}"); + ORM::configure('username', $user); + ORM::configure('password', $pass); + define('DB_SETUP', true); +} + function make_logger($channel) { $log = new Logger($channel); $log->pushHandler(new StreamHandler(dirname(__FILE__).'/../logs/app.log', Logger::DEBUG)); diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..a7b90e2 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^ index.php [QSA,L] \ No newline at end of file diff --git a/public/index.php b/public/index.php index e7907b6..51a5094 100644 --- a/public/index.php +++ b/public/index.php @@ -44,7 +44,7 @@ $templates = new League\Plates\Engine(dirname(__FILE__).'/../views'); // Check for existence of config variables, and show an error page if not set -if(empty(getenv('APP_NAME')) || empty(getenv('DB_HOST'))) { +if(empty(getenv('APP_NAME')) || !defined('DB_SETUP')) { echo view('setup-error', [ 'title' => 'Setup Error', ]);