Browse Source

Add support for proxy servers during image build

When building the docker image, the 'apt-get' and 'pip install' that are
run inside the docker image will fail in a an environment that uses
proxy servers.

Support environments with proxy servers by dynamically propagating
'http_proxy', 'https_proxy', and 'no_proxy' into the docker environment
when running 'apt-get' and 'pip install'

This can not be done with either --env-file or --env as those are
arguments to 'docker run'. The command being run here is 'docker build'

Once Docker 1.9 is widely deployed, we should switch to using the 'ARG'
command which was added in Docker 1.9. Currently Ubuntu 14.04 uses
Docker 1.6.  Using the ARG command will be a much cleaner solution.

Change-Id: Idd994cd58b9fb75bae13a43fc8363c36f113527d
Closes-Bug: #1533796
tags/1.2.0
John L. Villalovos 4 years ago
parent
commit
1ffaaf6abf
4 changed files with 44 additions and 12 deletions
  1. +1
    -0
      .gitignore
  2. +20
    -12
      Dockerfile
  3. +17
    -0
      imagebuild/coreos/docker_build.bash
  4. +6
    -0
      proxy.sh

+ 1
- 0
.gitignore View File

@@ -20,6 +20,7 @@ imagebuild/coreos/UPLOAD
_build
doc/source/api/
doc/build
.proxy.sh.save

# release notes build
releasenotes/build

+ 20
- 12
Dockerfile View File

@@ -5,22 +5,30 @@ FROM debian:jessie
# different it will not cache this layer
ADD . /tmp/ironic-python-agent

# Copy the proxy.sh script which copies the proxy settings from the host
# environment (if they are set). This file will be dynamically created by
# imagebuild/coreos/docker_build.bash
# TODO(jlvilla): Once Docker 1.9 is widely deployed, switch to using the 'ARG'
# command which was added in Docker 1.9. Currently Ubuntu 14.04 uses Docker
# 1.6. Using the ARG command will be a much cleaner solution.
COPY proxy.sh /usr/bin/proxy.sh

# Add 'testing' for qemu-utils
RUN echo 'APT::Default-Release "jessie";' > /etc/apt/apt.conf.d/10default && \
sed -e 's/jessie/testing/g' /etc/apt/sources.list > /etc/apt/sources.list.d/testing.list

# Install requirements: Python for ironic-python-agent, others for putting an
# image on disk
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y --no-install-recommends gdisk python2.7 python2.7-dev \
RUN proxy.sh apt-get update && \
proxy.sh apt-get -y upgrade && \
proxy.sh apt-get install -y --no-install-recommends gdisk python2.7 python2.7-dev \
python-pip qemu-utils parted hdparm util-linux genisoimage git gcc \
bash coreutils tgt dmidecode ipmitool && \
apt-get --only-upgrade -t testing install -y qemu-utils
proxy.sh apt-get --only-upgrade -t testing install -y qemu-utils

# Some cleanup
RUN apt-get -y autoremove && \
apt-get clean
RUN proxy.sh apt-get -y autoremove && \
proxy.sh apt-get clean

# Before cleaning mark packages that are required so they are not removed
RUN apt-mark manual python-setuptools
@@ -28,18 +36,18 @@ RUN apt-mark manual python-minimal

# Install requirements separately, because pip understands a git+https url
# while setuptools doesn't
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r /tmp/ironic-python-agent/requirements.txt
RUN proxy.sh pip install --upgrade pip
RUN proxy.sh pip install --no-cache-dir -r /tmp/ironic-python-agent/requirements.txt

# This will succeed because all the dependencies were installed previously
RUN pip install --no-cache-dir /tmp/ironic-python-agent
RUN proxy.sh pip install --no-cache-dir /tmp/ironic-python-agent

# Remove no longer needed packages
# NOTE(jroll) leave git to avoid strange apt issues in downstream Dockerfiles
# that may inherit from this one.
RUN apt-get -y purge gcc-4.6 gcc python2.7-dev && \
apt-get -y autoremove && \
apt-get clean
RUN proxy.sh apt-get -y purge gcc-4.6 gcc python2.7-dev && \
proxy.sh apt-get -y autoremove && \
proxy.sh apt-get clean
RUN rm -rf /tmp/ironic-python-agent
RUN rm -rf /var/lib/apt/lists/*



+ 17
- 0
imagebuild/coreos/docker_build.bash View File

@@ -16,7 +16,24 @@ fi

# Build the docker image
cd ../../

# TODO(jlvilla): Once Docker 1.9 is widely deployed, switch to using the 'ARG'
# command which was added in Docker 1.9. Currently Ubuntu 14.04 uses Docker
# 1.6. Using the ARG command will be a much cleaner solution.
mv proxy.sh .proxy.sh.save || true
# Create a temporary proxy.sh script, that will be used by the Dockerfile.
# Since we are calling 'docker build' we can not use --env-file/--env as those
# are arguments to 'docker run'
echo '#!/bin/sh' > proxy.sh
echo 'echo Running: $*' >> proxy.sh
echo "http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} no_proxy=${no_proxy:-} "'$*' >> proxy.sh
chmod 0755 proxy.sh

docker build -t oemdocker .

# Restore saved copy
mv .proxy.sh.save proxy.sh || true

cd -

# Create a UUID to identify the build


+ 6
- 0
proxy.sh View File

@@ -0,0 +1,6 @@
#!/bin/sh

# Have things work for users who didn't run with the
# imagebuild/coreos/docker_build.bash script

$*

Loading…
Cancel
Save