Skip to content

Instantly share code, notes, and snippets.

@lflucasferreira
Created January 11, 2020 17:55
Show Gist options
  • Select an option

  • Save lflucasferreira/ab86b3d8e4379d456df5a157f93f456c to your computer and use it in GitHub Desktop.

Select an option

Save lflucasferreira/ab86b3d8e4379d456df5a157f93f456c to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
def tarefa(hash = {})
browser = hash[:browser] ||= '-p chrome'
mode = hash[:mode] ||= '-p default'
desc "Executa os testes no #{hash[:task].capitalize} no modo #{hash[:env]}"
task hash[:task].to_sym, [:tags] do |_t, args|
Rake::Task['cucumber:command'].invoke(browser, mode, args.tags)
end
end
task :run
namespace :cucumber do
task :run
opts = { firefox: '-p firefox', ci: '-p ci', default: 'default' }
tarefa(task: 'chrome', env: opts[:default])
tarefa(task: 'firefox', browser: opts[:firefox], env: opts[:default])
namespace :ci do
task :run
ci = opts.key(opts[:ci])
tarefa(task: 'chrome', mode: opts[:ci], env: ci)
tarefa(task: 'firefox', mode: opts[:ci], browser: opts[:firefox], env: ci)
end
task :command, [:browser, :mode, :tags] do |_t, args|
sh "cucumber #{args.browser} #{args.mode} #{args.tags}"
end
end
desc 'Inicializa os containers via compose'
task :up do
sh 'docker-compose up -d'
sh "docker exec -it qaops sh -c '/etc/init.d/ssh start'"
Rake::Task['update'].invoke
sh 'docker ps'
end
desc 'Encerra e destroi os containers via compose'
task :down, [:rmi] do |_t, args|
args.with_defaults(rmi: nil)
options = "--rmi 'all'" if args.rmi.eql?('all')
images = 'qaschool/oficina qaschool/qaops'
sh "docker-compose down #{options}"
sh "docker rmi -f #{images}" if args.rmi.eql?('qaschool')
sh "ssh-keygen -R '[localhost]:2222'"
end
desc 'Atualiza Repositório Oficina de Testes no Nginx'
task :update do
repo = 'https://github.com/qaschoolbr/oficina.git'
path = '/usr/share/nginx/html'
sh "docker exec -it oficina bash -c 'cd #{path} && git pull #{repo}'"
end
desc 'Envia a chave SSH pro container QAOps'
task :setup do
host = "Host qaops\n\tHostname localhost"
info = "User qaschool\n\tPort 2222"
key = 'IdentityFile ~/.ssh/id_rsa-remote-ssh'
sh "ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa-remote-ssh"
sh 'ssh-copy-id -i ~/.ssh/id_rsa-remote-ssh.pub qaschool@localhost -p 2222'
sh "echo '\n#{host}\n\t#{info}\n\t#{key}' >> ~/.ssh/config"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment