From 259ca27a4f77c19d4253283ebf1d8c3896c8b9e6 Mon Sep 17 00:00:00 2001 From: Sean Eagan Date: Wed, 30 Jan 2019 14:19:10 -0600 Subject: [PATCH] Switch to ubuntu base image Change to use ubuntu base image instead of python. Also refactor Dockerfile to remove unnecessary build dependencies to reduce size. BREAKING CHANGE: The `make images` PYTHON_BASE_IMAGE arg is now renamed to BASE_IMAGE. Change-Id: I63556290d8e007bfac4315529261d75e362806d6 --- Dockerfile | 76 ++++++++++++++++++++++++++++++++++++++++-------------- Makefile | 8 +++--- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index c23e2224..65846e38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG FROM=python:3.6 +ARG FROM=ubuntu:18.04 FROM ${FROM} LABEL org.opencontainers.image.authors='airship-discuss@lists.airshipit.org, irc://#airshipit@freenode' @@ -14,31 +14,67 @@ ENV LC_ALL=C.UTF-8 EXPOSE 8000 -ENTRYPOINT ["./entrypoint.sh"] -CMD ["server"] - -RUN mkdir -p /armada && \ - apt-get update && \ - apt-get install -y --no-install-recommends \ - netbase \ - curl \ - git && \ - useradd -u 1000 -g users -d /armada armada && \ - rm -rf \ - /root/.cache \ - /var/lib/apt/lists/* +RUN set -ex && \ + apt-get -qq update && \ + apt-get -y install \ + ca-certificates \ + curl \ + netbase \ + python3-dev \ + python3-setuptools \ + --no-install-recommends \ + && apt-get autoremove -yqq --purge \ + && apt-get clean \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* \ + /usr/share/man \ + /usr/share/doc \ + /usr/share/doc-base WORKDIR /armada -COPY requirements.txt /tmp/ -RUN pip3 install -r /tmp/requirements.txt +# Add armada user +RUN useradd -u 1000 -g users -d $(pwd) armada -COPY . /armada +ENTRYPOINT ["./entrypoint.sh"] +CMD ["server"] + +COPY requirements.txt ./ + +# Build +RUN set -ex \ + && buildDeps=' \ + gcc \ + libssl-dev \ + make \ + python3-pip \ + ' \ + && apt-get -qq update \ + # Keep git separate so it's not removed below + && apt-get install -y $buildDeps git --no-install-recommends \ + && python3 -m pip install -U pip \ + && pip3 install -r requirements.txt --no-cache-dir \ + && apt-get purge -y --auto-remove $buildDeps \ + && apt-get autoremove -yqq --purge \ + && apt-get clean \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* \ + /usr/share/man \ + /usr/share/doc \ + /usr/share/doc-base + +COPY . ./ + +# Setting the version explicitly for PBR +ENV PBR_VERSION 0.8.0 RUN \ - mv /armada/etc/armada /etc/ && \ - cd /armada && \ - chown -R armada:users /armada && \ + mv etc/armada /etc/ && \ + chown -R armada:users . && \ python3 setup.py install USER armada diff --git a/Makefile b/Makefile index 929bde53..1ff8238c 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ COMMIT ?= $(shell git rev-parse HEAD) PYTHON = python3 CHARTS := $(patsubst charts/%/.,%,$(wildcard charts/*/.)) IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG} -PYTHON_BASE_IMAGE ?= python:3.6 +BASE_IMAGE ?= # VERSION INFO GIT_COMMIT = $(shell git rev-parse HEAD) @@ -99,6 +99,8 @@ run_images: run_armada run_armada: build_armada ./tools/armada_image_run.sh $(IMAGE) +_BASE_IMAGE_ARG := $(if $(BASE_IMAGE),--build-arg FROM="${BASE_IMAGE}" ,) + .PHONY: build_armada build_armada: ifeq ($(USE_PROXY), true) @@ -107,7 +109,7 @@ ifeq ($(USE_PROXY), true) --label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \ --label "org.opencontainers.image.title=$(IMAGE_NAME)" \ -f ./Dockerfile \ - --build-arg FROM=$(PYTHON_BASE_IMAGE) \ + $(_BASE_IMAGE_ARG) \ --build-arg http_proxy=$(PROXY) \ --build-arg https_proxy=$(PROXY) \ --build-arg HTTP_PROXY=$(PROXY) \ @@ -120,7 +122,7 @@ else --label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \ --label "org.opencontainers.image.title=$(IMAGE_NAME)" \ -f ./Dockerfile \ - --build-arg FROM=$(PYTHON_BASE_IMAGE) . + $(_BASE_IMAGE_ARG) . endif ifeq ($(PUSH_IMAGE), true) docker push $(IMAGE)