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

CircleCI Config with database support #4

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
version: 2

jobs:
backend:
docker:
- image: circleci/php:7.2-stretch
environment:
ag44jc7aqs2rsup2bb6cx7utc: '127.0.0.1' # 'mysql-url'
hp7wz20wu4qfbfcmqywfai1j4: tempfiles # 'mysql-user'
mom8c5hrbn8c1r5lro1imfyax: thisisonlyusedfortestinganyways # 'mysql-password'
qb1yi60nrz3tjjjqqb7l2yqra: tempfiles # 'mysql-db'
rb421p9wniz81ttj7bdgrg0ub: tempfiles # 'mysql-table'
- image: circleci/mariadb:10-bionic-ram
environment:
MYSQL_DATABASE: tempfiles
MYSQL_USER: tempfiles
MYSQL_PASSWORD: thisisonlyusedfortestinganyways
steps:
- checkout

- restore_cache:
key: composer-cache-{{ checksum "backend/composer.lock" }}

- run:
name: Composer install
command: "cd backend && composer install"

- save_cache:
paths:
- backend/vendor
key: composer-cache-{{ checksum "backend/composer.lock" }}

- run:
name: Install PHP extensions
command: sudo docker-php-ext-install -j$(nproc) mysqli

- run:
name: Install MySQL Client
command: |
sudo apt update
sudo apt install -y mysql-client

- run:
name: Waiting for Mariadb to be ready
command: |
for i in `seq 1 10`;
do
nc -z localhost 3306 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Mariadb && exit 1

- run:
name: Create database & table
command: mysql --protocol=tcp --host=localhost --port=3306 --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql


- run:
name: "Run PHP Unit Tests"
command: "cd backend && ./vendor/phpunit/phpunit/phpunit"

frontend:
docker:
- image: circleci/ruby:2
steps:
- checkout

- restore_cache:
keys:
- gem-cache-{{ checksum "frontend/Gemfile.lock" }}

- run:
name: Bundle install
command: cd frontend && bundle install --path vendor/bundle

- save_cache:
paths:
- frontend/vendor/bundle
key: gem-cache-{{ checksum "frontend/Gemfile.lock" }}

- run:
name: Build frontend
command: cd frontend && bundle exec rake proof build

# deploy:
# machine:
# enabled: true
# steps:
# - run:
# name: Trigger Webhook
# command: # curl?



workflows:
version: 2
test:
jobs:
- backend
- frontend
# - deploy:
# requires:
# - backend
# - frontend
# filters:
# branches:
# only: master
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ matrix:
include:
- language: php
php:
- 7.2
- 7.3
- "7.2"
- "7.3"
before_install:
- cd backend
install:
Expand All @@ -20,7 +20,8 @@ matrix:
- 2.4.1
cache:
bundler: true
directories: $TRAVIS_BUILD_DIR/tmp/.htmlproofer
directories:
- $TRAVIS_BUILD_DIR/tmp/.htmlproofer
before_install:
- cd frontend
script:
Expand Down
8 changes: 4 additions & 4 deletions backend/src/com/carlgo11/tempfiles/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
checkFile(__DIR__ . '/API.php');

// Load MySQL connection unless the script is run by PHPUnit.
olback marked this conversation as resolved.
Show resolved Hide resolved
if (!isset($_ENV['phpunit']))
$mysql_connection = mysqli_connect($conf['mysql-url'], $conf['mysql-user'], $conf['mysql-password'], $conf['mysql-db'])
or mySQLError($mysql_connection);
$mysql_connection = mysqli_connect($conf['mysql-url'], $conf['mysql-user'], $conf['mysql-password'], $conf['mysql-db'])
or mySQLError($mysql_connection);


/**
Expand All @@ -23,7 +22,8 @@
function mySQLError($mysql_connection) {
error_log('MySQL connection failed: ' . htmlspecialchars($mysql_connection->error));
http_response_code(500);
die("Connection to our database failed.");
die('Connection to our database failed.');
throw new Exeption('Connection to our database failed.');
}

/**
Expand Down
23 changes: 23 additions & 0 deletions backend/src/com/carlgo11/tempfiles/DataStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,27 @@ public static function uploadFile(File $file, string $password) {
}
}

// TODO: Remove. Just an example.
public static function getMariaDBVersion() {
global $mysql_connection;

try {

$query = $mysql_connection->prepare('SELECT VERSION()');

$query->execute();
$query->store_result();
$query->bind_result($version);
$query->fetch();
$query->close();

return $version;

} catch (Exception $e) {
error_log($e);
return FALSE;
}

}

}
10 changes: 5 additions & 5 deletions backend/src/com/carlgo11/tempfiles/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
return array(
# Allowed formats <n>MB, <n>GB, <n>TB, <n>PB.
'max-file-size' => '12MB',
#'mysql-url' => 'localhost',
# 'mysql-url' => 'localhost',
'mysql-url' => getenv('ag44jc7aqs2rsup2bb6cx7utc'),
#'mysql-user => 'tempfiles',
# 'mysql-user' => 'tempfiles',
'mysql-user' => getenv('hp7wz20wu4qfbfcmqywfai1j4'),
#'mysql-password' => 'password',
# 'mysql-password' => 'password',
'mysql-password' => getenv('mom8c5hrbn8c1r5lro1imfyax'),
#'mysql-db' => 'tempfiles',
# 'mysql-db' => 'tempfiles',
'mysql-db' => getenv('qb1yi60nrz3tjjjqqb7l2yqra'),
#'mysql-table' => 'files',
# 'mysql-table' => 'files',
'mysql-table' => getenv('rb421p9wniz81ttj7bdgrg0ub'),
# Encryption algorithm to use for encrypting uploads.
'Encryption-Method' => 'aes-256-gcm'
Expand Down
16 changes: 16 additions & 0 deletions backend/tests/com/carlgo11/tempfiles/DataStorageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace com\carlgo11\tempfiles;

use com\carlgo11\tempfiles;
use PHPUnit\Framework\TestCase;

class DataStorageTest extends TestCase
{

// TODO: Remove. Just an example.
public function testGetMariaDBVersion() {
$this->assertIsString(DataStorage::getMariaDBVersion());
}

}