Add docker and make support
This commit is contained in:
parent
695149c497
commit
0c0e9c3e59
|
@ -1,6 +1,9 @@
|
|||
server/composer.lock
|
||||
server/vendor
|
||||
.idea
|
||||
.jshintrc
|
||||
tests/Gemfile.lock
|
||||
server/composer.lock
|
||||
server/vendor
|
||||
server/files/
|
||||
!server/files/.gitkeep
|
||||
server/.dbdata
|
||||
server/.fakemail
|
||||
|
|
54
README.md
54
README.md
|
@ -45,48 +45,28 @@ Just as there is a `gulp dev` task for development, there is also a `gulp prod`
|
|||
3. Run `npm test` to run the tests.
|
||||
|
||||
### Getting up and running BACK-END (server folder)
|
||||
1. Install [Docker CE](https://docs.docker.com/install/)
|
||||
2. Go to the server folder: `cd opensupports/server`
|
||||
3. Run `make build` to build the images
|
||||
4. Run `make install` to install composer dependencies
|
||||
|
||||
1. Clone this repo: `git clone https://github.com/opensupports/opensupports.git`
|
||||
2. [Install PHP 5.6](https://www.dev-metal.com/install-setup-php-5-6-ubuntu-14-04-lts/)
|
||||
3. [Create MySQL Database](#markdown-header-create-mysql-database)
|
||||
4. [Install composer](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-14-04)
|
||||
5. Go to the server folder: `cd opensupports/server`
|
||||
6. Run: `composer install`
|
||||
7. Run the server with: `php -S localhost:8080`
|
||||
- `make run` runs the backend and database
|
||||
- `make stop` stop backend and database server
|
||||
- `make log` show live server logs
|
||||
- `make db` access to mysql database console
|
||||
- `make sh` access to backend docker container bash
|
||||
- `make test` run phpunit tests
|
||||
|
||||
##### Create MySQL Database
|
||||
|
||||
1. Install mysql-server:
|
||||
|
||||
Ubuntu
|
||||
|
||||
`sudo apt-get install mysql-server`
|
||||
|
||||
Cent OS
|
||||
|
||||
`sudo yum install mysql-server`
|
||||
`/etc/init.d/mysqld start`
|
||||
|
||||
2. Access the MySQL shell:
|
||||
|
||||
`mysql -u root`
|
||||
|
||||
3. Create a new database:
|
||||
|
||||
`CREATE DATABASE development;`
|
||||
|
||||
4. Run the MySQL server:
|
||||
|
||||
`sudo /etc/init.d/mysql start`
|
||||
Server api runs on `http://localhost:8080/`
|
||||
Also, there's a php server running on `http://localhost:6060/`
|
||||
|
||||
##### BACKEND API RUBY TESTING
|
||||
|
||||
1. Install Ruby: `sudo apt-get install ruby-full`
|
||||
2. Install MySQL dev dependencies: `sudo apt-get install libmysqlclient-dev libmysqlclient16 ruby-dev`
|
||||
3. Install bundle: `sudo gem install bundler`
|
||||
4. Go to tests folder: `cd opensupports/tests`
|
||||
5. Install project dependencies: `bundle install`
|
||||
Tests can run by using executing the `run-tests.sh` file.
|
||||
1. Go to tests folder: `cd opensupports/tests`
|
||||
2. Run `make install` to install ruby and its the required dependencies
|
||||
|
||||
- `make run` for running tests (database will be cleared)
|
||||
- `make clear` for clearing database
|
||||
|
||||
##### BACKEND FAKE SMTP SERVER
|
||||
If you're doing development, you can use a FakeSMTP server to see the mails that are being sent.
|
||||
|
|
|
@ -26,6 +26,7 @@ class InstallStep3Database extends React.Component {
|
|||
{this.renderMessage()}
|
||||
<Form loading={this.state.loading} onSubmit={this.onSubmit.bind(this)}>
|
||||
<FormField name="dbHost" label={i18n('DATABASE_HOST')} fieldProps={{size: 'large'}} required/>
|
||||
<FormField name="dbPort" label={i18n('DATABASE_PORT')} fieldProps={{size: 'large'}} infoMessage={i18n('DEFAULT_PORT')} required/>
|
||||
<FormField name="dbName" label={i18n('DATABASE_NAME')} fieldProps={{size: 'large'}} infoMessage={i18n('LEFT_EMPTY_DATABASE')}/>
|
||||
<FormField name="dbUser" label={i18n('DATABASE_USER')} fieldProps={{size: 'large'}} required/>
|
||||
<FormField name="dbPassword" label={i18n('DATABASE_PASSWORD')} fieldProps={{size: 'large', password: true}}/>
|
||||
|
@ -75,4 +76,4 @@ class InstallStep3Database extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default InstallStep3Database;
|
||||
export default InstallStep3Database;
|
||||
|
|
|
@ -228,6 +228,7 @@ export default {
|
|||
'USER_SYSTEM': 'User System',
|
||||
'PREVIOUS': 'Previous',
|
||||
'DATABASE_HOST': 'MySQL server',
|
||||
'DATABASE_PORT': 'MySQL server port',
|
||||
'DATABASE_NAME': 'MySQL database name',
|
||||
'DATABASE_USER': 'MySQL user',
|
||||
'DATABASE_PASSWORD': 'MySQL password',
|
||||
|
@ -359,6 +360,7 @@ export default {
|
|||
'ACTIVITY_PRIORITY_CHANGED_THIS': 'changed priority of this ticket to',
|
||||
'DATE_PREFIX': 'on',
|
||||
'LEFT_EMPTY_DATABASE': 'Leave empty for automatic database creation',
|
||||
'DEFAULT_PORT': 'Leave empty for 3306 as default',
|
||||
'REMEMBER_ME': 'Remember me',
|
||||
'EMAIL_LOWERCASE': 'email',
|
||||
'PASSWORD_LOWERCASE': 'password',
|
||||
|
|
|
@ -4,7 +4,7 @@ const SessionStore = require('lib-app/session-store');
|
|||
|
||||
function processData (data, dataAsForm = false) {
|
||||
let newData;
|
||||
|
||||
|
||||
if(dataAsForm) {
|
||||
newData = new FormData();
|
||||
|
||||
|
@ -20,7 +20,7 @@ function processData (data, dataAsForm = false) {
|
|||
csrf_userid: SessionStore.getSessionData().userId
|
||||
}, data)
|
||||
}
|
||||
|
||||
|
||||
return newData;
|
||||
}
|
||||
|
||||
|
@ -48,16 +48,16 @@ module.exports = {
|
|||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
getFileLink(filePath) {
|
||||
return apiRoot + '/system/download?file=' + filePath;
|
||||
},
|
||||
|
||||
|
||||
getAPIUrl() {
|
||||
return apiRoot;
|
||||
},
|
||||
|
||||
|
||||
getURL() {
|
||||
return root;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
.dbdata
|
||||
.fakemail
|
|
@ -0,0 +1,11 @@
|
|||
FROM fauria/lamp
|
||||
MAINTAINER Ivan Diaz <ivan@opensupports.com>
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install zip unzip php7.0-zip php7.0-mbstring -y && \
|
||||
apt-get remove --yes php7.0-snmp && \
|
||||
(curl -s https://getcomposer.org/installer | php) && \
|
||||
mv composer.phar /usr/local/bin/composer
|
||||
|
||||
RUN echo 'LISTEN 8080' >> /etc/apache2/apache2.conf
|
||||
RUN sed -i "1s/.*/<VirtualHost *:8080>/" /etc/apache2/sites-enabled/000-default.conf
|
|
@ -0,0 +1,33 @@
|
|||
red=`tput setaf 1`
|
||||
yellow=`tput setaf 3`
|
||||
reset=`tput sgr0`
|
||||
|
||||
build:
|
||||
@docker pull mysql
|
||||
@docker build -t opensupports-srv . || echo "A${red}An error occurred${reset}"
|
||||
|
||||
install:
|
||||
@docker exec -it opensupports-srv bash -c "cd /var/www/html && composer install" || echo "${red}Please execute 'make run' first${reset}"
|
||||
|
||||
run:
|
||||
@docker run -d --name opensupports-db -p 4040:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v $(PWD)/.dbdata/:/var/lib/mysql mysql
|
||||
@docker run -d --name opensupports-myadmin --link opensupports-db:db -p 6060:80 phpmyadmin/phpmyadmin
|
||||
@docker run -d --name opensupports-fakesmtp -p 7070:25 -v ${PWD}/.fakemail/:/var/mail munkyboy/fakesmtp
|
||||
@docker run -d --name opensupports-srv --net="host" --rm -e LOG_STDOUT=true -e LOG_STDERR=true -e LOG_LEVEL=debug -v ${PWD}:/var/www/html opensupports-srv
|
||||
|
||||
test:
|
||||
@./run-tests.sh
|
||||
|
||||
log:
|
||||
@docker attach opensupports-srv || echo "${red}Please execute 'make run' first${reset}"
|
||||
|
||||
stop:
|
||||
@docker stop opensupports-db && docker rm opensupports-db || true
|
||||
@docker stop opensupports-myadmin && docker rm opensupports-myadmin || true
|
||||
@docker stop opensupports-srv
|
||||
|
||||
db:
|
||||
@docker exec -it opensupports-db bash -c "mysql -u root" || echo "${red}Please execute 'make run' first${reset}"
|
||||
|
||||
sh:
|
||||
@docker exec -it opensupports-srv bash
|
|
@ -1,16 +1,6 @@
|
|||
<?php
|
||||
$env['MYSQL_SERVER'] = getenv('MYSQL_SERVER');
|
||||
$env['MYSQL_USER'] = getenv('MYSQL_USER');
|
||||
$env['MYSQL_PASSWORD'] = getenv('MYSQL_PASSWORD');
|
||||
$env['MYSQL_DATABASE'] = getenv('MYSQL_DATABASE');
|
||||
|
||||
$mysql_host = ($env['MYSQL_SERVER']) ? $env['MYSQL_SERVER'] : 'localhost';
|
||||
$mysql_user = ($env['MYSQL_USER']) ? $env['MYSQL_USER'] : 'root';
|
||||
$mysql_password = ($env['MYSQL_PASSWORD']) ? $env['MYSQL_PASSWORD'] : '';
|
||||
$mysql_database = ($env['MYSQL_DATABASE']) ? $env['MYSQL_DATABASE'] : 'development';
|
||||
|
||||
define('MYSQL_HOST', $mysql_host);
|
||||
define('MYSQL_USER', $mysql_user);
|
||||
define('MYSQL_PASSWORD', $mysql_password);
|
||||
define('MYSQL_DATABASE', $mysql_database);
|
||||
|
||||
define('MYSQL_HOST', '127.0.0.1');
|
||||
define('MYSQL_PORT', '4040');
|
||||
define('MYSQL_USER', 'root');
|
||||
define('MYSQL_PASSWORD', '');
|
||||
define('MYSQL_DATABASE', 'development');
|
||||
|
|
|
@ -44,14 +44,15 @@ class InitDatabaseController extends Controller {
|
|||
}
|
||||
|
||||
$dbHost = Controller::request('dbHost');
|
||||
$dbPort = Controller::request('dbPort');
|
||||
$dbName = Controller::request('dbName');
|
||||
$dbUser = Controller::request('dbUser');
|
||||
$dbPass = Controller::request('dbPassword');
|
||||
|
||||
RedBean::setup('mysql:host=' . $dbHost, $dbUser, $dbPass);
|
||||
RedBean::setup("mysql:host=$dbHost;port=$dbPort", $dbUser, $dbPass);
|
||||
|
||||
if($dbName) {
|
||||
RedBean::addDatabase($dbName, 'mysql:host='. $dbHost . ';dbname=' . $dbName, $dbUser, $dbPass);
|
||||
RedBean::addDatabase($dbName, "mysql:host=$dbHost;port=$dbPort;dbname=$dbName", $dbUser, $dbPass);
|
||||
RedBean::selectDatabase($dbName);
|
||||
|
||||
if(!RedBean::testConnection()) {
|
||||
|
@ -60,7 +61,7 @@ class InitDatabaseController extends Controller {
|
|||
} else {
|
||||
$dbName = 'opensupports_' . Hashing::generateRandomNumber(100, 999);
|
||||
RedBean::exec('CREATE DATABASE ' . $dbName);
|
||||
RedBean::addDatabase($dbName, 'mysql:host='. $dbHost . ';dbname=' . $dbName, $dbUser, $dbPass);
|
||||
RedBean::addDatabase($dbName, "mysql:host=$dbHost;port=$dbPort;dbname=$dbName", $dbUser, $dbPass);
|
||||
RedBean::selectDatabase($dbName);
|
||||
|
||||
if(!RedBean::testConnection()) {
|
||||
|
@ -71,6 +72,7 @@ class InitDatabaseController extends Controller {
|
|||
$configFile = fopen('config.php', 'w+') or die(ERRORS::INVALID_FILE);
|
||||
$content = '<?php' . PHP_EOL;
|
||||
$content .= 'define(\'MYSQL_HOST\', \'' . $dbHost . '\');' . PHP_EOL;
|
||||
$content .= 'define(\'MYSQL_PORT\', \'' . $dbPort . '\');' . PHP_EOL;
|
||||
$content .= 'define(\'MYSQL_USER\', \'' . $dbUser . '\');' . PHP_EOL;
|
||||
$content .= 'define(\'MYSQL_PASSWORD\', \'' . $dbPass . '\');' . PHP_EOL;
|
||||
$content .= 'define(\'MYSQL_DATABASE\', \'' . $dbName . '\');' . PHP_EOL;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
@include 'config.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
|
@ -6,7 +7,8 @@ require_once 'vendor/autoload.php';
|
|||
use RedBeanPHP\Facade as RedBean;
|
||||
|
||||
if(defined('MYSQL_HOST') && defined('MYSQL_DATABASE') && defined('MYSQL_USER') && defined('MYSQL_PASSWORD')) {
|
||||
RedBean::setup('mysql:host='. MYSQL_HOST .';dbname=' . MYSQL_DATABASE , MYSQL_USER, MYSQL_PASSWORD);
|
||||
if(!defined('MYSQL_PORT')) define('MYSQL_PORT', '3306');
|
||||
RedBean::setup('mysql:host='. MYSQL_HOST . ';port=' . MYSQL_PORT . ';dbname=' . MYSQL_DATABASE , MYSQL_USER, MYSQL_PASSWORD);
|
||||
RedBean::setAutoResolve(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
bacon (1.2.0)
|
||||
domain_name (0.5.20170404)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
http-cookie (1.0.3)
|
||||
domain_name (~> 0.5)
|
||||
mechanize (2.7.5)
|
||||
domain_name (~> 0.5, >= 0.5.1)
|
||||
http-cookie (~> 1.0)
|
||||
mime-types (>= 1.17.2)
|
||||
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
||||
net-http-persistent (~> 2.5, >= 2.5.2)
|
||||
nokogiri (~> 1.6)
|
||||
ntlm-http (~> 0.1, >= 0.1.1)
|
||||
webrobots (>= 0.0.9, < 0.2)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mini_portile2 (2.1.0)
|
||||
mysql (2.9.1)
|
||||
net-http-digest_auth (1.4.1)
|
||||
net-http-persistent (2.9.4)
|
||||
nokogiri (1.6.8.1)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
ntlm-http (0.1.1)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.7.5)
|
||||
webrobots (0.1.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
bacon
|
||||
mechanize
|
||||
mysql
|
||||
|
||||
BUNDLED WITH
|
||||
1.16.1
|
|
@ -0,0 +1,14 @@
|
|||
DB_HOST ?= `docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' opensupports-db`
|
||||
|
||||
install:
|
||||
@apt-get install ruby-full
|
||||
@apt-get install libmysqlclient-dev libmysqlclient16 ruby-dev
|
||||
@gem install bundler
|
||||
@bundle install
|
||||
|
||||
run:
|
||||
./run-tests.sh
|
||||
|
||||
|
||||
clear:
|
||||
./clean_db.sh
|
|
@ -1,9 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# DELETE ALL TABLES
|
||||
TABLES=$(mysql -u root development -e "SHOW TABLES IN development;" | awk '{ print $1}' | grep -v '^Tables')
|
||||
TABLES=$(mysql --host 127.0.0.1 --port 4040 -u root development -e "SHOW TABLES IN development;" | awk '{ print $1}' | grep -v '^Tables')
|
||||
|
||||
for t in $TABLES
|
||||
do
|
||||
mysql -u root development -e "DROP TABLE $t"
|
||||
mysql --host 127.0.0.1 --port 4040 -u root development -e "DROP TABLE $t"
|
||||
done
|
||||
|
|
|
@ -21,9 +21,10 @@ end
|
|||
|
||||
class Database
|
||||
def initialize()
|
||||
mysqlHost = ENV['MYSQL_HOST'] || '127.0.0.1'
|
||||
mysqlUser = ENV['MYSQL_USER'] || 'root'
|
||||
mysqlPass = ENV['MYSQL_PASSWORD'] || ''
|
||||
@connection = Mysql.new('localhost', mysqlUser , mysqlPass, 'development')
|
||||
@connection = Mysql.new(mysqlHost, mysqlUser, mysqlPass, 'development', 4040)
|
||||
end
|
||||
|
||||
def close()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
./clean_db.sh
|
||||
./clean_db.sh
|
||||
./clean_db.sh
|
||||
bacon init.rb
|
||||
bacon init.rb
|
||||
|
|
|
@ -25,9 +25,9 @@ describe '/system/init-settings' do
|
|||
'language' => 'en'
|
||||
})
|
||||
|
||||
lang = $database.getRow('setting', 'language', 'name')
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
lang = $database.getRow('setting', 'language', 'name')
|
||||
(lang['value']).should.equal('en')
|
||||
|
||||
result = request('/system/init-admin', {
|
||||
|
|
Loading…
Reference in New Issue