Let's say you have a repository in gitlab. For facilitated distribution of the application and according development throughout a team, you convert the app into a Docker Container, which can be spinned up on any laptop via Docker Desktop. You've then also setup completely automated API tests which fire a set of API requests to your docker container booted up at e.g. https://localhost:8080/. These tests are implemented via code, so they are executable locally either via CLI, the language, or the integration used for it provided by the IDE. The mission now is, how do I replicate this in a gitlab CI pipeline ?
From what I understand, I need two docker container environments within my CI pipeline:
one mirroring my local IDE development environment from within which the test requests are fired
Another one to actually run the docker container that hosts the REST API to which the test requests shall be fired.
How is such a setup mirrored in a gitlab CI? What I am currently thinking of is:
The first container represents an environment that is very unlikely to change, as the IDE development environment is predictable and isolated from the running application. So for this container 1, I would create a
Dockerfilethat you add into the repository of the same project which replicates your local development environment (of the IDE from which you normally execute automated tests locally). Build the image of that and upload it to the private container registry provided by gitlab. This image is then used within the CI pipeline file via theimagekeyword to provide the above-mentioned container 1.Container 2 is where I am confused. It seems I cannot run
docker-composeor similar within a CI pipeline and would need something like `Docker in Docker` to be able to bootup my localhost REST API container within the CI pipeline. But before starting to do this, I wanted to be sure that there's no better way to set this up? As the build of the container 2 must precisely be tested within the CI pipeline, it does not make sense to upload an image to my registry for this container 2. I also would like to not need to replicate e.g. the build logic of my Dockerfile within my CI pipeline, as that would effectively eliminate the single source of truth for the image build.