I had difficulty automating our build using docker-compose , and I ended up using docker build for everything:
Three layers for construction
Run β develop β build
Then I copy the build results to the 'deploy' image:
Run β Expand
Four layers for the game:
To run
- Contains all the packages needed to run the application - for example, libsqlite3-0
develop
FROM <projname>:run- Contains packages needed for assembly
- e.g. g ++, cmake, libsqlite3-dev
- Dockerfile does any external builds
- e.g. steps to build boost-python3 (not in package manager repositories)
build
FROM <projname>:develop- Contains source
- Dockerfile performs internal assembly (code that changes frequently)
- Embedded binaries are copied from this image for deployment use.
deployment
FROM <projname>:run- The assembly output is copied to the image and installed.
RUN or ENTRYPOINT used to launch an application.
The folder structure is as follows:
. βββ run β βββ Dockerfile βββ develop β βββ Dockerfile βββ build β βββ Dockerfile β βββ removeOldImages.sh βββ deploy βββ Dockerfile βββ pushImage.sh
Setting up the build server means doing:
docker build -f run -t <projName>:run docker build -f develop -t <projName>:develop
Every time we make an assembly, this happens:
# Execute the build docker build -f build -t <projName>:build # Install build outputs docker build -f deploy -t <projName>:version # If successful, push deploy image to dockerhub docker tag <projName>:<version> <projName>:latest docker push <projName>:<version> docker push <projName>:latest
I refer people to Dockerfiles as documentation on how to build / run / install a project.
If the assembly failed and the output file is insufficient for investigation, I can run /bin/bash in <projname>:build and <projname>:build what went wrong.
I put together a GitHub repository around this idea. This works well for C ++, but you can probably use it for anything.
I did not investigate this function, but @TaylorEdmiston pointed out that my template here is very similar to multi-stage assemblies that I did not know about when I came up with this. It looks like a more elegant (and better documented) way to achieve the same.