Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from sanger/gpl181_openstack
Browse files Browse the repository at this point in the history
Gpl181 openstack
  • Loading branch information
JamesGlover authored Jan 19, 2022
2 parents 8ba4a79 + 871a649 commit 0e553f8
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 52 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.5.3
2 changes: 1 addition & 1 deletion .rvmrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use 1.8.7" > .rvmrc
environment_id="ruby-1.8.7-p334@plate_barcode"
environment_id="ruby-2.5.3@plate_barcode"

# Uncomment the following lines if you want to verify rvm version per project
# rvmrc_rvm_version="1.15.3 (master)" # 1.10.1 seams as a safe start
Expand Down
16 changes: 8 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
source "http://rubygems.org"
source 'https://rubygems.org'

gem 'sinatra', "~>1.0"
gem 'activerecord', "~>2.3.15"
gem 'sinatra'
gem 'activerecord'
gem 'builder'
gem 'puma'

group :development do
gem "mysql", "~> 2.8.1"
gem 'mysql2'
end

group :deployment do
gem "mongrel_experimental"
gem "mongrel_cluster"
gem "activerecord-oracle_enhanced-adapter", "1.2.3"
gem "ruby-oci8", "~> 2.1.0"
gem 'activerecord-oracle_enhanced-adapter'
gem 'ruby-oci8'
end
80 changes: 48 additions & 32 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
activerecord (2.3.15)
activesupport (= 2.3.15)
activerecord-oracle_enhanced-adapter (1.2.3)
activerecord (>= 2.0.0)
activesupport (2.3.15)
cgi_multipart_eof_fix (2.5.0)
daemons (1.1.0)
fastthread (1.0.7)
gem_plugin (0.2.3)
mongrel (1.1)
cgi_multipart_eof_fix (>= 2.4)
daemons (>= 1.0.3)
fastthread (>= 1.0.1)
gem_plugin (>= 0.2.3)
mongrel_cluster (1.0.5)
gem_plugin (>= 0.2.3)
mongrel (>= 1.0.2)
mongrel_experimental (1.1)
mongrel (= 1.1)
mysql (2.8.1)
rack (1.2.1)
ruby-oci8 (2.1.5)
sinatra (1.0)
rack (>= 1.0)
activemodel (5.2.1)
activesupport (= 5.2.1)
activerecord (5.2.1)
activemodel (= 5.2.1)
activesupport (= 5.2.1)
arel (>= 9.0)
activerecord-oracle_enhanced-adapter (5.2.3)
activerecord (~> 5.2.0)
ruby-plsql (>= 0.6.0)
activesupport (5.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (9.0.0)
builder (3.2.3)
concurrent-ruby (1.0.5)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
minitest (5.11.3)
mustermann (1.0.3)
mysql2 (0.5.2)
puma (3.12.1)
rack (2.0.5)
rack-protection (2.0.4)
rack
ruby-oci8 (2.2.6.1)
ruby-plsql (0.7.1)
sinatra (2.0.4)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.4)
tilt (~> 2.0)
thread_safe (0.3.6)
tilt (2.0.8)
tzinfo (1.2.5)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
activerecord (~> 2.3.15)
activerecord-oracle_enhanced-adapter (= 1.2.3)
mongrel_cluster
mongrel_experimental
mysql (~> 2.8.1)
ruby-oci8 (~> 2.1.0)
sinatra (~> 1.0)
activerecord
activerecord-oracle_enhanced-adapter
builder
mysql2
puma
ruby-oci8
sinatra

BUNDLED WITH
1.17.3
6 changes: 0 additions & 6 deletions README

This file was deleted.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Plate Barcode
=============

Description
-----------

Sinatra application which will connnect to an oracle database called SNP and return a new plate barcode ID.

Usage
-----

In the repository base directory run:

```
bundle exec rackup -E development -p 3011 config.ru
```

Then point your browser at: `http://localhost:3011`
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#\ -w -p 3011
require "plate_barcode"
require "./plate_barcode"
disable :run, :reload

run Sinatra::Application
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
development:
adapter: mysql
adapter: mysql2
username: root
password:
database: plate_barcode_development
120 changes: 120 additions & 0 deletions lib/deployed_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# frozen_string_literal: true

require 'open3'

module Deployed
class RepoData
def tag
@tag ||= git_tag || read_file('TAG').strip.presence
end

def revision
@revision ||= git_rev || read_file('REVISION').strip.presence
end

def branch
@branch ||= git_branch || read_file('BRANCH').strip.presence
end

def release
@release ||= read_file('RELEASE').strip
end

def release_url
@release_url ||= read_file('REPO').strip
end

def revision_short
@revision_short ||= revision&.slice 0..6
end

def label
tag.presence || branch
end

def major
@major ||= version(:major)
end

def minor
@minor ||= version(:minor)
end

def extra
@extra ||= version(:extra)
end

def version_hash
@version_hash ||= /\Arelease-(?<major>\d+)\.(?<minor>\d+)\.?(?<extra>\S*)\z/.match(label)
end

def version_label
if major == 0 && minor == 0 && extra == 0
'WIP'
else
"#{major}.#{minor}.#{extra}"
end
end

private

def git_tag
cmd = 'git tag -l --points-at HEAD --sort -version:refname | head -1'
@git_tag ||= execute_command(cmd)
end

def git_rev
cmd = 'git rev-parse HEAD'
@git_rev ||= execute_command(cmd)
end

def git_branch
cmd = 'git rev-parse --abbrev-ref HEAD'
@git_branch ||= execute_command(cmd)
end

def version(rank)
version_hash ? version_hash[rank] : 0
end

def execute_command(cmd)
_stdin, stdout, _stderr, _wait_thr = Open3.popen3(cmd)
res = stdout.gets
res&.strip
end

def read_file(filename)
File.open(File.join(APP_ROOT, filename), 'r', &:readline)
rescue Errno::ENOENT, EOFError
''
end
end

ENVIRONMENT = "#{ RAILS_ENV }"

REPO_DATA = RepoData.new

VERSION_ID = REPO_DATA.version_label

APP_NAME = 'Plate Barcode'
RELEASE_NAME = REPO_DATA.release.presence || 'LOCAL'

MAJOR = REPO_DATA.major
MINOR = REPO_DATA.minor
EXTRA = REPO_DATA.extra
BRANCH = REPO_DATA.label.presence || 'unknown_branch'
COMMIT = REPO_DATA.revision.presence || 'unknown_revision'
ABBREV_COMMIT = REPO_DATA.revision_short.presence || 'unknown_revision'

VERSION_STRING = "#{APP_NAME} #{VERSION_ID} [#{ENVIRONMENT}]"
VERSION_COMMIT = "#{BRANCH}@#{ABBREV_COMMIT}"
REPO_URL = REPO_DATA.release_url.presence || '#'
HOSTNAME = Socket.gethostname

require 'ostruct'
DETAILS = OpenStruct.new(
:name => APP_NAME,
:version => VERSION_ID,
:environment => ENVIRONMENT
)
end
6 changes: 3 additions & 3 deletions plate_barcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
helpers do
def get_version_string
require File.join(APP_ROOT,'lib/versionstrings')
Deployed::VERSION_STRING
"#{Deployed::APP_NAME} [#{RAILS_ENV}] #{Deployed::RELEASE_NAME}"
end
end

# Establish a connection to the database. If we're in development mode then the database
# connection should be made to behave like one to an Oracle DB.
ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(APP_ROOT,'config/database.yml')))[RAILS_ENV])
if RAILS_ENV == 'development'
ActiveRecord::ConnectionAdapters::MysqlAdapter
class ActiveRecord::ConnectionAdapters::MysqlAdapter
ActiveRecord::ConnectionAdapters::Mysql2Adapter
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
def next_sequence_value(name)
@sequence ||= 0
@sequence += 1
Expand Down

0 comments on commit 0e553f8

Please sign in to comment.