From e379435d81dae01f876ce3a8b8166c2be2b0b0a8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 26 Apr 2022 22:33:36 -0700 Subject: [PATCH] docker: add building and running env to the dockers --- README.md | 2 ++ cspell.config.yaml | 1 + dev/docker/ubuntu.dockerfile | 22 +++++++++++++++++----- dev/docker/ubuntu_node.dockerfile | 21 ++++++++++++++++----- dev/docker/ubuntu_stable_node.dockerfile | 21 ++++++++++++++++----- 5 files changed, 52 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b4909739..42797ea4 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,8 @@ See [this folder](https://github.com/aminya/setup-cpp/tree/master/dev/docker), f If you want to build the ones included, then run: ```ps1 +git clone --recurse-submodules https://github.com/aminya/setup-cpp +cd ./setup-cpp docker build -f ./dev/docker/ubuntu.dockerfile -t setup_cpp . ``` diff --git a/cspell.config.yaml b/cspell.config.yaml index 9c9269e2..346c65a0 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -7,6 +7,7 @@ ignorePaths: - pnpm-lock.yaml - .git/ - dist/ + - dev/cpp_vcpkg_project words: - aarch - aminya diff --git a/dev/docker/ubuntu.dockerfile b/dev/docker/ubuntu.dockerfile index d0dff673..127d5937 100644 --- a/dev/docker/ubuntu.dockerfile +++ b/dev/docker/ubuntu.dockerfile @@ -1,4 +1,5 @@ -FROM ubuntu:devel +#### Base Image +FROM ubuntu:devel AS base # add setup_cpp WORKDIR "/" @@ -8,9 +9,20 @@ RUN wget --no-verbose "https://github.com/aminya/setup-cpp/releases/download/v0. RUN chmod +x ./setup_cpp_linux # install llvm, cmake, ninja, and ccache -RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true - -# reload the environment -CMD source ~/.cpprc +RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --make true +CMD source ~/.cpprc ENTRYPOINT [ "/bin/sh" ] + +#### Building +FROM base AS builder +ADD ./dev/cpp_vcpkg_project /home/app +WORKDIR /home/app +RUN make build + +### Running environment +FROM gcr.io/distroless/cc +# copy the built binaries and their runtime dependencies +COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ +WORKDIR /home/app/ +ENTRYPOINT ["./my_exe"] diff --git a/dev/docker/ubuntu_node.dockerfile b/dev/docker/ubuntu_node.dockerfile index 29d53ec7..8ec3fa64 100644 --- a/dev/docker/ubuntu_node.dockerfile +++ b/dev/docker/ubuntu_node.dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:devel +FROM ubuntu:devel AS base RUN apt-get update -qq RUN apt-get install -y --no-install-recommends nodejs @@ -8,9 +8,20 @@ ADD "./dist/" "/" WORKDIR "/" # run installation -RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true +RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --make true -# reload the environment and print the versions -CMD source ~/.cpprc && clang --version && cmake --version && ninja --version && ccache --version && cppcheck --version && vcpkg --version && doxygen --version && dot --version && gcovr --version +CMD source ~/.cpprc +ENTRYPOINT [ "/bin/sh" ] -ENTRYPOINT [ "/bin/sh" ] \ No newline at end of file +#### Building +FROM base AS builder +ADD ./dev/cpp_vcpkg_project /home/app +WORKDIR /home/app +RUN make build + +### Running environment +FROM gcr.io/distroless/cc +# copy the built binaries and their runtime dependencies +COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ +WORKDIR /home/app/ +ENTRYPOINT ["./my_exe"] diff --git a/dev/docker/ubuntu_stable_node.dockerfile b/dev/docker/ubuntu_stable_node.dockerfile index 717de80f..8b3d9734 100644 --- a/dev/docker/ubuntu_stable_node.dockerfile +++ b/dev/docker/ubuntu_stable_node.dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM ubuntu:20.04 AS base # set time-zone ENV TZ=Canada/Pacific @@ -16,9 +16,20 @@ ADD "./dist/" "/" WORKDIR "/" # run installation -RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true +RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --make true -# reload the environment and print the versions -CMD source ~/.cpprc && clang --version && cmake --version && ninja --version && ccache --version && cppcheck --version && vcpkg --version && doxygen --version && dot --version && gcovr --version +CMD source ~/.cpprc +ENTRYPOINT [ "/bin/sh" ] -ENTRYPOINT [ "/bin/sh" ] \ No newline at end of file +#### Building +FROM base AS builder +ADD ./dev/cpp_vcpkg_project /home/app +WORKDIR /home/app +RUN make build + +### Running environment +FROM gcr.io/distroless/cc +# copy the built binaries and their runtime dependencies +COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ +WORKDIR /home/app/ +ENTRYPOINT ["./my_exe"]