June 23rd 2020
I do test automation for ONLYOFFICE document editors, and our team uses Docker for lots of tasks. It’s difficult for me to imagine how to work without it and not suffer performance losses.
In this article, I will describe my experience with Docker and provide you with some tricks to make your life easier with its help.
Docker for build automation and app launching
Docker is a great tool for build automation and app launching. Even it seems you can just write a simple bash script, try Docker instead. This way you will be sure that even if you need to run the container on a different operating system everything will work exactly how you planned. With bash script it’s not always possible.
I won’t repeat all the basic things about Docker and Docker-compose from the official documentation. But I have some tips from my experience. Pay attention to these things while creating a dockerfile:
Excluding unnecessary files
```COPY / ADD```
command will copy all the files from your directory (see the difference between these commands in Docker Best Practices).
to exclude the files you don’t need. See the details here.
Using links to git repo
- You create a dockerfile for project building in the project’s root folder
- You don’t change its name to a custom one.
version: '3' services: test-service: build: context: https://github.com/no-flamine/docker-in-root-example.git
Using databases in containers
If your app has a database, web-server, or something of the kind, use a separate container for them.
You probably read that database in a container is a bad idea. That’s true because Docker was created for processing not storing. But during development and testing, it’s totally OK to use it as you don’t have much important data stored there. You can kill this database anytime you want, add a new one and load it with any trash data if you need that for testing. Later, for production, you’ll add an opportunity to connect a perfectly safe and stable external database for actual data.
parameter (see documentation for more info) when you start your containers for production. It’s rather unpleasant when services crash, but it’s way worse they don’t return to life.
Running tests with Docker
Docker significantly simplifies running autotests, because you need two commands only (build/run).
Each time we update the tests, we check the new version on the stable version of the product. To do so, we just need to build an image and start the container using dockerfile from the project’s root.
Checking the updated tests on the stable version of the product is important, otherwise, the newly added changes can break the master branch.
name: check on: [push] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - name: Running test inside doc-builder-testing run: | docker build -t doc-builder-testing . docker run doc-builder-testing
We have only two strings in the run section – build и run.
We also have dockerfiles for testing DocBuilder installation on supported systems. When we add support for more systems, we’ll create dockerfiles for them as well.