bumpver/docker_base.Dockerfile
2020-08-26 21:49:01 +00:00

75 lines
2.6 KiB
Docker

# Stages:
# root : Common image, both for the builder and for the final image.
# This contains only minimal dependencies required in both cases
# for miniconda and the makefile.
# env_builder: stage in which the conda envrionment is created
# and dependencies are installed
# base : the final image containing only the required environment files,
# and none of the infrastructure required to generate them.
FROM registry.gitlab.com/mbarkhau/bootstrapit/env_builder AS builder
# gcc required for cmarkgfm on python3.8
# https://github.com/theacodes/cmarkgfm/issues/22
RUN apt-get update
RUN apt-get install -y gcc
RUN mkdir /root/.ssh/ && \
ssh-keyscan gitlab.com >> /root/.ssh/known_hosts && \
ssh-keyscan registry.gitlab.com >> /root/.ssh/known_hosts
ARG SSH_PRIVATE_RSA_KEY
ENV ENV_SSH_PRIVATE_RSA_KEY=${SSH_PRIVATE_RSA_KEY}
# Write private key and generate public key
RUN if ! test -z "${ENV_SSH_PRIVATE_RSA_KEY}"; then \
echo -n "-----BEGIN RSA PRIVATE KEY-----" >> /root/.ssh/id_rsa && \
echo -n ${ENV_SSH_PRIVATE_RSA_KEY} \
| sed 's/-----BEGIN RSA PRIVATE KEY-----//' \
| sed 's/-----END RSA PRIVATE KEY-----//' \
| sed 's/ /\n/g' \
>> /root/.ssh/id_rsa && \
echo -n "-----END RSA PRIVATE KEY-----" >> /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/* && \
ssh-keygen -y -f /root/.ssh/id_rsa > /root/.ssh/id_rsa.pub; \
fi
ADD requirements/ requirements/
ADD scripts/ scripts/
ADD makefile.bootstrapit.make makefile.bootstrapit.make
ADD makefile makefile
# install envs (relatively stable)
ADD requirements/conda.txt requirements/conda.txt
RUN make build/envs.txt
# install python package dependencies (change more often)
ADD requirements/ requirements/
RUN make conda
RUN rm -f /root/.ssh/id_rsa
# Deleting pkgs implies that `conda install`
# will have to pull all packages again.
RUN conda clean --all --yes
# Conda docs say that it is not safe to delete pkgs
# because there may be symbolic links, so we verify
# first that there are no such links.
RUN find -L /opt/conda/envs/ -type l | grep "/opt/conda/pkgs" || exit 0
# The conda install is not usable after this RUN command. Since
# we only need /opt/conda/envs/ anyway, this shouldn't be an issue.
RUN conda clean --all --yes && \
ls -d /opt/conda/* | grep -v envs | xargs rm -rf && \
find /opt/conda/ -name "*.exe" | xargs rm -rf && \
find /opt/conda/ -name "__pycache__" | xargs rm -rf && \
rm -rf /opt/conda/pkgs/
FROM registry.gitlab.com/mbarkhau/bootstrapit/root
RUN apt-get install --yes mercurial;
COPY --from=builder /opt/conda/ /opt/conda/
COPY --from=builder /vendor/ /vendor