From acfc861e58cd4dcd2e3f9165664dbcf4ccc67526 Mon Sep 17 00:00:00 2001 From: Manuel Barkhau Date: Thu, 6 Dec 2018 14:21:21 +0100 Subject: [PATCH] update docker image gen --- .gitlab-ci.yml | 2 +- docker_base.Dockerfile | 56 ++++-------------------------------------- makefile | 9 +++++-- 3 files changed, 13 insertions(+), 54 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 368402a..3b411f5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/docker_base.Dockerfile b/docker_base.Dockerfile index 47c588d..8587294 100644 --- a/docker_base.Dockerfile +++ b/docker_base.Dockerfile @@ -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 diff --git a/makefile b/makefile index feb8484..bdd1798 100644 --- a/makefile +++ b/makefile @@ -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