From 73478bbe8cb697ae696dc3b600d4292665c7dd20 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 15 Jul 2023 15:05:41 -0700 Subject: [PATCH] feat: add separate production and testing docker files --- .dockerignore | 25 +++++++-- .github/workflows/CI.yml | 26 +++++++-- README.md | 28 +++++----- .../arch.dockerfile} | 27 +++------- .../__tests__}/arch.yml | 0 .../fedora.dockerfile} | 24 +++------ .../__tests__}/fedora.yml | 0 dev/docker/__tests__/ubuntu.dockerfile | 30 +++++++++++ .../__tests__}/ubuntu.yml | 0 dev/docker/arch.dockerfile | 28 ++++++++++ dev/docker/fedora.dockerfile | 26 +++++++++ dev/docker/ubuntu.dockerfile | 16 +++--- dev/docker/ubuntu_node.dockerfile | 54 ------------------- 13 files changed, 162 insertions(+), 122 deletions(-) rename dev/docker/{arch_node.dockerfile => __tests__/arch.dockerfile} (58%) rename dev/{container-tests => docker/__tests__}/arch.yml (100%) rename dev/docker/{fedora_node.dockerfile => __tests__/fedora.dockerfile} (63%) rename dev/{container-tests => docker/__tests__}/fedora.yml (100%) create mode 100644 dev/docker/__tests__/ubuntu.dockerfile rename dev/{container-tests => docker/__tests__}/ubuntu.yml (100%) create mode 100644 dev/docker/arch.dockerfile create mode 100644 dev/docker/fedora.dockerfile delete mode 100644 dev/docker/ubuntu_node.dockerfile diff --git a/.dockerignore b/.dockerignore index 23883578..43e563c4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,20 @@ -.parcel-cache/ -node_modules/ -dev/docker/ -dev/container-tests/ -dist/ \ No newline at end of file +.git/ +# OS metadata +**/.DS_Store +**/Thumbs.db + +# Node +**/node_modules +**/package-lock.json +**/temp-* + +# TypeScript +**/*.tsbuildinfo + +# Build directories +**/packages/*/dist/ +**/.parcel-cache +**/exe/ +**/*.log +**/*.exe +**/.cache/ diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c810a431..c5b9565e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -132,10 +132,14 @@ jobs: matrix: os: - ubuntu-22.04 + node: + - 18 + pnpm: + - 8 container: - - "arch_node.dockerfile" - - "fedora_node.dockerfile" - - "ubuntu_node.dockerfile" + - "./dev/docker/__tests__/arch.dockerfile" + - "./dev/docker/__tests__/fedora.dockerfile" + - "./dev/docker/__tests__/ubuntu.dockerfile" steps: - uses: actions/checkout@v3 with: @@ -151,7 +155,21 @@ jobs: restore-keys: | "setupcpp-docker-cache-OS:${{ matrix.os }}" + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + + - name: Setup Pnpm + uses: pnpm/action-setup@v2 + with: + version: ${{ matrix.pnpm }} + + - name: Install and build + run: | + pnpm install + - name: Build id: docker_build run: | - docker build -f ./dev/docker/${{ matrix.container }} -t setup-cpp . + docker build -f ${{ matrix.container }} -t setup-cpp . diff --git a/README.md b/README.md index 40dfa519..da29897d 100644 --- a/README.md +++ b/README.md @@ -153,29 +153,29 @@ Here is an example for using setup-cpp to make a builder image that has the Cpp ```dockerfile #### Base Image -FROM ubuntu:22.04 AS base +FROM ubuntu:22.04 as base -# add setup-cpp -RUN apt-get update -qq -RUN apt-get install -y --no-install-recommends npm -RUN npm install -g setup-cpp +# install nodejs and setup-cpp +RUN apt-get update -qq && \ + apt-get install -y --no-install-recommends nodejs npm && \ + npm install -g setup-cpp # install llvm, cmake, ninja, and ccache -RUN setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --make true +RUN setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --task true -CMD source ~/.cpprc -ENTRYPOINT [ "/bin/bash" ] +ENTRYPOINT ["/bin/bash"] -#### Building -FROM base AS builder -ADD ./dev/cpp_vcpkg_project /home/app +#### Building (example) +FROM base as builder +COPY ./dev/cpp_vcpkg_project /home/app WORKDIR /home/app RUN bash -c 'source ~/.cpprc \ - && make build' + && task build' + ### Running environment # use a distroless image or ubuntu:22.04 if you wish -FROM gcr.io/distroless/cc +FROM gcr.io/distroless/cc as runner # copy the built binaries and their runtime dependencies COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ WORKDIR /home/app/ @@ -217,7 +217,7 @@ jobs: - name: Build id: docker_build run: | - docker build -f ./dev/docker/debian.dockerfile -t setup-cpp . + docker build -f ./dev/docker/ubuntu.dockerfile -t setup-cpp . ``` ### Inside GitLab pipelines diff --git a/dev/docker/arch_node.dockerfile b/dev/docker/__tests__/arch.dockerfile similarity index 58% rename from dev/docker/arch_node.dockerfile rename to dev/docker/__tests__/arch.dockerfile index 002366c9..e9bbea24 100644 --- a/dev/docker/arch_node.dockerfile +++ b/dev/docker/__tests__/arch.dockerfile @@ -1,28 +1,18 @@ ## base image FROM archlinux as base -# install nodejs and pnpm -RUN pacman -Syuu --noconfirm && pacman-db-upgrade && pacman -S --noconfirm --needed nodejs npm git \ - && npm install -g pnpm +# install nodejs +RUN pacman -Syuu --noconfirm && \ + pacman-db-upgrade && \ + pacman -S --noconfirm --needed nodejs +# add setup-cpp.js (built outside of this dockerfile) +COPY "./dist/node18" "/" -#### Building -FROM base AS builder -## https://github.com/ever0de/pnpm-docker-root-bug#how-to-fix -WORKDIR /workspace -COPY . . -RUN pnpm install - - -#### setup-cpp -FROM base AS setup-cpp -# add setup-cpp.js -COPY --from=builder /workspace/dist/node18 / # run installation -RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true -CMD ["source", "~/.cpprc"] -ENTRYPOINT ["/bin/bash"] +RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true +ENTRYPOINT ["/bin/bash"] #### Building (example) FROM setup-cpp AS example-builder @@ -31,7 +21,6 @@ WORKDIR /home/app RUN bash -c 'source ~/.cpprc \ && task build' - #### Running environment # use a distroless image or ubuntu:22.04 if you wish FROM gcr.io/distroless/cc as runner diff --git a/dev/container-tests/arch.yml b/dev/docker/__tests__/arch.yml similarity index 100% rename from dev/container-tests/arch.yml rename to dev/docker/__tests__/arch.yml diff --git a/dev/docker/fedora_node.dockerfile b/dev/docker/__tests__/fedora.dockerfile similarity index 63% rename from dev/docker/fedora_node.dockerfile rename to dev/docker/__tests__/fedora.dockerfile index 46c0d4d6..871da893 100644 --- a/dev/docker/fedora_node.dockerfile +++ b/dev/docker/__tests__/fedora.dockerfile @@ -1,28 +1,17 @@ ## base image FROM fedora as base -# nodejs and curl for downloading setup-cpp -RUN dnf -y install nodejs npm curl git && dnf clean all \ - && npm install -g pnpm +# install nodejs and setup-cpp +RUN dnf -y install nodejs npm && \ + npm install -g setup-cpp +# add setup-cpp.js (built outside of this dockerfile) +COPY "./dist/node18" "/" -#### Building -FROM base AS builder -## https://github.com/ever0de/pnpm-docker-root-bug#how-to-fix -WORKDIR /workspace -COPY . . -RUN pnpm install - - -#### setup-cpp -FROM base AS setup-cpp -# add setup-cpp.js -COPY --from=builder /workspace/dist/node18 / # run installation RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true -CMD ["source", "~/.cpprc"] -ENTRYPOINT ["/bin/bash"] +ENTRYPOINT ["/bin/bash"] #### Building (example) FROM setup-cpp AS example-builder @@ -31,7 +20,6 @@ WORKDIR /home/app RUN bash -c 'source ~/.cpprc \ && task build' - #### Running environment # use a distroless image or ubuntu:22.04 if you wish FROM gcr.io/distroless/cc as runner diff --git a/dev/container-tests/fedora.yml b/dev/docker/__tests__/fedora.yml similarity index 100% rename from dev/container-tests/fedora.yml rename to dev/docker/__tests__/fedora.yml diff --git a/dev/docker/__tests__/ubuntu.dockerfile b/dev/docker/__tests__/ubuntu.dockerfile new file mode 100644 index 00000000..b063c5e8 --- /dev/null +++ b/dev/docker/__tests__/ubuntu.dockerfile @@ -0,0 +1,30 @@ +#### Base Image +FROM ubuntu:22.04 as base + +# install nodejs and setup-cpp +RUN apt-get update -qq && \ + apt-get install -y --no-install-recommends nodejs + +# add setup-cpp.js (built outside of this dockerfile) +COPY "./dist/node18" "/" + +# install setup-cpp +RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --task true + +ENTRYPOINT ["/bin/bash"] + +#### Building +FROM base as builder +COPY ./dev/cpp_vcpkg_project /home/app +WORKDIR /home/app +RUN bash -c 'source ~/.cpprc \ + && task build' + + +### Running environment +# use a distroless image or ubuntu:22.04 if you wish +FROM gcr.io/distroless/cc as runner +# 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/container-tests/ubuntu.yml b/dev/docker/__tests__/ubuntu.yml similarity index 100% rename from dev/container-tests/ubuntu.yml rename to dev/docker/__tests__/ubuntu.yml diff --git a/dev/docker/arch.dockerfile b/dev/docker/arch.dockerfile new file mode 100644 index 00000000..9ceda45b --- /dev/null +++ b/dev/docker/arch.dockerfile @@ -0,0 +1,28 @@ +## base image +FROM archlinux as base + +# install nodejs and setup-cpp +RUN pacman -Syuu --noconfirm && \ + pacman-db-upgrade && \ + pacman -S --noconfirm --needed nodejs npm && \ + npm install -g setup-cpp + +# run installation +RUN setup-cpp --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true + +ENTRYPOINT ["/bin/bash"] + +#### Building (example) +FROM base AS example-builder +COPY ./dev/cpp_vcpkg_project /home/app +WORKDIR /home/app +RUN bash -c 'source ~/.cpprc \ + && task build' + +#### Running environment +# use a distroless image or ubuntu:22.04 if you wish +FROM gcr.io/distroless/cc as runner +# copy the built binaries and their runtime dependencies +COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/ +WORKDIR /home/app/ +ENTRYPOINT ["./my_exe"] diff --git a/dev/docker/fedora.dockerfile b/dev/docker/fedora.dockerfile new file mode 100644 index 00000000..233d627c --- /dev/null +++ b/dev/docker/fedora.dockerfile @@ -0,0 +1,26 @@ +## base image +FROM fedora as base + +# install nodejs and setup-cpp +RUN dnf -y install nodejs npm && \ + npm install -g setup-cpp + +# run installation +RUN setup-cpp --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true + +ENTRYPOINT ["/bin/bash"] + +#### Building (example) +FROM base AS example-builder +COPY ./dev/cpp_vcpkg_project /home/app +WORKDIR /home/app +RUN bash -c 'source ~/.cpprc \ + && task build' + +#### Running environment +# use a distroless image or ubuntu:22.04 if you wish +FROM gcr.io/distroless/cc as runner +# copy the built binaries and their runtime dependencies +COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/ +WORKDIR /home/app/ +ENTRYPOINT ["./my_exe"] diff --git a/dev/docker/ubuntu.dockerfile b/dev/docker/ubuntu.dockerfile index 5f8acaba..4b366b24 100644 --- a/dev/docker/ubuntu.dockerfile +++ b/dev/docker/ubuntu.dockerfile @@ -1,17 +1,17 @@ #### Base Image FROM ubuntu:22.04 as base -# install setup-cpp -RUN apt-get update -qq && apt-get install -y --no-install-recommends npm git curl && rm -rf /var/lib/apt/lists/* \ - && npm install -g setup-cpp \ -# install llvm, cmake, ninja, and ccache - && setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --task true +# install nodejs and setup-cpp +RUN apt-get update -qq && \ + apt-get install -y --no-install-recommends nodejs npm && \ + npm install -g setup-cpp + +# install llvm, cmake, ninja, and ccache +RUN setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --task true -CMD ["source", "~/.cpprc"] ENTRYPOINT ["/bin/bash"] - -#### Building +#### Building (example) FROM base as builder COPY ./dev/cpp_vcpkg_project /home/app WORKDIR /home/app diff --git a/dev/docker/ubuntu_node.dockerfile b/dev/docker/ubuntu_node.dockerfile deleted file mode 100644 index abea3290..00000000 --- a/dev/docker/ubuntu_node.dockerfile +++ /dev/null @@ -1,54 +0,0 @@ -FROM ubuntu:22.04 AS base - -# install node with nvm -RUN apt-get update -qq && apt-get install -y --no-install-recommends git curl wget ca-certificates && rm -rf /var/lib/apt/lists/* -ARG nvm_version="0.39.3" -ARG node_version="18.15.0" -ENV NVM_DIR /usr/local/nvm -RUN mkdir $NVM_DIR -ADD https://raw.githubusercontent.com/nvm-sh/nvm/v${nvm_version}/install.sh /tmp/nvm_install.sh -RUN chmod +x /tmp/nvm_install.sh && /tmp/nvm_install.sh \ - && . $NVM_DIR/nvm.sh \ - && nvm install $node_version \ - && nvm alias default $node_version \ - && nvm use default -ENV NODE_PATH $NVM_DIR/v${node_version}/lib/node_modules -ENV PATH $NVM_DIR/versions/node/v${node_version}/bin:$PATH - -# install pnpm -RUN npm install -g pnpm - - -#### Building -FROM base AS builder -## https://github.com/ever0de/pnpm-docker-root-bug#how-to-fix -WORKDIR /workspace -COPY . . -RUN pnpm install - - -#### setup-cpp -FROM base AS setup-cpp -# add setup-cpp.js -COPY --from=builder /workspace/dist/node18 / -# run installation -RUN . "${NVM_DIR}/nvm.sh" && node /setup-cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true -CMD ["source", "~/.cpprc"] -ENTRYPOINT ["/bin/bash"] - - -#### Building (example) -FROM setup-cpp AS example-builder -COPY ./dev/cpp_vcpkg_project /home/app -WORKDIR /home/app -RUN bash -c 'source ~/.cpprc \ - && task build' - - -#### Running environment -# use a distroless image or ubuntu:22.04 if you wish -FROM gcr.io/distroless/cc as runner -# copy the built binaries and their runtime dependencies -COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/ -WORKDIR /home/app/ -ENTRYPOINT ["./my_exe"]