-
Notifications
You must be signed in to change notification settings - Fork 391
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
add docker multistage build #150
base: master
Are you sure you want to change the base?
add docker multistage build #150
Conversation
Hey, thanks for the PR! Nice approach using the multi-stage build, that looks like a clean approach to separating the development and production environment in a single Dockerfile.
While I like the clean separation, I agree that placing the files into the project root would seem cleaner. Also this seems to be much more commonplace from what I've seen.
I'm also undecided on this. On one hand, I feel that tests are usually designed to be run on the development environment, so running the tests in the build docker image seems natural. On the other hand it definitely seems like a good idea to run the tests in the same environment as production to ensure that everything still works there. Finally, I wonder what your thoughts on adding Docker to the starter is. From my personal experience, I feel that Docker is still not very common in the C++ development lifecycle (besides CI) and is often added at a more mature project stage. If Docker would be part of the starter, the Dockerfile would also have to be maintained alongside the project (or removed), adding a bit more overhead for using the starter. As a compromise, how would you feel about dropping the CI tests for the Dockerfile and instead adding usage instructions to the Readme? I think that way Docker would feel more like an optional feature instead of an essential part of every C++ project. |
If we categorize all C++ projects in the three arbitrary categories |
b1547f2
to
25d1b92
Compare
I updated the everything and also extracted the Docker CI/CD part into a separate repository. The CI/CD pipeline features:
The setup is quite easy and requires only the DockerHub username and an access_token as GitHub secrets. I like the example code ( I removed the tests from the Docker images but kept the local build on the Again, feedback on the changes is greatly appreciated. |
Is there an interest to merge this? With the CrowCpp example or without? |
Hey, thanks for the changes! Tbh I'm a bit hesitant to merge this, as it adapts the starter for a very specific use-case and library. As the starter is intended for both simple and advanced projects, I feel such a change could make it unattractive for some users. As a compromise, how would you feel about linking to your fork from the readme for those interested in Docker / CrowCpp use? |
include(../cmake/CPM.cmake) | ||
|
||
# Crow needs Boost 1.64 and does not provide CPM.cmake integration itself, so we have to get Boost | ||
# first | ||
find_package(Boost 1.64 QUIET) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dockerfile at this level does not work!
We need access to ../cmake
and ../CMakeLists.txt
while build standalone
# get the Greeter lib | ||
CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is something like add_subdirectory(.. Greeter)
libboost-all-dev \ | ||
; | ||
COPY . . | ||
RUN cmake -S standalone -B build -G Ninja -D CMAKE_BUILD_TYPE=Release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configure error here!
When playing around with docker in another project, I wanted to to see what some best practices for using C++ and docker might look like and checked out this repo. Unfortunately, #63 seems to have died quite some time ago.
This is more a discussion starter than a complete PR, but comes with my naive approach on how a multi-stage docker build could look like - assuming the
greeter standalone
executable would be our 'web-application' or 'server'.Some remarks.
.dockerignore
file) and justing usingCOPY . .
would be more straight forward.ubuntu:20.04
because it's a nice compromise between ease of use and size (assuming we want to deploy an actual application). Something likegcc:11.2
would be easier to set up but a lot heavier (78mb vs 1.1gb)Feedback is greatly appreciated