github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/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  		pkgconfig # for the pkg-config command
    75  		selinux-policy
    76  		selinux-policy-devel
    77  		sqlite-devel # for "sqlite3.h"
    78  		systemd-devel # for "sd-journal.h" and libraries
    79  		tar # older versions of dev-tools do not have tar
    80  	)
    81  
    82  	case "$from" in
    83  		oraclelinux:7)
    84  			# Enable the optional repository
    85  			packages=( --enablerepo=ol7_optional_latest "${packages[*]}" )
    86  			;;
    87  	esac
    88  
    89  	case "$from" in
    90  		oraclelinux:6)
    91  			# doesn't use systemd, doesn't have a devel package for it
    92  			packages=( "${packages[@]/systemd-devel}" )
    93  			;;
    94  	esac
    95  
    96  	# opensuse & oraclelinx:6 do not have the right libseccomp libs
    97  	# centos:7 and oraclelinux:7 have a libseccomp < 2.2.1 :(
    98  	case "$from" in
    99  		opensuse:*|oraclelinux:*|centos:7)
   100  			packages=( "${packages[@]/libseccomp-devel}" )
   101  			;;
   102  		*)
   103  			extraBuildTags+=' seccomp'
   104  			;;
   105  	esac
   106  
   107  	case "$from" in
   108  		opensuse:*)
   109  			packages=( "${packages[@]/btrfs-progs-devel/libbtrfs-devel}" )
   110  			packages=( "${packages[@]/pkgconfig/pkg-config}" )
   111  			# use zypper
   112  			echo "RUN zypper --non-interactive install ${packages[*]}" >> "$version/Dockerfile"
   113  			;;
   114  		*)
   115  			echo "RUN ${installer} install -y ${packages[*]}" >> "$version/Dockerfile"
   116  			;;
   117  	esac
   118  
   119  	echo >> "$version/Dockerfile"
   120  
   121  	# TODO remove this since dockerinit is finally gone
   122  	case "$from" in
   123  		fedora:*)
   124  			awk '$1 == "ENV" && $2 == "SECCOMP_VERSION" { print; exit }' ../../../Dockerfile >> "$version/Dockerfile"
   125  			cat <<-'EOF' >> "$version/Dockerfile"
   126  			RUN buildDeps=' \
   127  				automake \
   128  				libtool \
   129  			' \
   130  			&& set -x \
   131  			&& yum install -y $buildDeps \
   132  			&& export SECCOMP_PATH=$(mktemp -d) \
   133  			&& curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_VERSION}/libseccomp-${SECCOMP_VERSION}.tar.gz" \
   134  			| tar -xzC "$SECCOMP_PATH" --strip-components=1 \
   135  			&& ( \
   136  				cd "$SECCOMP_PATH" \
   137  				&& ./configure --prefix=/usr \
   138  				&& make \
   139  				&& install -c src/.libs/libseccomp.a /usr/lib/libseccomp.a \
   140  				&& chmod 644 /usr/lib/libseccomp.a \
   141  				&& ranlib /usr/lib/libseccomp.a \
   142  				&& ldconfig -n /usr/lib \
   143  			) \
   144  			&& rm -rf "$SECCOMP_PATH"
   145  			EOF
   146  
   147  			echo >> "$version/Dockerfile"
   148  			;;
   149  		*) ;;
   150  	esac
   151  
   152  	case "$from" in
   153  		oraclelinux:6)
   154  			# We need a known version of the kernel-uek-devel headers to set CGO_CPPFLAGS, so grab the UEKR4 GA version
   155  			# This requires using yum-config-manager from yum-utils to enable the UEKR4 yum repo
   156  			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"
   157  			echo "RUN yum install -y kernel-uek-devel-4.1.12-32.el6uek"  >> "$version/Dockerfile"
   158  			echo >> "$version/Dockerfile"
   159  			;;
   160  		*) ;;
   161  	esac
   162  
   163  
   164  	awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../Dockerfile >> "$version/Dockerfile"
   165  	echo 'RUN curl -fSL "https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile"
   166  	echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile"
   167  
   168  	echo >> "$version/Dockerfile"
   169  
   170  	echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile"
   171  
   172  	echo >> "$version/Dockerfile"
   173  
   174  	# print build tags in alphabetical order
   175  	buildTags=$( echo "selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' )
   176  
   177  	echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile"
   178  	echo >> "$version/Dockerfile"
   179  
   180  	case "$from" in
   181                  oraclelinux:6)
   182                          # We need to set the CGO_CPPFLAGS environment to use the updated UEKR4 headers with all the userns stuff.
   183                          # The ordering is very important and should not be changed.
   184                          echo 'ENV CGO_CPPFLAGS -D__EXPORTED_HEADERS__ \'  >> "$version/Dockerfile"
   185                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/generated/uapi \'  >> "$version/Dockerfile"
   186                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/uapi \'  >> "$version/Dockerfile"
   187                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/generated/uapi \'  >> "$version/Dockerfile"
   188                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/uapi \'  >> "$version/Dockerfile"
   189                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include'  >> "$version/Dockerfile"
   190                          echo >> "$version/Dockerfile"
   191                          ;;
   192                  *) ;;
   193          esac
   194  
   195  
   196  done