Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'Deploy to Heroku' button #1285

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/npm-gulp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Package easyappointments

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Build
run: |
npm install
npm run package
env:
GIT_COMMIT_SHA: ${{ steps.vars.outputs.sha_short }}

- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: easy-appointments-${{ steps.vars.outputs.sha_short }}
path: easyappointments*.tar.gz
40 changes: 40 additions & 0 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run PHP tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php-version: [7.4]

steps:
- uses: actions/checkout@v3

- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php-version }}
php_extensions: gd

- name: Fullfil prerequisites
run: |
cp config-sample.php config.php

# Disabling because this does not currently work
# - name: Perform tests
# uses: php-actions/composer@v6
# with:
# command: test
40 changes: 40 additions & 0 deletions .profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
replace_in_config() {
key="$1"
value="$2"
sed -i -r "s|(${key}\s+)=.+\$|\1= '${value}';|" /app/build/config.php
}

# Parse MySQL_URL
protocol="$(echo "$MYSQL_URL" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
url="$(echo ${MYSQL_URL/$protocol/})"

# extract the credentials
userpass="$(echo $url | grep @ | cut -d@ -f1)"
password="$(echo $userpass | grep : | cut -d: -f2)"

if [ -n "$password" ]; then
# We received a password, so split to retrieve the username
username="$(echo $userpass | grep : | cut -d: -f1)"
else
# Username has been supplied, no password
username=$userpass
fi

# extract the host
host="$(echo ${url/$user@/} | cut -d/ -f1 | rev | cut -d':' -f2- | rev)"

# Remove credentials from the host if present
basename="$(echo ${host#"$userpass"})"
# extract the path
path="$(echo $url | grep / | cut -d/ -f2-)"

if [ ! -f "/app/build/config.php" ]; then
cp /app/build/config-sample.php /app/build/config.php
echo "Created /app/build/config.php"
fi

replace_in_config "BASE_URL" "$BASE_URL"
replace_in_config "DB_HOST" "$basename"
replace_in_config "DB_NAME" "$path"
replace_in_config "DB_USERNAME" "$username"
replace_in_config "DB_PASSWORD" "$password"
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: heroku-php-apache2 build
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<a href="https://discord.com/invite/UeeSkaw">
<img alt="Chat On Discord" src="https://img.shields.io/badge/chat-on%20discord-7289da?style=for-the-badge&logo=discord&logoColor=white">
</a>
<a href="https://heroku.com/deploy">
<img src="https://www.herokucdn.com/deploy/button.svg" alt="Deploy">
</a>

</p>

<p align="center">
Expand Down Expand Up @@ -74,7 +78,7 @@ $ npm start

Note: If you're using Linux Bash for Windows, [see this guide](https://www.howtogeek.com/261575/how-to-run-graphical-linux-desktop-applications-from-windows-10s-bash-shell/) or use `node` from the command prompt.

You can build the files by running `npm run build`. This command will bundle everything to a `build` directory.
You can build the files by running `composer install; npm run build`. This command will bundle everything to a `build` directory.

## Installation

Expand Down
53 changes: 53 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "Easy!Appointments",
"description": "Allow customers to book appointments with you via a highly customizable and sophisticated web application",
"repository": "https://github.com/daneov/easyappointments",
"logo": "https://raw.githubusercontent.com/alextselegidis/easyappointments/develop/logo.png",
"keywords": ["node", "php", "calendar"],
"addons": [
{
"plan": "jawsdb:kitefin",
"as": "MySQL"
},
{
"plan": "papertrail:choklad"
}
],
"env": {
"BASE_URL": {
"description": "The domain the site is accessible on",
"required": true,
"value": "https://<app-name>.herokuapp.com"
},
"MAIL_SMTP_SERVER": {
"description": "SMTP server used to send emails",
"required": true,
"value": "smtp.gmail.com"
},
"MAIL_SMTP_LOGIN": {
"description": "Username for the SMTP server",
"required": true,
"value": "@gmail.com"
},
"MAIL_SMTP_PASSWORD": {
"description": "App or account password for the SMTP server",
"required": true,
"value": ""
},
"MAIL_SMTP_PORT": {
"description": "Port to use for the SMTP connection. Must match SMTP_ENCRYPTION",
"required": false,
"value": "587"
},
"MAIL_SMTP_ENCRYPTION": {
"description": "Encrypt the SMTP connection using either 'tls' or 'ssl'",
"required": false,
"value": "tls"
}
},
"buildpacks": [{
"url": "heroku/php"
},{
"url": "heroku/nodejs"
}]
}
14 changes: 7 additions & 7 deletions application/config/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// @link https://codeigniter.com/user_guide/libraries/email.html

$config['useragent'] = 'Easy!Appointments';
$config['protocol'] = 'mail'; // or 'smtp'
$config['protocol'] = 'smtp'; // or 'smtp'
$config['mailtype'] = 'html'; // or 'text'
// $config['smtp_debug'] = '0'; // or '1'
// $config['smtp_auth'] = TRUE; //or FALSE for anonymous relay.
// $config['smtp_host'] = '';
// $config['smtp_user'] = '';
// $config['smtp_pass'] = '';
// $config['smtp_crypto'] = 'ssl'; // or 'tls'
// $config['smtp_port'] = 25;
$config['smtp_auth'] = TRUE; //or FALSE for anonymous relay.
$config['smtp_host'] = $_ENV['MAIL_SMTP_SERVER'] ?? '';
$config['smtp_user'] = $_ENV['MAIL_SMTP_LOGIN'] ?? '';
$config['smtp_pass'] = $_ENV['MAIL_SMTP_PASSWORD'] ?? '';
$config['smtp_crypto'] = $_ENV['MAIL_SMTP_ENCRYPTION'] ?? 'tls'; // 'tls' or 'ssl'
$config['smtp_port'] = $_ENV['MAIL_SMTP_PORT'] ?? 587;
91 changes: 91 additions & 0 deletions application/core/EA_Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php if ( ! defined('BASEPATH') ) exit('No direct script access allowed');

// this class is adapted from system/libraries/Log.php
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
* @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/

// ------------------------------------------------------------------------

/**
* Logging Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Logging
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/general/errors.html
*/
class EA_Log {

protected $_threshold = 1;
protected $_date_fmt = 'Y-m-d H:i:s';
protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4');

/**
* Constructor
*/
public function __construct()
{
$config =& get_config();

if (is_numeric($config['log_threshold']))
{
$this->_threshold = $config['log_threshold'];

}

if ($config['log_date_format'] != '')
{
$this->_date_fmt = $config['log_date_format'];

}

}

// --------------------------------------------------------------------

/**
* Write Log to php://stderr
*
* Generally this function will be called using the global log_message() function
*
* @param string the error level
* @param string the error message
* @param bool whether the error is a native PHP error
* @return bool
*/
public function write_log($level = 'error', $msg, $php_error = FALSE)
{
$level = strtoupper($level);

if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold) )
{
return FALSE;

}

file_put_contents('php://stderr', $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n");

return TRUE;

}


}
// END Log Class

/* End of file EA_Log.php */
/* Location: ./application/core/EA_Log.php */
?>
47 changes: 30 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// Gulp instance and plugins.
const gulp = require('gulp');
const fs = require('fs-extra');
const zip = require('zip-dir');
const tar = require('gulp-tar');
const gzip = require('gulp-gzip');
const plugins = require('gulp-load-plugins')();
const {execSync} = require('child_process');
const del = require('del');
Expand All @@ -26,11 +27,8 @@ gulp.src = function () {
}));
};

gulp.task('package', (done) => {
const archive = 'easyappointments-0.0.0.zip';

gulp.task('build', (done) => {
fs.removeSync('build');
fs.removeSync(archive);

fs.mkdirsSync('build');
fs.copySync('application', 'build/application');
Expand Down Expand Up @@ -66,10 +64,15 @@ gulp.task('package', (done) => {
fs.copySync('README.md', 'build/README.md');
fs.copySync('LICENSE', 'build/LICENSE');

execSync('cd build && composer install --no-interaction --no-dev --no-scripts --optimize-autoloader', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
if (process.env['CI'] === "true") {
execSync('cd build && composer install --no-interaction --no-dev --no-scripts --optimize-autoloader', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
} else {
// Assuming composer has already been run, copying binaries into build directory
fs.copySync('vendor/', 'build/vendor');
}

del.sync('**/.DS_Store');

Expand All @@ -79,15 +82,23 @@ gulp.task('package', (done) => {

del.sync('build/vendor/codeigniter/framework/user_guide');

zip('build', {saveTo: archive}, function (err) {
if (err) {
console.log('Zip Error', err);
}

done();
});
done();
});

gulp.task('package', (done) => {
const sha = process.env['GIT_COMMIT_SHA']
const version = !!sha ? sha : Date.now();
const archive = `easyappointments-${version}.tar`;


gulp.src('build/*')
.pipe(tar(archive))
.pipe(gzip())
.pipe(gulp.dest('.'));

done();
})

gulp.task('clean', (done) => {
fs.removeSync('assets/js/**/*.min.js');
fs.removeSync('assets/css/**/*.min.css');
Expand Down Expand Up @@ -161,6 +172,8 @@ gulp.task('watch', (done) => {

gulp.task('dev', gulp.series('clean', 'scripts', 'styles', 'watch'));

gulp.task('build', gulp.series('clean', 'scripts', 'styles', 'package'));
gulp.task('build', gulp.series('clean', 'scripts', 'styles', 'build'));

gulp.task('package', gulp.series('clean', 'scripts', 'styles', 'build', 'package'));

gulp.task('default', gulp.parallel('dev'));