-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
execut tests to a running container with specific options #11
Comments
Hello, Finally I use this method to use tests on a container : describe "test on container" do
describe "container" do
@container = Docker::Container.get('httpd_container')
set :backend, :docker
set :docker_container, @container.id
describe port(8080) do
it { should be_listening }
end
describe port(8443) do
it { should be_listening }
end
describe command('curl -s localhost:8080') do
its(:stdout) { should match /Hello!/ }
end
end
end However I encounter another problem, I want to know if my container is healthy with the following command : describe command('docker ps -f name=httpd_container') do
its(:stdout) { should match /healthy/ }
end The problem is that I already use a backend for the container then the test doesn't work. Is it possible to use 2 backend in a rspec script ? Regards, Azaroths |
Hi @Azaroths, I'm not sure if I'm understanding your problem correctly. I don't quite understand what you mean by "use 2 backend". The Anyway, for your case I recommend you to use describe docker_run(id: 'httpd_container') do
describe port(8080) do
it { should be_listening }
end
describe port(8443) do
it { should be_listening }
end
describe command('curl -s localhost:8080') do
its(:stdout) { should match /Hello!/ }
end
end I have not tested it, but should work in theory. |
Hi @zuazo I need to start a container with specific options ( I try to start tests in a running container or maybe exists a serverspec command for execute a container with my specific options but I didn't find it :( Thanks for your help |
Hi @zuazo I tried this PRODUCTION_OPTIONS = "--cpu-period=100000 --cpu-quota=75000 --security-opt=no-new-privileges --pids-limit=100 --network=wl_bridge"
WL_HTTPD_IMAGE = "my_image"
WL_HTTPD_TEST="httpd_test"
@container1 = %x[docker run --name httpd-prod --health-cmd "echo" #{PRODUCTION_OPTIONS} -d #{WL_HTTPD_IMAGE}]
@container2 = %x[docker run --name httpd-middle --health-cmd "echo" #{PRODUCTION_OPTIONS} -d #{WL_HTTPD_TEST}]
describe "test on containers" do
describe "container 1" do
describe docker_run(id: @container1, tag: "#{WL_HTTPD_IMAGE}") do
describe file('/etc') do
it { should exist }
end
describe port(8080) do
it { should be_listening }
end
describe port(8443) do
it { should be_listening }
end
describe file('/var/www/html/index.html') do
it { should exist }
its(:content) { should match /Hello!/ }
end
end
end
describe "container 2" do
describe docker_run(id: @container2, tag: "#{WL_HTTPD_TEST}") do
describe file('/etc') do
it { should exist }
end
describe port(8080) do
it { should be_listening }
end
describe port(8443) do
it { should be_listening }
end
describe file('/var/www/html/index.html') do
it { should exist }
its(:content) { should match /Hello!/ }
end
end
end
end But when I do docker inspect on my container, the production options are not in the logs. Is it normal ? Regards, Azaroths |
Finally, I will try to modify your gem code to have more options when I start a container. Regards, Azaroths |
OK, sorry @Azaroths. I did not respond because to do what you intend, as you have realized, would require implementing changes in the library and I have not had time to look at it carefully. Either way, let me know if you need help or you find any problem. A PR would be greatly appreciated 😉 |
Dockerspec Version
Dockerspec (0.4.1)
Ruby Version
Ruby 2.4.0
Platform Details
CentOS Linux release 7.3.1611
Scenario
Hello,
I would like execute scripts for test in containers with specific options.
For this, containers are executed with specific options like this:
docker run --name httpd-prod-opts --health-cmd "echo" --memory = 512M --cpu-period = 100000 --cpu-quota = 75000 Pids-limit = 100 --network = my_bridge -d my_image
I would like to connect to a running container in order to run serverspec tests on it such as , is it possible ? In my script I can't use "describe docker_run('')" cause I need to have my specific options formy containers.
I tried several things without success, I don't know how to proceed to connect to a running container
Is there a method for this?
Sorry for my english, it is not really good
Regards,
Azaroths
The text was updated successfully, but these errors were encountered: