feat: add separate production and testing docker files

This commit is contained in:
Amin Yahyaabadi 2023-07-15 15:05:41 -07:00
parent 78e0cf33cc
commit 73478bbe8c
13 changed files with 162 additions and 122 deletions

View File

@ -1,5 +1,20 @@
.parcel-cache/
node_modules/
dev/docker/
dev/container-tests/
dist/
.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/

View File

@ -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 .

View File

@ -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"]
#### 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

View File

@ -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

View File

@ -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

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

View File

@ -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

View File

@ -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"]