Class: DockerEndpoint
- Inherits:
- 
      WEBrick::HTTPServlet::AbstractServlet
      
        - Object
- WEBrick::HTTPServlet::AbstractServlet
- DockerEndpoint
 
- Defined in:
- lib/continuous_integration/tasks.rb
Overview
Class to perform operations on receiving http calls
Instance Method Summary collapse
- 
  
    
      #do_POST(request, _response)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    curl localhost:8080/docker POST call made by quay to CI server. 
- 
  
    
      #docker_update  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    update docker images locally. 
- #generate_log ⇒ Object
- 
  
    
      #initialize(_param)  ⇒ DockerEndpoint 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of DockerEndpoint. 
- 
  
    
      #perform_operations  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    method to perform various CI operations. 
- 
  
    
      #run_api_tests  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Action - run api tests. 
- #run_ui_tests ⇒ Object
- #slack_post ⇒ Object
Constructor Details
#initialize(_param) ⇒ DockerEndpoint
Returns a new instance of DockerEndpoint.
| 7 8 9 10 11 12 13 14 15 16 | # File 'lib/continuous_integration/tasks.rb', line 7 def initialize(_param) @resource_path = '/cards' @repo_name = '' @process_status = '' @result = '' @result_api = '' @result_ui = '' @git_branch = '' @lock = false end | 
Instance Method Details
#do_POST(request, _response) ⇒ Object
curl localhost:8080/docker POST call made by quay to CI server
| 20 21 22 23 24 25 26 27 28 29 30 31 32 | # File 'lib/continuous_integration/tasks.rb', line 20 def do_POST(request, _response) # parse JSOn to hash key request_hash = JSON.parse(request.body, symbolize_names: true) # 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 perform_operations end | 
#docker_update ⇒ Object
update docker images locally
| 51 52 53 54 55 56 57 58 | # File 'lib/continuous_integration/tasks.rb', line 51 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 ⇒ Object
| 83 84 85 86 87 88 89 90 91 | # File 'lib/continuous_integration/tasks.rb', line 83 def generate_log obj = { 'Docker logs' => @process_status, 'API logs' => @result_api, 'SE logs' => @result_ui } response.body = JSON.generate obj response['Content-Type'] = 'application/json' end | 
#perform_operations ⇒ Object
method to perform various CI operations
| 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # File 'lib/continuous_integration/tasks.rb', line 35 def perform_operations # handle requests one at a time (to avoid concurrency) - Needs testing while @lock @lock = true docker_update sleep 10 run_api_tests run_ui_tests generate_log slack_post @lock = false end end | 
#run_api_tests ⇒ Object
Action - run api tests
| 61 62 63 64 65 66 67 68 69 70 71 | # File 'lib/continuous_integration/tasks.rb', line 61 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 ⇒ Object
| 73 74 75 76 77 78 79 80 81 | # File 'lib/continuous_integration/tasks.rb', line 73 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 ⇒ Object
| 93 94 95 | # File 'lib/continuous_integration/tasks.rb', line 93 def slack_post # curl to post to slack for the team to see the results end |