github.com/vincentwoo/docker@v0.7.3-0.20160116130405-82401a4b13c0/contrib/builder/rpm/generate.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  # usage: ./generate.sh [versions]
     5  #    ie: ./generate.sh
     6  #        to update all Dockerfiles in this directory
     7  #    or: ./generate.sh
     8  #        to only update fedora-23/Dockerfile
     9  #    or: ./generate.sh fedora-newversion
    10  #        to create a new folder and a Dockerfile within it
    11  
    12  cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
    13  
    14  versions=( "$@" )
    15  if [ ${#versions[@]} -eq 0 ]; then
    16  	versions=( */ )
    17  fi
    18  versions=( "${versions[@]%/}" )
    19  
    20  for version in "${versions[@]}"; do
    21  	distro="${version%-*}"
    22  	suite="${version##*-}"
    23  	from="${distro}:${suite}"
    24  	installer=yum
    25  	if [[ "$distro" == "fedora" ]]; then
    26  		installer=dnf
    27  	fi
    28  
    29  	mkdir -p "$version"
    30  	echo "$version -> FROM $from"
    31  	cat > "$version/Dockerfile" <<-EOF
    32  		#
    33  		# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/generate.sh"!
    34  		#
    35  
    36  		FROM $from
    37  	EOF
    38  
    39  	echo >> "$version/Dockerfile"
    40  
    41  	extraBuildTags=
    42  
    43  	case "$from" in
    44  		centos:*)
    45  			# get "Development Tools" packages dependencies
    46  			echo 'RUN yum groupinstall -y "Development Tools"' >> "$version/Dockerfile"
    47  
    48  			if [[ "$version" == "centos-7" ]]; then
    49  				echo 'RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs' >> "$version/Dockerfile"
    50  			fi
    51  			;;
    52  		oraclelinux:*)
    53  			# get "Development Tools" packages and dependencies
    54  			# we also need yum-utils for yum-config-manager to pull the latest repo file
    55  			echo 'RUN yum groupinstall -y "Development Tools"' >> "$version/Dockerfile"
    56  			;;
    57  		opensuse:*)
    58  			# get rpm-build and curl packages and dependencies
    59  			echo 'RUN zypper --non-interactive install ca-certificates* curl gzip rpm-build' >> "$version/Dockerfile"
    60  			;;
    61  		*)
    62  			echo "RUN ${installer} install -y @development-tools fedora-packager" >> "$version/Dockerfile"
    63  			;;
    64  	esac
    65  
    66  	# this list is sorted alphabetically; please keep it that way
    67  	packages=(
    68  		btrfs-progs-devel # for "btrfs/ioctl.h" (and "version.h" if possible)
    69  		device-mapper-devel # for "libdevmapper.h"
    70  		glibc-static
    71  		libseccomp-devel # for "seccomp.h" & "libseccomp.so"
    72  		libselinux-devel # for "libselinux.so"
    73  		libtool-ltdl-devel # for pkcs11 "ltdl.h"
    74  		selinux-policy
    75  		selinux-policy-devel
    76  		sqlite-devel # for "sqlite3.h"
    77  		tar # older versions of dev-tools do not have tar
    78  	)
    79  
    80  	case "$from" in
    81  		oraclelinux:7)
    82  			# Enable the optional repository
    83  			packages=( --enablerepo=ol7_optional_latest "${packages[*]}" )
    84  			;;
    85  	esac
    86  
    87  	# opensuse & oraclelinx:6 do not have the right libseccomp libs
    88  	# centos:7 and oraclelinux:7 have a libseccomp < 2.2.1 :(
    89  	case "$from" in
    90  		opensuse:*|oraclelinux:*|centos:7)
    91  			packages=( "${packages[@]/libseccomp-devel}" )
    92  			;;
    93  		*)
    94  			extraBuildTags+=' seccomp'
    95  			;;
    96  	esac
    97  
    98  	case "$from" in
    99  		opensuse:*)
   100  			packages=( "${packages[@]/btrfs-progs-devel/libbtrfs-devel}" )
   101  			# use zypper
   102  			echo "RUN zypper --non-interactive install ${packages[*]}" >> "$version/Dockerfile"
   103  			;;
   104  		*)
   105  			echo "RUN ${installer} install -y ${packages[*]}" >> "$version/Dockerfile"
   106  			;;
   107  	esac
   108  
   109  	echo >> "$version/Dockerfile"
   110  
   111  	# fedora does not have a libseccomp.a for compiling static dockerinit
   112  	# ONLY install libseccomp.a from source, this can be removed once dockerinit is removed
   113  	# TODO remove this manual seccomp compilation once dockerinit is gone or no longer needs to be statically compiled
   114  	case "$from" in
   115  		fedora:*)
   116  			awk '$1 == "ENV" && $2 == "SECCOMP_VERSION" { print; exit }' ../../../Dockerfile >> "$version/Dockerfile"
   117  			cat <<-'EOF' >> "$version/Dockerfile"
   118  			RUN buildDeps=' \
   119  				automake \
   120  				libtool \
   121  			' \
   122  			&& set -x \
   123  			&& yum install -y $buildDeps \
   124  			&& export SECCOMP_PATH=$(mktemp -d) \
   125  			&& git clone -b "$SECCOMP_VERSION" --depth 1 https://github.com/seccomp/libseccomp.git "$SECCOMP_PATH" \
   126  			&& ( \
   127  				cd "$SECCOMP_PATH" \
   128  				&& ./autogen.sh \
   129  				&& ./configure --prefix=/usr \
   130  				&& make \
   131  				&& install -c src/.libs/libseccomp.a /usr/lib/libseccomp.a \
   132  				&& chmod 644 /usr/lib/libseccomp.a \
   133  				&& ranlib /usr/lib/libseccomp.a \
   134  				&& ldconfig -n /usr/lib \
   135  			) \
   136  			&& rm -rf "$SECCOMP_PATH"
   137  			EOF
   138  
   139  			echo >> "$version/Dockerfile"
   140  			;;
   141  		*) ;;
   142  	esac
   143  
   144  	case "$from" in
   145  		oraclelinux:6)
   146  			# We need a known version of the kernel-uek-devel headers to set CGO_CPPFLAGS, so grab the UEKR4 GA version
   147  			# This requires using yum-config-manager from yum-utils to enable the UEKR4 yum repo
   148  			echo "RUN yum install -y yum-utils && curl -o /etc/yum.repos.d/public-yum-ol6.repo http://yum.oracle.com/public-yum-ol6.repo && yum-config-manager -q --enable ol6_UEKR4"  >> "$version/Dockerfile"
   149  			echo "RUN yum install -y kernel-uek-devel-4.1.12-32.el6uek"  >> "$version/Dockerfile"
   150  			echo >> "$version/Dockerfile"
   151  			;;
   152  		*) ;;
   153  	esac
   154  
   155  
   156  	awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../Dockerfile >> "$version/Dockerfile"
   157  	echo 'RUN curl -fSL "https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile"
   158  	echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile"
   159  
   160  	echo >> "$version/Dockerfile"
   161  
   162  	echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile"
   163  
   164  	echo >> "$version/Dockerfile"
   165  
   166  	# print build tags in alphabetical order
   167  	buildTags=$( echo "selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' )
   168  
   169  	echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile"
   170  	echo >> "$version/Dockerfile"
   171  
   172  	case "$from" in
   173                  oraclelinux:6)
   174                          # We need to set the CGO_CPPFLAGS environment to use the updated UEKR4 headers with all the userns stuff.
   175                          # The ordering is very important and should not be changed.
   176                          echo 'ENV CGO_CPPFLAGS -D__EXPORTED_HEADERS__ \'  >> "$version/Dockerfile"
   177                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/generated/uapi \'  >> "$version/Dockerfile"
   178                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/uapi \'  >> "$version/Dockerfile"
   179                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/generated/uapi \'  >> "$version/Dockerfile"
   180                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/uapi \'  >> "$version/Dockerfile"
   181                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include'  >> "$version/Dockerfile"
   182                          echo >> "$version/Dockerfile"
   183                          ;;
   184                  *) ;;
   185          esac
   186  
   187  
   188  done