2023-04-06 20:29:38 +08:00
FROM ubuntu:20.04 as base
# set time-zone
ENV TZ=Canada/Pacific
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
2023-04-06 20:40:23 +08:00
# install node with nvm
RUN apt-get update -qq && apt-get install -y --no-install-recommends git curl wget ca-certificates
2023-04-06 20:29:38 +08:00
ARG nvm_version="0.39.3"
2023-04-06 20:40:23 +08:00
ARG node_version="12.22.12"
RUN mkdir /usr/local/nvm
ENV NVM_DIR /usr/local/nvm
ADD https://raw.githubusercontent.com/nvm-sh/nvm/v${nvm_version}/install.sh /nvm_install.sh
RUN chmod +x /nvm_install.sh && /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
2023-04-06 20:29:38 +08:00
2023-04-17 17:14:02 +08:00
# install pnpm
2023-04-18 19:37:21 +08:00
ENV PNPM_VERSION "6.35.1"
ADD https://get.pnpm.io/install.sh /tmp/pnpm_install.sh
RUN chmod +x /tmp/pnpm_install.sh && bash /tmp/pnpm_install.sh
ENV PNPM_HOME "/root/.local/share/pnpm"
ENV PATH "${PATH}:${PNPM_HOME}"
2023-04-06 20:29:38 +08:00
2023-04-17 17:14:02 +08:00
#### Building
FROM base AS builder
## https://github.com/ever0de/pnpm-docker-root-bug#how-to-fix
WORKDIR /workspace
COPY . .
2023-04-18 19:37:21 +08:00
## WARN "prepare" script of "setup-cpp" inside "/workspace" is skipped as the working directory seems suspicious. To run this lifecycle script anyway, use "--unsafe-perm".
RUN pnpm install --unsafe-perm
2023-04-17 17:14:02 +08:00
#### setup-cpp
FROM base AS setup-cpp
# add setup-cpp.js
COPY --from=builder /workspace/dist/node12 /
# 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
2023-04-06 20:29:38 +08:00
CMD ["source", "~/.cpprc"]
ENTRYPOINT ["/bin/bash"]
2023-04-17 17:14:02 +08:00
#### Building (example)
FROM setup-cpp AS example-builder
2023-04-06 20:29:38 +08:00
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& task build'
2023-04-17 17:14:02 +08:00
#### Running environment
# use a distroless image or ubuntu:22.04 if you wish
2023-04-06 20:29:38 +08:00
FROM gcr.io/distroless/cc as runner
# copy the built binaries and their runtime dependencies
2023-04-17 17:14:02 +08:00
COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/
2023-04-06 20:29:38 +08:00
WORKDIR /home/app/
ENTRYPOINT ["./my_exe"]