Skip to content

DevOps: Run rails tasks from a VAEC Jenkins Instance

Emmanuel Nwakire edited this page Jul 12, 2024 · 4 revisions
  1. Have an account
  2. Browse to http://internal-jenkinsdevops-837096002.us-gov-west-1.elb.amazonaws.com/
  3. Log in
  4. Click on "Task"
  5. Click on "Configure" from the side navigation
  6. Scroll down to "Build"
  7. In the "Execute shell" section and "Command" textarea, type the following command
ssh ec2-user@[SERVER VARIABLE] "sudo docker exec [CONTAINER NAME] rails [RAKE TASK COMMAND];"

Replace [SERVER VARIABLE] with the variable of the server you want to run this task on:

  • production: $PROD_SERVER
  • staging: $STG_SERVER
  • development: $DEV_SERVER

Replace [CONTAINER NAME] with the name of the docker container for the application: diffusion-marketplace_app_1

Replace [RAKE TASK COMMAND] with the name of the task you want to run. For a full list of available tasks, you can run rake --tasks in your local project folder.

  • ex: milestones:port_milestones_to_timelines

So an example command would look like this:

ssh ec2-user@$DEV_SERVER "sudo docker exec diffusion-marketplace_app_1 rails milestones:port_milestones_to_timelines;"
  1. Click "Save"
  2. Click "Build Now"
  3. Click the task number in the "Build History"
  4. Click "Console Output"
  5. Ensure you see "SUCCESS" in the logs

An example of a more advanced command may look like this:

ssh ec2-user@$PROD_SERVER "sudo docker exec diffusion-marketplace_app_1 rails runner \"ActiveRecord::Base.logger = nil; counter = 0; Practice.where(published: true).order(name: :asc).each { |p| if p.diffusion_histories.empty? then counter += 1; puts %Q(ID: #{p.id}, Name: #{p.name}, #{p.user&.email.present? ? %Q(Owner email: #{p.user&.email}, )  : ''}Support email: #{p.support_network_email}, URL: https://marketplace.va.gov/practices/#{p.slug}) end }; puts %Q(Total: #{counter}); nil; STDOUT.flush\";"
Clone this wiki locally