Merge pull request #181 from aminya/docker

This commit is contained in:
Amin Yahyaabadi 2023-07-15 19:22:05 -07:00 committed by GitHub
commit 1d68644b94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 291 additions and 143 deletions

View File

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

View File

@ -153,29 +153,49 @@ 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 setup-cpp-ubuntu
# install nodejs and setup-cpp
RUN apt-get update -qq && \
# install nodejs
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
# 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"]
#### Building (example)
FROM base as builder
FROM setup-cpp-ubuntu AS builder
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& 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 --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/
@ -189,7 +209,7 @@ If you want to build the ones included, then run:
```shell
git clone --recurse-submodules https://github.com/aminya/setup-cpp
cd ./setup-cpp
docker build -f ./dev/docker/ubuntu.dockerfile -t setup-cpp .
docker build -f ./dev/docker/setup-cpp-ubuntu.dockerfile -t setup-cpp .
```
Where you should use the path to the dockerfile after `-f`.

View File

@ -1,30 +1,47 @@
## 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 && \
pacman-db-upgrade && \
pacman -S --noconfirm --needed nodejs
# add setup-cpp.js (built outside of this dockerfile)
COPY "./dist/legacy" "/"
# 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
# install nodejs
pacman -S --noconfirm --needed nodejs npm && \
# install setup-cpp
npm install -g setup-cpp@v0.30.1 && \
# 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 && \
# arch cleanup
pacman -Scc --noconfirm && \
rm -rf /var/cache/pacman/pkg/* && \
rm -rf /tmp/*
ENTRYPOINT ["/bin/bash"]
#### Building (example)
FROM base AS example-builder
FROM setup-cpp-arch 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
# use a fresh image as the runner
FROM archlinux:base as runner
# 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/
ENTRYPOINT ["./my_exe"]

View File

@ -1,29 +1,44 @@
## 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/"
# install nodejs
RUN dnf -y install nodejs npm && \
npm install -g setup-cpp
# add setup-cpp.js (built outside of this dockerfile)
COPY "./dist/legacy" "/"
# 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
# install setup-cpp
npm install -g setup-cpp@v0.30.1 && \
# 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"]
#### Building (example)
FROM base AS example-builder
FROM setup-cpp-fedora 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
# use a fresh image as the runner
FROM fedora:38 as runner
# 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/
ENTRYPOINT ["./my_exe"]

View File

@ -1,29 +1,49 @@
#### 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 && \
apt-get install -y --no-install-recommends nodejs
# add setup-cpp.js (built outside of this dockerfile)
COPY "./dist/legacy" "/"
# install nodejs
apt-get install -y --no-install-recommends nodejs npm && \
# 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"]
#### Building
FROM base as builder
#### Building (example)
FROM setup-cpp-ubuntu AS builder
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& 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 --from=builder /home/app/build/my_exe/Release/ /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)
FROM base AS example-builder
FROM setup-cpp-arch 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
# use a fresh image as the runner
FROM archlinux:base as runner
# 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/
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)
FROM base AS example-builder
FROM setup-cpp-fedora 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
# use a fresh image as the runner
FROM fedora:38 as runner
# 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/
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 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 && \
# 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)
FROM base as builder
FROM setup-cpp-ubuntu AS builder
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& 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 --from=builder /home/app/build/my_exe/Release/ /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",
"packages",
"dev/docker",
"dev/container-tests",
"dev/docker/__tests__",
"README.md",
"LICENSE.txt",
"LICENSE.dependencies.txt",
@ -29,10 +29,6 @@
],
"scripts": {
"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",
"bump": "ncu -u -x numerous && pnpm update",
"clean": "shx rm -rf .parcel-cache dist exe",
@ -55,13 +51,17 @@
"start.docker.fedora": "docker run -t setup-cpp:fedora .",
"start.docker.ubuntu": "docker run -t setup-cpp:ubuntu .",
"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.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.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",
"devDependencies": {

View File

@ -157,8 +157,9 @@ export async function addAptKeyViaDownload(name: string, url: string) {
const fileName = `/etc/apt/trusted.gpg.d/${name}`
if (!(await pathExists(fileName))) {
initGpg()
await setupAptPack([{ name: "curl" }], undefined)
execRootSync("bash", ["-c", `curl -s ${url} | gpg --no-default-keyring --keyring gnupg-ring:${fileName} --import`])
await setupAptPack([{ name: "curl" }, { name: "ca-certificates" }], undefined)
await execa("curl", ["-s", url, "-o", `/tmp/${name}`])
execRootSync("gpg", ["--no-default-keyring", "--keyring", `gnupg-ring:${fileName}`, "--import", `/tmp/${name}`])
execRootSync("chmod", ["644", fileName])
}
return fileName