From 8550346b78778a67d960f9dfe4cc009a748f7710 Mon Sep 17 00:00:00 2001 From: Bryan Strassner Date: Fri, 25 Jan 2019 18:11:04 -0600 Subject: [PATCH] Switch to ubuntu base image Change to use ubuntu base image instead of python Refactor Shipyard Dockerfile to reduce image size significantly BREAKING CHANGE: The `make images` PYTHON_BASE_IMAGE arg is now renamed to BASE_IMAGE. Change-Id: I3338dfbbb91b5514fa4fd205bdfc4136d0abc2e5 --- Makefile | 13 +++---- images/airflow/Dockerfile | 5 ++- images/shipyard/Dockerfile | 72 ++++++++++++++++++++++++++++---------- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 098c9bd2..3faa37c6 100644 --- a/Makefile +++ b/Makefile @@ -31,8 +31,7 @@ PROXY ?= http://proxy.foo.com:8000 NO_PROXY ?= localhost,127.0.0.1,.svc.cluster.local USE_PROXY ?= false -PYTHON_BASE_IMAGE ?= python:3.6 -UBUNTU_BASE_IMAGE ?= ubuntu:16.04 +BASE_IMAGE ?= IMAGE:=${DOCKER_REGISTRY}/${IMAGE_PREFIX}/$(IMAGE_NAME):${IMAGE_TAG} IMAGE_DIR:=images/$(IMAGE_NAME) @@ -82,6 +81,8 @@ tests: run: USE_PROXY=$(USE_PROXY) PROXY=$(PROXY) $(SCRIPT) $(IMAGE) +_BASE_IMAGE_ARG := $(if $(BASE_IMAGE),--build-arg FROM="${BASE_IMAGE}" ,) + .PHONY: build_airflow build_airflow: ifeq ($(USE_PROXY), true) @@ -90,7 +91,7 @@ ifeq ($(USE_PROXY), true) --label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \ --label "org.opencontainers.image.title=$(IMAGE_NAME)" \ -f $(IMAGE_DIR)/Dockerfile \ - --build-arg FROM=$(UBUNTU_BASE_IMAGE) \ + $(_BASE_IMAGE_ARG) \ --build-arg http_proxy=$(PROXY) \ --build-arg https_proxy=$(PROXY) \ --build-arg HTTP_PROXY=$(PROXY) \ @@ -104,7 +105,7 @@ else --label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \ --label "org.opencontainers.image.title=$(IMAGE_NAME)" \ -f $(IMAGE_DIR)/Dockerfile \ - --build-arg FROM=$(UBUNTU_BASE_IMAGE) \ + $(_BASE_IMAGE_ARG) \ --build-arg ctx_base=$(BUILD_CTX) . endif ifeq ($(PUSH_IMAGE), true) @@ -119,7 +120,7 @@ ifeq ($(USE_PROXY), true) --label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \ --label "org.opencontainers.image.title=$(IMAGE_NAME)" \ -f $(IMAGE_DIR)/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) \ @@ -133,7 +134,7 @@ else --label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \ --label "org.opencontainers.image.title=$(IMAGE_NAME)" \ -f $(IMAGE_DIR)/Dockerfile \ - --build-arg FROM=$(PYTHON_BASE_IMAGE) \ + $(_BASE_IMAGE_ARG) \ --build-arg ctx_base=$(BUILD_CTX) . endif ifeq ($(PUSH_IMAGE), true) diff --git a/images/airflow/Dockerfile b/images/airflow/Dockerfile index 8652f158..45821d7e 100644 --- a/images/airflow/Dockerfile +++ b/images/airflow/Dockerfile @@ -51,7 +51,6 @@ RUN set -ex && \ apt-get -y install \ ca-certificates \ curl \ - gcc \ git \ g++ \ libffi-dev \ @@ -87,7 +86,7 @@ RUN useradd -ms /bin/bash -d ${AIRFLOW_HOME} airflow \ # Note - removing snakebite (python 2 vs. 3). See: # https://github.com/puckel/docker-airflow/issues/77 COPY images/airflow/requirements.txt /tmp/ -RUN pip3 install -r /tmp/requirements.txt \ +RUN pip3 install -r /tmp/requirements.txt --no-cache-dir \ && pip3 uninstall -y snakebite || true # Copy scripts used in the container: @@ -109,7 +108,7 @@ ENV PBR_VERSION 0.1a1 # stale or out-of-date code between these parts. # Shipyard requirements, source and installation COPY ${ctx_base}/shipyard_airflow/requirements.txt /tmp/api_requirements.txt -RUN pip3 install -r /tmp/api_requirements.txt +RUN pip3 install -r /tmp/api_requirements.txt --no-cache-dir COPY ${ctx_base}/shipyard_airflow /tmp/shipyard/ RUN cd /tmp/shipyard \ diff --git a/images/shipyard/Dockerfile b/images/shipyard/Dockerfile index e3bc3370..6c0ec774 100644 --- a/images/shipyard/Dockerfile +++ b/images/shipyard/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARG FROM=python:3.6 +ARG FROM=ubuntu:16.04 FROM ${FROM} LABEL org.opencontainers.image.authors='airship-discuss@lists.airshipit.org, irc://#airshipit@freenode' @@ -26,6 +26,8 @@ ENV container docker ENV PORT 9000 ENV LC_ALL C.UTF-8 ENV LANG C.UTF-8 +# Setting the version explicitly for PBR +ENV PBR_VERSION 0.1a1 ARG DEBIAN_FRONTEND=noninteractive ARG ctx_base=src/bin @@ -33,9 +35,24 @@ ARG ctx_base=src/bin # Expose port 9000 for application EXPOSE $PORT -# Execute entrypoint -ENTRYPOINT ["/home/shipyard/entrypoint.sh"] -CMD ["server"] +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 # Create shipyard user RUN useradd -ms /bin/bash shipyard \ @@ -48,24 +65,43 @@ COPY ${ctx_base}/shipyard_airflow/entrypoint.sh /home/shipyard/entrypoint.sh RUN chown -R shipyard: /home/shipyard \ && chmod +x /home/shipyard/entrypoint.sh -# Requirements +# Requirements and Shipyard source COPY ${ctx_base}/shipyard_airflow/requirements.txt /home/shipyard/api_requirements.txt -RUN pip3 install -r /home/shipyard/api_requirements.txt - COPY ${ctx_base}/shipyard_client/requirements.txt /home/shipyard/client_requirements.txt -RUN pip3 install -r /home/shipyard/client_requirements.txt - -# Setting the version explicitly for PBR -ENV PBR_VERSION 0.1a1 - -# Shipyard source and installation COPY ${ctx_base}/shipyard_client /home/shipyard/shipyard_client/ -RUN cd /home/shipyard/shipyard_client \ - && python3 setup.py install - COPY ${ctx_base}/shipyard_airflow /home/shipyard/shipyard/ -RUN cd /home/shipyard/shipyard \ - && python3 setup.py install +# Build + RUN set -ex \ + && buildDeps=' \ + gcc \ + git \ + libssl-dev \ + make \ + python3-pip \ + ' \ + && apt-get -qq update \ + && apt-get -y install -y $buildDeps --no-install-recommends \ + && python3 -m pip install -U pip \ + && pip3 install -r /home/shipyard/client_requirements.txt --no-cache-dir \ + && cd /home/shipyard/shipyard_client \ + && python3 setup.py install \ + && pip3 install -r /home/shipyard/api_requirements.txt --no-cache-dir \ + && cd /home/shipyard/shipyard \ + && python3 setup.py install \ + && 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 + +# Entrypoint +ENTRYPOINT ["/home/shipyard/entrypoint.sh"] +CMD ["server"] # Set user to shipyard USER shipyard