diff --git a/Gemfile b/Gemfile index 620d21a..32acfa8 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,8 @@ end gem 'tzinfo-data' gem 'rubocop-performance' gem 'tunemygc' +gem 'rugged' +gem 'git' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.4' diff --git a/Gemfile.lock b/Gemfile.lock index 45a9f01..f2306e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,13 +46,13 @@ GEM arel (8.0.0) ast (2.4.0) aws-eventstream (1.0.2) - aws-sdk (2.11.259) - aws-sdk-resources (= 2.11.259) - aws-sdk-core (2.11.259) + aws-sdk (2.11.260) + aws-sdk-resources (= 2.11.260) + aws-sdk-core (2.11.260) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-resources (2.11.259) - aws-sdk-core (= 2.11.259) + aws-sdk-resources (2.11.260) + aws-sdk-core (= 2.11.260) aws-sigv4 (1.1.0) aws-eventstream (~> 1.0, >= 1.0.2) azure_graph_rbac (0.17.1) @@ -140,6 +140,7 @@ GEM faraday (>= 0.7.4, < 1.0) ffi (1.10.0) gibberish (2.1.0) + git (1.5.0) gitlab (4.10.0) httparty (~> 0.14, >= 0.14.0) terminal-table (~> 1.5, >= 1.5.1) @@ -170,7 +171,7 @@ GEM htmlentities (4.3.4) http-cookie (1.0.3) domain_name (~> 0.5) - httparty (0.16.4) + httparty (0.17.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) httpclient (2.8.3) @@ -380,7 +381,7 @@ GEM rspec-mocks (~> 3.8.0) rspec-core (3.8.0) rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rspec-expectations (3.8.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) rspec-its (1.3.0) @@ -415,6 +416,7 @@ GEM ruby_dep (1.5.0) rubyntlm (0.6.2) rubyzip (1.2.2) + rugged (0.28.1) safe_yaml (1.0.5) sassc (2.0.1) ffi (~> 1.9) @@ -519,7 +521,7 @@ GEM execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.5) + unf_ext (0.0.7.6) unicode-display_width (1.5.0) unicode_utils (1.4.0) warden (1.2.8) @@ -573,6 +575,7 @@ DEPENDENCIES email_spec (~> 2.1) factory_bot_rails gibberish + git gitlab inspec_tools (~> 1.3.0) jbuilder (~> 2.5) @@ -600,6 +603,7 @@ DEPENDENCIES rubocop rubocop-performance rubocop-rspec + rugged sassc-rails simplecov spring diff --git a/app.json b/app.json new file mode 100644 index 0000000..6ebea34 --- /dev/null +++ b/app.json @@ -0,0 +1,57 @@ +{ + "addons": [ + "mongolab", + "tunemygc" + ], + "buildpacks": [ + { + "url": "heroku/ruby" + } + ], + "description": "InSpec Results Viewer", + "env": { + "CIPHER_PASSWORD": { + "generator": "secret" + }, + "CIPHER_SALT": { + "required": true + }, + "LANG": { + "required": true + }, + "MONGODB_URI": { + "required": true + }, + "RACK_ENV": { + "required": true + }, + "RAILS_ENV": { + "required": true + }, + "RAILS_LOG_TO_STDOUT": { + "required": true + }, + "RAILS_SERVE_STATIC_FILES": { + "required": true + }, + "RUBY_GC_TOKEN": { + "required": true + }, + "SECRET_KEY_BASE": { + "generator": "secret" + }, + " CIPHER_SALT": { + "generator": "secret" + } + }, + "formation": { + "web": { + "quantity": 1 + } + }, + "name": "heimdall", + "scripts": { + }, + "stack": "heroku-18" +} + diff --git a/app/assets/javascripts/version.coffee b/app/assets/javascripts/version.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/version.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/version.scss b/app/assets/stylesheets/version.scss new file mode 100644 index 0000000..4e1c090 --- /dev/null +++ b/app/assets/stylesheets/version.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the version controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/version_controller.rb b/app/controllers/version_controller.rb new file mode 100644 index 0000000..704f3b2 --- /dev/null +++ b/app/controllers/version_controller.rb @@ -0,0 +1,12 @@ +class VersionController < ApplicationController + def index + g = Git.open(Rails.root, :log => Logger.new(STDOUT)) + repo = Rugged::Repository.discover(Rails.root) + version = { + version: g.describe, + branch: repo.head.name.split('/').last, + sha: repo.head.target_id + } + render json: version + end +end diff --git a/app/helpers/version_helper.rb b/app/helpers/version_helper.rb new file mode 100644 index 0000000..5b2613e --- /dev/null +++ b/app/helpers/version_helper.rb @@ -0,0 +1,2 @@ +module VersionHelper +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 465c9ad..1e42bbe 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -34,11 +34,10 @@ diff --git a/config/VERSION b/config/VERSION new file mode 100644 index 0000000..d8da5d9 --- /dev/null +++ b/config/VERSION @@ -0,0 +1,5 @@ +{ + "version": "v2.0.3-29-gc553782", + "branch": "disp_ver", + "sha": "c553782b9186500b08e7fb9e74b0a17388be4747" +} diff --git a/config/initializers/git_revision.rb b/config/initializers/git_revision.rb deleted file mode 100644 index 7a10524..0000000 --- a/config/initializers/git_revision.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Get the deployed git revision to display in the footer -module Git - REVISION = `SHA1=$(git rev-parse --short HEAD 2> /dev/null); if [ $SHA1 ]; then echo $SHA1; else echo 'unknown'; fi`.chomp - VERSION = `VERSION=$(git describe --tags 2> /dev/null); if [ $VERSION ]; then echo $VERSION; else echo 'unknown'; fi`.chomp -end diff --git a/config/initializers/version.rb b/config/initializers/version.rb new file mode 100644 index 0000000..5a86859 --- /dev/null +++ b/config/initializers/version.rb @@ -0,0 +1,26 @@ +# config/initializers/version.rb + +if Rails.env.development? + # we will hae to use both the `git` and `rugged` gem until + # rugged implaments `git describe` + g = Git.open(Rails.root) + repo = Rugged::Repository.discover(Rails.root) + + version = { + version: g.describe, + branch: repo.head.name.split('/').last, + sha: repo.head.target_id + } + + File.open('config/VERSION','w') do |f| + f.write(JSON.pretty_generate(version)) + end +end + +module MyApp + # Read JSON from a file, iterate over objects + parsed = JSON.parse(File.read('config/VERSION'), :symbolize_names => true) + VERSION = parsed[:version] + BRANCH = parsed[:branch] + SHA = parsed[:sha] +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index bb9c39c..fc06b07 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + get 'version', to: 'version#index' resources :users do get :image, on: :member end diff --git a/spec/controllers/version_controller_spec.rb b/spec/controllers/version_controller_spec.rb new file mode 100644 index 0000000..66638cd --- /dev/null +++ b/spec/controllers/version_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe VersionController, type: :controller do + +end diff --git a/spec/helpers/version_helper_spec.rb b/spec/helpers/version_helper_spec.rb new file mode 100644 index 0000000..749b9f9 --- /dev/null +++ b/spec/helpers/version_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the VersionHelper. For example: +# +# describe VersionHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe VersionHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end