feat: add production docker images and generate tests

This commit is contained in:
Amin Yahyaabadi 2023-07-15 18:06:32 -07:00
parent c5d5df5b33
commit cd31ee43de
27 changed files with 254 additions and 127 deletions

View File

@ -172,6 +172,7 @@ jobs:
- name: Install and build - name: Install and build
run: | run: |
pnpm install pnpm install
pnpm build.docker_tests
- name: Build - name: Build
id: docker_build id: docker_build

View File

@ -1,30 +1,47 @@
## base image ## base image
FROM archlinux as base FROM archlinux:base as setup-cpp-arch
COPY "./dist/legacy" "/usr/lib/setup-cpp/"
# install nodejs
RUN pacman -Syuu --noconfirm && \ RUN pacman -Syuu --noconfirm && \
pacman-db-upgrade && \ pacman-db-upgrade && \
pacman -S --noconfirm --needed nodejs # install nodejs
pacman -S --noconfirm --needed nodejs npm && \
# add setup-cpp.js (built outside of this dockerfile) # install setup-cpp
COPY "./dist/legacy" "/" npm install -g setup-cpp@v0.30.1 && \
# install the compiler and tools
# run installation node /usr/lib/setup-cpp/setup-cpp.js \
RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --compiler llvm \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true && \
# arch cleanup
pacman -Scc --noconfirm && \
rm -rf /var/cache/pacman/pkg/* && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"] ENTRYPOINT ["/bin/bash"]
#### Building (example) #### Building (example)
FROM base AS example-builder FROM setup-cpp-arch AS builder
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \ RUN bash -c 'source ~/.cpprc \
&& task build' && task build'
#### Running environment #### Running environment
# use a distroless image or ubuntu:22.04 if you wish # use a fresh image as the runner
FROM gcr.io/distroless/cc as runner FROM archlinux:base as runner
# copy the built binaries and their runtime dependencies # copy the built binaries and their runtime dependencies
COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/
ENTRYPOINT ["./my_exe"] ENTRYPOINT ["./my_exe"]

View File

@ -1,29 +1,44 @@
## base image ## base image
FROM fedora as base FROM fedora:38 as setup-cpp-fedora
# install nodejs and setup-cpp COPY "./dist/legacy" "/usr/lib/setup-cpp/"
RUN dnf -y install nodejs npm && \
npm install -g setup-cpp
# add setup-cpp.js (built outside of this dockerfile) # install nodejs
COPY "./dist/legacy" "/" RUN dnf -y install nodejs-20 npm-9 && \
# install setup-cpp
# run installation npm install -g setup-cpp@v0.30.1 && \
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 # install the compiler and tools
node /usr/lib/setup-cpp/setup-cpp.js \
--compiler llvm \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true && \
# cleanup
dnf clean all && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"] ENTRYPOINT ["/bin/bash"]
#### Building (example) #### Building (example)
FROM base AS example-builder FROM setup-cpp-fedora AS builder
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \ RUN bash -c 'source ~/.cpprc \
&& task build' && task build'
#### Running environment #### Running environment
# use a distroless image or ubuntu:22.04 if you wish # use a fresh image as the runner
FROM gcr.io/distroless/cc as runner FROM fedora:38 as runner
# copy the built binaries and their runtime dependencies # copy the built binaries and their runtime dependencies
COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/
ENTRYPOINT ["./my_exe"] ENTRYPOINT ["./my_exe"]

View File

@ -1,29 +1,49 @@
#### Base Image #### Base Image
FROM ubuntu:22.04 as base FROM ubuntu:22.04 as setup-cpp-ubuntu
COPY "./dist/legacy" "/usr/lib/setup-cpp/"
# install nodejs and setup-cpp
RUN apt-get update -qq && \ RUN apt-get update -qq && \
apt-get install -y --no-install-recommends nodejs # install nodejs
apt-get install -y --no-install-recommends nodejs npm && \
# add setup-cpp.js (built outside of this dockerfile)
COPY "./dist/legacy" "/"
# install setup-cpp # install setup-cpp
RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --task true npm install -g setup-cpp@v0.30.1 && \
# install the compiler and tools
node /usr/lib/setup-cpp/setup-cpp.js \
--nala true \
--compiler llvm \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true && \
# cleanup
nala autoremove -y && \
nala autopurge -y && \
apt-get clean && \
nala clean --lists && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"] ENTRYPOINT ["/bin/bash"]
#### Building #### Building (example)
FROM base as builder FROM setup-cpp-ubuntu AS builder
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \ RUN bash -c 'source ~/.cpprc \
&& task build' && task build'
#### Running environment
# use a fresh image as the runner
FROM ubuntu:22.04 as runner
### 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 the built binaries and their runtime dependencies
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/

View File

@ -1,28 +1,16 @@
## 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) #### Building (example)
FROM base AS example-builder FROM setup-cpp-arch AS builder
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \ RUN bash -c 'source ~/.cpprc \
&& task build' && task build'
#### Running environment #### Running environment
# use a distroless image or ubuntu:22.04 if you wish # use a fresh image as the runner
FROM gcr.io/distroless/cc as runner FROM archlinux:base as runner
# copy the built binaries and their runtime dependencies # copy the built binaries and their runtime dependencies
COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/
ENTRYPOINT ["./my_exe"] ENTRYPOINT ["./my_exe"]

View File

@ -1,26 +1,16 @@
## 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) #### Building (example)
FROM base AS example-builder FROM setup-cpp-fedora AS builder
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \ RUN bash -c 'source ~/.cpprc \
&& task build' && task build'
#### Running environment #### Running environment
# use a distroless image or ubuntu:22.04 if you wish # use a fresh image as the runner
FROM gcr.io/distroless/cc as runner FROM fedora:38 as runner
# copy the built binaries and their runtime dependencies # copy the built binaries and their runtime dependencies
COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/
ENTRYPOINT ["./my_exe"] ENTRYPOINT ["./my_exe"]

View File

@ -0,0 +1,28 @@
## base image
FROM archlinux:base as setup-cpp-arch
RUN pacman -Syuu --noconfirm && \
pacman-db-upgrade && \
# install nodejs
pacman -S --noconfirm --needed nodejs npm && \
# install setup-cpp
npm install -g setup-cpp@v0.30.1 && \
# install the compiler and tools
setup-cpp \
--compiler llvm \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true && \
# arch cleanup
pacman -Scc --noconfirm && \
rm -rf /var/cache/pacman/pkg/* && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"]

View File

@ -0,0 +1,25 @@
## base image
FROM fedora:38 as setup-cpp-fedora
# install nodejs
RUN dnf -y install nodejs-20 npm-9 && \
# install setup-cpp
npm install -g setup-cpp@v0.30.1 && \
# install the compiler and tools
setup-cpp \
--compiler llvm \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true && \
# cleanup
dnf clean all && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"]

View File

@ -0,0 +1,31 @@
#### Base Image
FROM ubuntu:22.04 as setup-cpp-ubuntu
RUN apt-get update -qq && \
# install nodejs
apt-get install -y --no-install-recommends nodejs npm && \
# install setup-cpp
npm install -g setup-cpp@v0.30.1 && \
# install the compiler and tools
setup-cpp \
--nala true \
--compiler llvm \
--cmake true \
--ninja true \
--task true \
--vcpkg true \
--python true \
--make true \
--cppcheck true \
--gcovr true \
--doxygen true \
--ccache true && \
# cleanup
nala autoremove -y && \
nala autopurge -y && \
apt-get clean && \
nala clean --lists && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"]

View File

@ -1,27 +1,15 @@
#### 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 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
ENTRYPOINT ["/bin/bash"]
#### Building (example) #### Building (example)
FROM base as builder FROM setup-cpp-ubuntu AS builder
COPY ./dev/cpp_vcpkg_project /home/app COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \ RUN bash -c 'source ~/.cpprc \
&& task build' && task build'
#### Running environment
# use a fresh image as the runner
FROM ubuntu:22.04 as runner
### 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 the built binaries and their runtime dependencies
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/ COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/ WORKDIR /home/app/

View File

@ -0,0 +1,24 @@
import { readFile, writeFile } from "fs/promises"
async function main() {
const dockerFiles = ["ubuntu", "arch", "fedora"]
await Promise.all(
dockerFiles.map(async (dockerFile) => {
const dockerFileContent = await readFile(`./dev/docker/setup-cpp-${dockerFile}.dockerfile`, "utf-8")
const builderExample = await readFile(`./dev/docker/${dockerFile}.dockerfile`, "utf-8")
// after the first FROM, add COPY "./dist/legacy" "/"
const modifiedDockerFile = dockerFileContent
.replace(/FROM (.*)/g, `FROM $1\n\nCOPY "./dist/legacy" "/usr/lib/setup-cpp/"`)
.replace("setup-cpp ", "node /usr/lib/setup-cpp/setup-cpp.js ")
// concat the two files
const newDockerFileContent = `${modifiedDockerFile}\n${builderExample}`
// write the new file in dev/docker/__tests__
await writeFile(`./dev/docker/__tests__/${dockerFile}.dockerfile`, newDockerFileContent)
})
)
}
await main()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,7 @@
"src", "src",
"packages", "packages",
"dev/docker", "dev/docker",
"dev/container-tests", "dev/docker/__tests__",
"README.md", "README.md",
"LICENSE.txt", "LICENSE.txt",
"LICENSE.dependencies.txt", "LICENSE.dependencies.txt",
@ -29,10 +29,6 @@
], ],
"scripts": { "scripts": {
"build": "shx rm -rf dist/ && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern && run-p lint.tsc build.parcel copy.matchers", "build": "shx rm -rf dist/ && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern && run-p lint.tsc build.parcel copy.matchers",
"build.docker": "pnpm build && docker build -f ./dev/docker/ubuntu_node.dockerfile -t setup-cpp .",
"build.docker.arch": "pnpm build && docker build -f ./dev/docker/arch_node.dockerfile -t setup-cpp:arch .",
"build.docker.fedora": "pnpm build && docker build -f ./dev/docker/fedora_node.dockerfile -t setup-cpp:fedora .",
"build.docker.ubuntu": "pnpm build && docker build -f ./dev/docker/ubuntu_node.dockerfile -t setup-cpp:ubuntu .",
"build.parcel": "cross-env NODE_ENV=production parcel build && babel ./dist --out-dir dist --plugins @upleveled/babel-plugin-remove-node-prefix --compact --no-babelrc --source-maps true", "build.parcel": "cross-env NODE_ENV=production parcel build && babel ./dist --out-dir dist --plugins @upleveled/babel-plugin-remove-node-prefix --compact --no-babelrc --source-maps true",
"bump": "ncu -u -x numerous && pnpm update", "bump": "ncu -u -x numerous && pnpm update",
"clean": "shx rm -rf .parcel-cache dist exe", "clean": "shx rm -rf .parcel-cache dist exe",
@ -55,13 +51,17 @@
"start.docker.fedora": "docker run -t setup-cpp:fedora .", "start.docker.fedora": "docker run -t setup-cpp:fedora .",
"start.docker.ubuntu": "docker run -t setup-cpp:ubuntu .", "start.docker.ubuntu": "docker run -t setup-cpp:ubuntu .",
"test": "run-p --continue-on-error test.lint test.unit", "test": "run-p --continue-on-error test.lint test.unit",
"test.docker.arch": "docker build -f ./dev/docker/arch_node.dockerfile --target setup-cpp -t setup-cpp:arch-base . && container-structure-test test --image setup-cpp:arch-base --config ./dev/container-tests/arch.yml",
"test.docker.fedora": "docker build -f ./dev/docker/fedora_node.dockerfile --target setup-cpp -t setup-cpp:fedora-base . && container-structure-test test --image setup-cpp:fedora-base --config ./dev/container-tests/fedora.yml",
"test.docker.ubuntu": "docker build -f ./dev/docker/ubuntu_node.dockerfile --target setup-cpp -t setup-cpp:ubuntu-base . && container-structure-test test --image setup-cpp:ubuntu-base --config ./dev/container-tests/ubuntu.yml",
"test.lint": "run-p --aggregate-output --continue-on-error lint.cspell test.lint.eslint test.lint.prettier lint.tsc", "test.lint": "run-p --aggregate-output --continue-on-error lint.cspell test.lint.eslint test.lint.prettier lint.tsc",
"test.lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/", "test.lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
"test.lint.prettier": "prettier . --check", "test.lint.prettier": "prettier . --check",
"test.unit": "jest --runInBand" "test.unit": "jest --runInBand",
"build.docker_tests": "pnpm build && node ./dev/scripts/generate-docker-tests.mjs",
"build.docker.arch": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/arch.dockerfile -t setup-cpp:arch .",
"build.docker.fedora": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/fedora.dockerfile -t setup-cpp:fedora .",
"build.docker.ubuntu": "pnpm build.docker_tests && docker build -f ./dev/docker/__tests__/ubuntu.dockerfile -t setup-cpp:ubuntu .",
"test.docker.arch": "pnpm build.docker.arch && container-structure-test test --image setup-cpp:arch --config ./dev/docker/__tests__/arch.yml",
"test.docker.fedora": "pnpm build.docker.fedora && container-structure-test test --image setup-cpp:fedora --config ./dev/docker/__tests__/fedora.yml",
"test.docker.ubuntu": "pnpm build.docker.ubuntu && container-structure-test test --image setup-cpp:ubuntu --config ./dev/docker/__tests__/ubuntu.yml"
}, },
"prettier": "prettier-config-atomic", "prettier": "prettier-config-atomic",
"devDependencies": { "devDependencies": {