Removing unused Docker containers

Those who work with Docker know how fast is free space disappearing, especially, in case you are experimenting with some new features and don’t pay much attention to cleaning up. As the result, a lot of empty untagged containers can eat tens of gigabytes of space.

Here is the one-liner I found to be very useful for removing old stuff:

docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm

Actually, I’m not the one who came up with this answer, but I spent a few hours trying different commands and googling for the answer.

Here is the full Docker cheat sheet that I bumped into and found it being quite good itself:

https://github.com/wsargent/docker-cheat-sheet

Using renderables in Buildbot custom steps

Currently, I’m being widely involved in customization of Buildbot instances. Many questions arise, but no answers are usually available on the Web.

Recently, I designed a custom build step which by the definition needed to work with values from properties passed to it on the init time. The challenge was to make it understanding everything that can theoretically be passed – build properties (IProperty), plain values etc.

In this case, we can use ‘renderables’ list to specify mapping from variables that can contain properties to variables that are used to store rendered values.

We can use passed values without caring to handle it as property or some other renderable. Buildbot does it automatically

class MyStep(BuildStep):
    ...
    renderables = ['renderable1' , 'renderable2']

    def __init__(self, passed_var1, passed_var2):
        self.renderable1 = passed_var1
        self.renderable2 = passed_var2

Invoke the step in the build factory as:

MyStep(util.Prop(property1), util.Prop(property2))

or

MyStep('actual value 1', 'actual value 2')

Now we can use passed values simply as without caring to handle it as property or some other renderable. Buildbot does it automatically.

Getting style attributes of web-elements using Selenium IDE

Let’s assume you have an element of a web-page that contains an attribute, that you need to have access to, within its style property. Even more, this attribute is changed by your application, and you want to test whether it now corresponds to a correct value, or there is a mistake.

Element’s HTML:

<span id="imgStats" class="imgStats" style="background-image: url("yoursite.com/image.png");">

What we are looking for is a comparison of  yoursite.com/image.png to an actual value.

Solution: access it by xPath and use getXpathCount() method of SeleniumIDE in PHPUnit:

$this->assertEquals("1", $this->getXpathCount("xpath=id('imgStats')[@style='background-image: url(\"/yoursite.com/img.png\");']"));

This method counts a number of elements that have a particular xpath. In this case it is expected to be equal to 1. If you have any other attributes in style, you must specify them in the selector. Otherwise it won’t work. Also take into account a syntax of this expression, it took one hour to figure out a correct sequence of all these semicolons and brackets 🙂