Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Added a version controller and used proper ruby gems to gather data. #103

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions .pkgr.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
---
before:
- 'export SECRET_KEY_BASE=xxx'
after_install: 'setup-secrets.sh'
- "export SECRET_KEY_BASE=xxx"
after_install: "setup-secrets.sh"
build_dependencies:
- ImageMagick-devel
- libxml2-devel
- libxslt-devel
- gcc
- make
- cmake
- cmake-devel
- automake
dependencies:
- mongodb-org-server
- ImageMagick
- cmake
targets:
centos-7:
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 12 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -573,6 +575,7 @@ DEPENDENCIES
email_spec (~> 2.1)
factory_bot_rails
gibberish
git
gitlab
inspec_tools (~> 1.3.0)
jbuilder (~> 2.5)
Expand Down Expand Up @@ -600,6 +603,7 @@ DEPENDENCIES
rubocop
rubocop-performance
rubocop-rspec
rugged
sassc-rails
simplecov
spring
Expand Down
21 changes: 11 additions & 10 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
"mongolab",
"tunemygc"
],
"buildpacks": [
"buildpacks": [{
"url": "https://github.com/ello/heroku-buildpack-cmake.git"
},
{
"url": "heroku/ruby"
}
],
"description": "InSpec Results Viewer",
"env": {
"CIPHER_PASSWORD": {
"SECRET_KEY_BASE": {
"generator": "secret"
},
"CIPHER_SALT": {
"required": true
"generator": "secret"
},
"CIPHER_PASSWORD": {
"generator": "secret"
},
"LANG": {
"required": true
Expand All @@ -36,12 +41,6 @@
},
"RUBY_GC_TOKEN": {
"required": true
},
"SECRET_KEY_BASE": {
"generator": "secret"
},
" CIPHER_SALT": {
"generator": "secret"
}
},
"formation": {
Expand All @@ -51,6 +50,8 @@
},
"name": "heimdall",
"scripts": {
"postdeploy": "bundle exec rake db:setup",
"pr-predestroy": "bundle exec rake db:drop"
},
"stack": "heroku-18"
}
}
3 changes: 3 additions & 0 deletions app/assets/javascripts/version.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/version.scss
Original file line number Diff line number Diff line change
@@ -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/
12 changes: 12 additions & 0 deletions app/controllers/version_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/version_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module VersionHelper
end
7 changes: 3 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
<!-- Main Footer -->
<footer class="main-footer">
<!-- To the right -->
<div class="pull-right hidden-xs">
Version: <%= Git::VERSION %>
<div class="pull-right">
<a href="https://github.com/mitre/heimdall/tree/<%= MyApp::VERSION %>"><%= MyApp::VERSION %></a> (<%= MyApp::BRANCH %>)
</div>
<!-- Default to the left -->
<strong>Copyright &copy; 2018 <a href="#">MITRE</a>.</strong> All rights reserved.
<strong>Copyright &copy; <%= Date.today.year %> <a href="http://www.mitre.org/">MITRE</a></strong>
</footer>
</div>
<!-- ./wrapper -->
Expand Down
5 changes: 5 additions & 0 deletions config/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": "v2.0.3-36-ga68c8cd",
"branch": "disp_ver",
"sha": "a68c8cdfd00ef3e5d066cd8f3f085bb5f6d083a0"
}
5 changes: 0 additions & 5 deletions config/initializers/git_revision.rb

This file was deleted.

26 changes: 26 additions & 0 deletions config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure this will work as intended. It actually might be completely impossible to add a version in this manner since adding the version to the hash itself will change what the hash should be. Also, any squashes or merges done on Github will all have the wrong SHA since rails is not run on those. Heroku used to provide a SOURCE_VERSION ENV but is seems they have removed it.

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
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
get 'version', to: 'version#index'
resources :users do
get :image, on: :member
end
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/version_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe VersionController, type: :controller do

end
15 changes: 15 additions & 0 deletions spec/helpers/version_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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