update docker image gen

This commit is contained in:
Manuel Barkhau 2018-12-06 14:21:21 +01:00
parent 7835c8b337
commit acfc861e58
3 changed files with 13 additions and 54 deletions

View file

@ -5,7 +5,7 @@ stages:
unit:
stage: test
image: registry.gitlab.com/mbarkhau/pycalver/base:latest
image: registry.gitlab.com/mbarkhau/pycalver/base
script:
- make lint
- make mypy

View file

@ -1,59 +1,13 @@
# Stages:
# base_image : Common base image, both for the builder and for the final image.
# 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.
# builder : stage in which the conda envrionment is created
# env_builder: stage in which the conda envrionment is created
# and dependencies are installed
# final : the final image containing only the required environment files,
# base : the final image containing only the required environment files,
# and none of the infrastructure required to generate them.
FROM debian:stable-slim AS base_image
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV CONDA_DIR /opt/conda
ENV PATH $CONDA_DIR/bin:$PATH
ENV SHELL /bin/bash
RUN if [ $(which apk) ]; then \
apk add --no-cache bash make sed grep gawk curl git bzip2 unzip; \
elif [ $(which apt-get) ]; then \
apt-get update && apt-get install --yes bash make sed grep gawk curl git bzip2 unzip; \
else \
echo "Invalid Distro: $(uname -a)"; \
exit 1; \
fi
CMD [ "/bin/bash" ]
FROM base_image AS builder
RUN if [ $(which apk) ]; then \
apk add --no-cache ca-certificates openssh-client openssh-keygen; \
elif [ $(which apt-get) ]; then \
apt-get --yes install ca-certificates openssh-client; \
else \
echo "Invalid Distro: $(uname -a)"; \
exit 1; \
fi
ENV MINICONDA_VER latest
ENV MINICONDA Miniconda3-$MINICONDA_VER-Linux-x86_64.sh
ENV MINICONDA_URL https://repo.continuum.io/miniconda/$MINICONDA
RUN curl -L "$MINICONDA_URL" --silent -o miniconda3.sh && \
/bin/bash miniconda3.sh -f -b -p $CONDA_DIR && \
rm miniconda3.sh && \
/opt/conda/bin/conda clean -tipsy && \
ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
echo "conda activate base" >> ~/.bashrc && \
conda update --all --yes && \
conda config --set auto_update_conda False
# Project specific files only from here on forward
FROM registry.gitlab.com/mbarkhau/bootstrapit/env_builder AS builder
RUN mkdir /root/.ssh/ && \
ssh-keyscan gitlab.com >> /root/.ssh/known_hosts && \
@ -103,7 +57,7 @@ RUN conda clean --all --yes && \
rm -rf /opt/conda/pkgs/
FROM base_image
FROM registry.gitlab.com/mbarkhau/bootstrapit/root
COPY --from=builder /opt/conda/ /opt/conda/
COPY --from=builder /vendor/ /vendor

View file

@ -60,7 +60,10 @@ DEV_ENV_PY := $(DEV_ENV)/bin/python
RSA_KEY_PATH := ${HOME}/.ssh/${PKG_NAME}_gitlab_runner_id_rsa
DOCKER_BASE_IMAGE := registry.gitlab.com/mbarkhau/pycalver/base:latest
DOCKER_BASE_IMAGE := registry.gitlab.com/mbarkhau/pycalver/base
DOCKER_IMAGE_VERSION := $(shell date -u +'%Y%m%dt%H%M%S')_$(shell git rev-parse --short HEAD)
build/envs.txt: requirements/conda.txt
@mkdir -p build/;
@ -368,7 +371,7 @@ check: fmt lint mypy test
env_subshell:
@bash --init-file <(echo '\
source $$HOME/.bashrc; \
source $(CONDA_ROOT)/etc/profile.d/conda.sh; \
source $(CONDA_ROOT)/etc/profile.d/conda.sh \
export ENV=$${ENV-dev}; \
export PYTHONPATH="src/:vendor/:$$PYTHONPATH"; \
conda activate $(DEV_ENV_NAME) \
@ -510,11 +513,13 @@ build_docker:
docker build \
--build-arg SSH_PRIVATE_RSA_KEY="$$(cat '${RSA_KEY_PATH}')" \
--file docker_base.Dockerfile \
--tag $(DOCKER_BASE_IMAGE):$(DOCKER_IMAGE_VERSION) \
--tag $(DOCKER_BASE_IMAGE) \
.; \
else \
docker build \
--file docker_base.Dockerfile \
--tag $(DOCKER_BASE_IMAGE):$(DOCKER_IMAGE_VERSION) \
--tag $(DOCKER_BASE_IMAGE) \
.; \
fi