class DockerEndpoint
Class to perform operations on receiving http calls
Public Class Methods
new(_param)
click to toggle source
# File lib/continuous_integration/tasks.rb, line 6 def initialize(_param) @resource_path = '/cards' @repo_name = '' @process_status = '' @result = '' @result_api = '' @result_ui = '' @git_branch = '' @response = '' end
Public Instance Methods
do_POST(request, _response)
click to toggle source
curl localhost:8080/docker POST call made by quay to CI server
# File lib/continuous_integration/tasks.rb, line 19 def do_POST(request, _response) #print "Request is #{request}" # parse JSOn to hash key request_hash = JSON.parse(request.body, symbolize_names: true) begin # fetch the github repo name @repo_name = request_hash[:name] # fetch the github branch name @git_branch = request_hash[:trigger_metadata][:ref] @git_branch = @git_branch.split('/') @git_branch = @git_branch.last #loop in case already processing a request while true if $LOCK sleep 10 puts "Waiting" else puts "File not there" break end end perform_operations _response.body = JSON.generate @response _response['Content-Type'] = 'application/json' rescue StandardError => error #unset lock on exceptions $LOCK = false print "Not a valid Quay post " + error.to_s end end
docker_update()
click to toggle source
update docker images locally
# File lib/continuous_integration/tasks.rb, line 78 def docker_update Dir.chdir(DOCKER_PATH) do # perform docker images update `sudo docker-compose kill` `sudo docker-compose rm` `sudo docker-compose up -d` end end
generate_log()
click to toggle source
# File lib/continuous_integration/tasks.rb, line 110 def generate_log @response = { 'Docker logs' => @process_status, 'API logs' => @result_api, 'SE logs' => @result_ui } end
perform_operations()
click to toggle source
method to perform various CI operations
# File lib/continuous_integration/tasks.rb, line 60 def perform_operations #set lock $LOCK = true docker_update sleep 10 run_api_tests run_ui_tests generate_log slack_post #unset lock $LOCK = false end
run_api_tests()
click to toggle source
Action - run api tests
# File lib/continuous_integration/tasks.rb, line 88 def run_api_tests Dir.chdir(API_SPECS_PATH) do # shell command to run my tests using rake. # I am using `aha` shell tool to grab shell output to html cmd = "RUBYOPT='-W0' HOST=#{HOST} RMQ_HOST=#{HOST} RMQ_VHOST=/ bundle exec rake cars:#{@git_branch} | aha --black >logs/#{@git_branch}/$(date +\%d-\%m-\%Y-\%H-\%s)-API-run.htm" @result_api = `#{cmd}` # or use ` .... ` instead of %x[ .... ] to run commands end end
run_ui_tests()
click to toggle source
# File lib/continuous_integration/tasks.rb, line 100 def run_ui_tests Dir.chdir(UI_SPECS_PATH) do # navigate to specs dir cmd = "HOST='https://#{HOST}' BROWSER=phantomjs SCREENS=true bundle exec rake selenium:#{@git_branch} | aha --black >logs/#{@git_branch}/$(date +\%d-\%m-\%Y-\%H-\%s)-UI-run.htm" @result_ui = `#{cmd}` end end
slack_post()
click to toggle source
# File lib/continuous_integration/tasks.rb, line 118 def slack_post # curl to post to slack for the team to see the results end