diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..a144be10 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +sudo: required + +env: + global: + - ORACLE_COOKIE=sqldev + - ORACLE_FILE=oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip + - ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe + - NLS_LANG=AMERICAN_AMERICA.AL32UTF8 + - ORACLE_BASE=/u01/app/oracle + - LD_LIBRARY_PATH=$ORACLE_HOME/lib + - PATH=$PATH:$ORACLE_HOME/jdbc/lib + - DATABASE_VERSION=11.2.0.2 + - ORACLE_SID=XE + - DATABASE_NAME=XE + - ORA_SDTZ='Europe/London' #Needed as a client parameter + - TZ='Europe/London' #Needed as a DB Server parameter + +before_install: + - chmod +x .travis/oracle/download.sh + - chmod +x .travis/oracle/install.sh + - chmod +x .travis/setup_accounts.sh + +install: + - .travis/oracle/download.sh + - .travis/oracle/install.sh + - .travis/setup_accounts.sh + - bundle install + +language: ruby +rvm: + - 2.3.0 + - 2.2.4 + - 1.9.3 + - jruby-1.7.9 + - jruby-9.0.4.0 diff --git a/.travis/oracle/LICENSE b/.travis/oracle/LICENSE new file mode 100644 index 00000000..58e4b751 --- /dev/null +++ b/.travis/oracle/LICENSE @@ -0,0 +1,5 @@ +Copyright (c) 2013, Christopher Bandy + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/.travis/oracle/README.md b/.travis/oracle/README.md new file mode 100644 index 00000000..5bdfbdb1 --- /dev/null +++ b/.travis/oracle/README.md @@ -0,0 +1,64 @@ +[![Build](https://travis-ci.org/cbandy/travis-oracle.svg?branch=master)](https://travis-ci.org/cbandy/travis-oracle) + +Use [Oracle Database Express Edition][] in your builds on [Travis CI][]. + +[Oracle Database Express Edition]: http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html +[Travis CI]: https://travis-ci.org/ + + +Usage +----- + +To use this tool, you must have an Oracle account with which you have accepted +the current license agreement for [Oracle Database Express Edition][]. + +1. Add your Oracle username and password to your build [environment variables][], + either as hidden repository settings or encrypted variables: + + | Variable Name | Value | + | -------------------------- | ------------- | + | `ORACLE_LOGIN_ssousername` | your username | + | `ORACLE_LOGIN_password` | your password | + +2. Add the version information to your build environment variables: + + ```yaml + - ORACLE_COOKIE=sqldev + - ORACLE_FILE=oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip + - ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe + - ORACLE_SID=XE + ``` + +3. Download and extract the [latest release][] into your project. For example, + + ```shell + wget 'https://github.com/cbandy/travis-oracle/archive/v2.0.0.tar.gz' + mkdir -p .travis/oracle + tar xz --strip-components 1 -C .travis/oracle -f v2.0.0.tar.gz + ``` + +4. Enable [`sudo`](https://docs.travis-ci.com/user/workers/standard-infrastructure/): + + ```yaml + sudo: required + ``` + +5. Finally, execute the extracted scripts as part of your build, usually + during [`before_install`](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle): + + ```yaml + - .travis/oracle/download.sh + - .travis/oracle/install.sh + ``` + +[SQL\*Plus][] is installed to `$ORACLE_HOME/bin/sqlplus`, and the current user +has both normal and DBA access without a password, i.e. `/` and `/ AS SYSDBA`. + +[OCI][] and [OCCI][] libraries and header files are in `$ORACLE_HOME/lib` and +`$ORACLE_HOME/rdbms/public`, respectively. + +[environment variables]: https://docs.travis-ci.com/user/environment-variables/ +[latest release]: https://github.com/cbandy/travis-oracle/releases/latest +[OCCI]: http://www.oracle.com/pls/topic/lookup?ctx=xe112&id=LNCPP +[OCI]: http://www.oracle.com/pls/topic/lookup?ctx=xe112&id=LNOCI +[SQL\*Plus]: http://www.oracle.com/pls/topic/lookup?ctx=xe112&id=SQPUG diff --git a/.travis/oracle/download.js b/.travis/oracle/download.js new file mode 100644 index 00000000..b5dccf08 --- /dev/null +++ b/.travis/oracle/download.js @@ -0,0 +1,100 @@ +// vim: set et sw=2 ts=2: +"use strict"; +var env = process.env; +var Promise = require('bluebird'); +var Phantom = Promise.promisifyAll(require('node-phantom-simple')); +var PhantomError = require('node-phantom-simple/headless_error'); + +Phantom.createAsync({ parameters: { 'ssl-protocol': 'tlsv1' } }).then(function (browser) { + browser = Promise.promisifyAll(browser, { suffix: 'Promise' }); + + // Configure the browser, open a tab + return browser + .addCookiePromise({'name': 'oraclelicense', 'value': "accept-" + env['ORACLE_COOKIE'] + "-cookie", 'domain': '.oracle.com' }) + .then(function () { + return browser.createPagePromise(); + }) + .then(function (page) { + page = Promise.promisifyAll(page, { suffix: 'Promise' }); + + // Configure the tab + page.onResourceError = console.error.bind(console); + return page + .setPromise('settings.userAgent', env['USER_AGENT']) // PhantomJS configures the UA per tab + + // Request the file, wait for the login page + .then(function () { + return page.openPromise("https://edelivery.oracle.com/akam/otn/linux/" + env['ORACLE_FILE']).then(function (status) { + if (status != 'success') throw "Unable to connect to oracle.com"; + return page.waitForSelectorPromise('input[type=password]', 5000); + }) + .catch(PhantomError, function (err) { + return page.getPromise('plainText').then(function (text) { + console.error("Unable to load login page. Last response was:\n" + text); + throw err; + }); + }); + }) + + // Export cookies for cURL + .then(function () { + return page.getPromise('cookies').then(function (cookies) { + var data = ""; + for (var i = 0; i < cookies.length; ++i) { + var cookie = cookies[i]; + data += cookie.domain + "\tTRUE\t" + cookie.path + "\t" + + (cookie.secure ? "TRUE" : "FALSE") + "\t0\t" + + cookie.name + "\t" + cookie.value + "\n"; + } + return Promise.promisifyAll(require('fs')).writeFileAsync(env['COOKIES'], data); + }); + }) + + // Submit the login form using cURL + .then(function () { + return page.evaluatePromise(function () { + var $form = jQuery(document.forms[0]); + return { + action: $form.prop('action'), + data: $form.serialize() + }; + }) + .then(function (form) { + return browser.exitPromise().then(function () { + for (var key in env) { + if (key.indexOf('ORACLE_LOGIN_') == 0 && env.hasOwnProperty(key)) { + var name = key.substr(13) + '='; + form.data = form.data.replace(name, name + env[key]); + } + } + + var cmd = ['curl', [ + '--cookie', env['COOKIES'], + '--cookie-jar', env['COOKIES'], + '--data', '@-', + '--location', + '--output', require('path').basename(env['ORACLE_FILE']), + '--user-agent', env['USER_AGENT'], + form.action + ]]; + + console.info("Executing %j", cmd); + + var child_process = require('child_process'); + var child = child_process.spawn.apply(child_process, cmd.concat({ stdio: ['pipe', 1, 2] })); + child.on('exit', process.exit); + child.stdin.end(form.data); + }); + }); + }) + .catch(function (err) { + console.error(err); + browser.on('exit', function () { process.exit(1); }); + browser.exit(); + }); + }); +}) +.catch(function (err) { + console.error(err); + process.exit(1); +}); diff --git a/.travis/oracle/download.sh b/.travis/oracle/download.sh new file mode 100755 index 00000000..540b61cb --- /dev/null +++ b/.travis/oracle/download.sh @@ -0,0 +1,16 @@ +#!/bin/sh -e + +[ -n "$ORACLE_COOKIE" ] || { echo "Missing ORACLE_COOKIE environment variable!"; exit 1; } +[ -n "$ORACLE_FILE" ] || { echo "Missing ORACLE_FILE environment variable!"; exit 1; } + +cd "$(dirname "$(readlink -f "$0")")" + +npm install bluebird node-phantom-simple + +export COOKIES='cookies.txt' +export USER_AGENT='Mozilla/5.0' + +echo > "$COOKIES" +chmod 600 "$COOKIES" + +exec node download.js diff --git a/.travis/oracle/install.sh b/.travis/oracle/install.sh new file mode 100755 index 00000000..f4ded7af --- /dev/null +++ b/.travis/oracle/install.sh @@ -0,0 +1,32 @@ +#!/bin/sh -e + +[ -n "$ORACLE_FILE" ] || { echo "Missing ORACLE_FILE environment variable!"; exit 1; } +[ -n "$ORACLE_HOME" ] || { echo "Missing ORACLE_HOME environment variable!"; exit 1; } + +ORACLE_RPM="$(basename $ORACLE_FILE .zip)" + +cd "$(dirname "$(readlink -f "$0")")" + +sudo apt-get -qq update +sudo apt-get --no-install-recommends -qq install bc libaio1 rpm unzip + +df -B1 /dev/shm | awk 'END { if ($1 != "shmfs" && $1 != "tmpfs" || $2 < 2147483648) exit 1 }' || + ( sudo rm -r /dev/shm && sudo mkdir /dev/shm && sudo mount -t tmpfs shmfs -o size=2G /dev/shm ) + +test -f /sbin/chkconfig || + ( echo '#!/bin/sh' | sudo tee /sbin/chkconfig > /dev/null && sudo chmod u+x /sbin/chkconfig ) + +test -d /var/lock/subsys || sudo mkdir /var/lock/subsys + +unzip -j "$(basename $ORACLE_FILE)" "*/$ORACLE_RPM" +sudo rpm --install --nodeps --nopre "$ORACLE_RPM" + +echo 'OS_AUTHENT_PREFIX=""' | sudo tee -a "$ORACLE_HOME/config/scripts/init.ora" > /dev/null +sudo usermod -aG dba $USER + +( echo ; echo ; echo travis ; echo travis ; echo n ) | sudo AWK='/usr/bin/awk' /etc/init.d/oracle-xe configure + +"$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA <