From 997b6725fea73f1baab97abe3e88ed8e9f17e755 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 26 Apr 2022 22:07:54 -0700 Subject: [PATCH 1/5] chore: rename building path to dev --- .github/workflows/CI.yml | 2 +- README.md | 6 +++--- {building => dev}/docker/ubuntu.dockerfile | 0 {building => dev}/docker/ubuntu_node.dockerfile | 0 {building => dev}/docker/ubuntu_stable_node.dockerfile | 0 {building => dev}/scripts/debug_remove.js | 0 {building => dev}/scripts/pack-exe.js | 0 package.json | 4 ++-- 8 files changed, 6 insertions(+), 6 deletions(-) rename {building => dev}/docker/ubuntu.dockerfile (100%) rename {building => dev}/docker/ubuntu_node.dockerfile (100%) rename {building => dev}/docker/ubuntu_stable_node.dockerfile (100%) rename {building => dev}/scripts/debug_remove.js (100%) rename {building => dev}/scripts/pack-exe.js (100%) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b3cd0b4d..89bb57fc 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -127,6 +127,6 @@ jobs: - name: Build id: docker_build run: | - docker build -f ./building/docker/${{ matrix.container }} -t setup_cpp . + docker build -f ./dev/docker/${{ matrix.container }} -t setup_cpp . env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true diff --git a/README.md b/README.md index 9c97ee27..b4909739 100644 --- a/README.md +++ b/README.md @@ -197,12 +197,12 @@ RUN source ~/.cpprc ENTRYPOINT [ "/bin/sh" ] ``` -See [this folder](https://github.com/aminya/setup-cpp/tree/master/building/docker), for some dockerfile examples. +See [this folder](https://github.com/aminya/setup-cpp/tree/master/dev/docker), for some dockerfile examples. If you want to build the ones included, then run: ```ps1 -docker build -f ./building/docker/ubuntu.dockerfile -t setup_cpp . +docker build -f ./dev/docker/ubuntu.dockerfile -t setup_cpp . ``` Where you should use the path to the dockerfile after `-f`. @@ -230,7 +230,7 @@ jobs: - name: Build id: docker_build run: | - docker build -f ./building/docker/debian.dockerfile -t setup_cpp . + docker build -f ./dev/docker/debian.dockerfile -t setup_cpp . env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true ``` diff --git a/building/docker/ubuntu.dockerfile b/dev/docker/ubuntu.dockerfile similarity index 100% rename from building/docker/ubuntu.dockerfile rename to dev/docker/ubuntu.dockerfile diff --git a/building/docker/ubuntu_node.dockerfile b/dev/docker/ubuntu_node.dockerfile similarity index 100% rename from building/docker/ubuntu_node.dockerfile rename to dev/docker/ubuntu_node.dockerfile diff --git a/building/docker/ubuntu_stable_node.dockerfile b/dev/docker/ubuntu_stable_node.dockerfile similarity index 100% rename from building/docker/ubuntu_stable_node.dockerfile rename to dev/docker/ubuntu_stable_node.dockerfile diff --git a/building/scripts/debug_remove.js b/dev/scripts/debug_remove.js similarity index 100% rename from building/scripts/debug_remove.js rename to dev/scripts/debug_remove.js diff --git a/building/scripts/pack-exe.js b/dev/scripts/pack-exe.js similarity index 100% rename from building/scripts/pack-exe.js rename to dev/scripts/pack-exe.js diff --git a/package.json b/package.json index e326a34a..a026608e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "scripts": { "build": "run-p test.tsc build.parcel copy.matchers", - "build.docker": "pnpm build && docker build -f ./building/docker/ubuntu_node.dockerfile -t setup_cpp .", + "build.docker": "pnpm build && docker build -f ./dev/docker/ubuntu_node.dockerfile -t setup_cpp .", "build.parcel": "shx rm -rf ./dist/*.js ./dist/*.js.map && cross-env NODE_ENV=production parcel build --detailed-report", "bump": "ncu -u -x execa && pnpm update", "clean": "shx rm -rf .parcel-cache dist exe", @@ -21,7 +21,7 @@ "dev": "cross-env NODE_ENV=development parcel watch", "format": "prettier --write .", "lint": "eslint . --fix", - "pack.exe": "shx rm -rf ./dist/tsconfig.tsbuildinfo && node ./building/scripts/pack-exe.js", + "pack.exe": "shx rm -rf ./dist/tsconfig.tsbuildinfo && node ./dev/scripts/pack-exe.js", "prepare": "npm run build", "start.docker": "docker run -t setup_cpp .", "test": "run-p test.format test.lint test.cspell test.tsc test.unit", From f9a84c82e80e2dad5cdf7ebf08c425769f36cf36 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 26 Apr 2022 22:13:54 -0700 Subject: [PATCH 2/5] chore: add cpp_vcpkg_project as an example --- .eslintrc.json | 2 +- .gitmodules | 3 +++ .prettierignore | 1 + dev/cpp_vcpkg_project | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 dev/cpp_vcpkg_project diff --git a/.eslintrc.json b/.eslintrc.json index 2f460539..7d6c702d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,4 @@ { "extends": "eslint-config-atomic", - "ignorePatterns": ["dist/", "node_modules/"] + "ignorePatterns": ["dist/", "node_modules/", "dev/cpp_vcpkg_project"] } diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..7d28b8b0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dev/cpp_vcpkg_project"] + path = dev/cpp_vcpkg_project + url = https://github.com/aminya/cpp_vcpkg_project diff --git a/.prettierignore b/.prettierignore index 833fbbde..1f9b46de 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,3 +6,4 @@ dist stats.html src/python/setup-python/ src/msvc/msvc-dev-cmd/ +dev/cpp_vcpkg_project diff --git a/dev/cpp_vcpkg_project b/dev/cpp_vcpkg_project new file mode 160000 index 00000000..f4fe2164 --- /dev/null +++ b/dev/cpp_vcpkg_project @@ -0,0 +1 @@ +Subproject commit f4fe216401a8eac95d66969f0ee2b760b3c4edf0 From e379435d81dae01f876ce3a8b8166c2be2b0b0a8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 26 Apr 2022 22:33:36 -0700 Subject: [PATCH 3/5] 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"] From acb5fbf1628910d3db4e6bb9c0324368754e6b91 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 26 Apr 2022 22:52:01 -0700 Subject: [PATCH 4/5] docker: source ~/.cpprc in the builder step [skip test] --- README.md | 2 +- dev/docker/ubuntu.dockerfile | 5 +++-- dev/docker/ubuntu_node.dockerfile | 5 +++-- dev/docker/ubuntu_stable_node.dockerfile | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 42797ea4..c07397f1 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true # activate cpp environment variables RUN source ~/.cpprc -ENTRYPOINT [ "/bin/sh" ] +ENTRYPOINT [ "/bin/bash" ] ``` See [this folder](https://github.com/aminya/setup-cpp/tree/master/dev/docker), for some dockerfile examples. diff --git a/dev/docker/ubuntu.dockerfile b/dev/docker/ubuntu.dockerfile index 127d5937..cc091a9a 100644 --- a/dev/docker/ubuntu.dockerfile +++ b/dev/docker/ubuntu.dockerfile @@ -12,13 +12,14 @@ RUN chmod +x ./setup_cpp_linux RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --make true CMD source ~/.cpprc -ENTRYPOINT [ "/bin/sh" ] +ENTRYPOINT [ "/bin/bash" ] #### Building FROM base AS builder ADD ./dev/cpp_vcpkg_project /home/app WORKDIR /home/app -RUN make build +RUN bash -c 'source ~/.cpprc \ + && make build' ### Running environment FROM gcr.io/distroless/cc diff --git a/dev/docker/ubuntu_node.dockerfile b/dev/docker/ubuntu_node.dockerfile index 8ec3fa64..fbfd84d8 100644 --- a/dev/docker/ubuntu_node.dockerfile +++ b/dev/docker/ubuntu_node.dockerfile @@ -11,13 +11,14 @@ WORKDIR "/" RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --make true CMD source ~/.cpprc -ENTRYPOINT [ "/bin/sh" ] +ENTRYPOINT [ "/bin/bash" ] #### Building FROM base AS builder ADD ./dev/cpp_vcpkg_project /home/app WORKDIR /home/app -RUN make build +RUN bash -c 'source ~/.cpprc \ + && make build' ### Running environment FROM gcr.io/distroless/cc diff --git a/dev/docker/ubuntu_stable_node.dockerfile b/dev/docker/ubuntu_stable_node.dockerfile index 8b3d9734..21d1910c 100644 --- a/dev/docker/ubuntu_stable_node.dockerfile +++ b/dev/docker/ubuntu_stable_node.dockerfile @@ -19,13 +19,14 @@ WORKDIR "/" RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --make true CMD source ~/.cpprc -ENTRYPOINT [ "/bin/sh" ] +ENTRYPOINT [ "/bin/bash" ] #### Building FROM base AS builder ADD ./dev/cpp_vcpkg_project /home/app WORKDIR /home/app -RUN make build +RUN bash -c 'source ~/.cpprc \ + && make build' ### Running environment FROM gcr.io/distroless/cc From e982b8598f0c0ee93cbfc96e11a8ae49e07b6142 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 26 Apr 2022 23:05:25 -0700 Subject: [PATCH 5/5] docs: update the readme docker [skip ci] --- README.md | 24 +++++++++++++++++++----- dev/docker/ubuntu.dockerfile | 1 + dev/docker/ubuntu_node.dockerfile | 1 + dev/docker/ubuntu_stable_node.dockerfile | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c07397f1..fa456a5d 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,8 @@ jobs: Here is an example for using setup_cpp to make a builder image that has the Cpp tools you need. ```dockerfile -FROM ubuntu:devel +#### Base Image +FROM ubuntu:devel AS base # add setup_cpp WORKDIR "/" @@ -189,12 +190,25 @@ 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 - -# activate cpp environment variables -RUN source ~/.cpprc +RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --make true +CMD source ~/.cpprc ENTRYPOINT [ "/bin/bash" ] + +#### Building +FROM base AS builder +ADD ./dev/cpp_vcpkg_project /home/app +WORKDIR /home/app +RUN bash -c 'source ~/.cpprc \ + && make build' + +### Running environment +# use a distroless image or ubuntu:devel if you wish +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"] ``` See [this folder](https://github.com/aminya/setup-cpp/tree/master/dev/docker), for some dockerfile examples. diff --git a/dev/docker/ubuntu.dockerfile b/dev/docker/ubuntu.dockerfile index cc091a9a..e1e9ed09 100644 --- a/dev/docker/ubuntu.dockerfile +++ b/dev/docker/ubuntu.dockerfile @@ -22,6 +22,7 @@ RUN bash -c 'source ~/.cpprc \ && make build' ### Running environment +# use a distroless image or ubuntu:devel if you wish FROM gcr.io/distroless/cc # copy the built binaries and their runtime dependencies COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ diff --git a/dev/docker/ubuntu_node.dockerfile b/dev/docker/ubuntu_node.dockerfile index fbfd84d8..1bbd70be 100644 --- a/dev/docker/ubuntu_node.dockerfile +++ b/dev/docker/ubuntu_node.dockerfile @@ -21,6 +21,7 @@ RUN bash -c 'source ~/.cpprc \ && make build' ### Running environment +# use a distroless image or ubuntu:devel if you wish FROM gcr.io/distroless/cc # copy the built binaries and their runtime dependencies COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ diff --git a/dev/docker/ubuntu_stable_node.dockerfile b/dev/docker/ubuntu_stable_node.dockerfile index 21d1910c..b4120ac7 100644 --- a/dev/docker/ubuntu_stable_node.dockerfile +++ b/dev/docker/ubuntu_stable_node.dockerfile @@ -29,6 +29,7 @@ RUN bash -c 'source ~/.cpprc \ && make build' ### Running environment +# use a distroless image or ubuntu:20.04 if you wish FROM gcr.io/distroless/cc # copy the built binaries and their runtime dependencies COPY --from=builder /home/app/build/my_exe/Release/ /home/app/