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
This commit is contained in:
Bryan Strassner 2019-01-25 18:11:04 -06:00
parent 6bd02eea84
commit 8550346b78
3 changed files with 63 additions and 27 deletions

View File

@ -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)

View File

@ -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 \

View File

@ -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