github.com/endocode/docker@v1.4.2-0.20160113120958-46eb4700391e/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  			echo 'RUN yum groupinstall -y "Development Tools"' >> "$version/Dockerfile"
    55  			;;
    56  		opensuse:*)
    57  			# get rpm-build and curl packages and dependencies
    58  			echo 'RUN zypper --non-interactive install ca-certificates* curl gzip rpm-build' >> "$version/Dockerfile"
    59  			;;
    60  		*)
    61  			echo "RUN ${installer} install -y @development-tools fedora-packager" >> "$version/Dockerfile"
    62  			;;
    63  	esac
    64  
    65  	# this list is sorted alphabetically; please keep it that way
    66  	packages=(
    67  		btrfs-progs-devel # for "btrfs/ioctl.h" (and "version.h" if possible)
    68  		device-mapper-devel # for "libdevmapper.h"
    69  		glibc-static
    70  		libseccomp-devel # for "seccomp.h" & "libseccomp.so"
    71  		libselinux-devel # for "libselinux.so"
    72  		libtool-ltdl-devel # for pkcs11 "ltdl.h"
    73  		selinux-policy
    74  		selinux-policy-devel
    75  		sqlite-devel # for "sqlite3.h"
    76  		tar # older versions of dev-tools do not have tar
    77  	)
    78  
    79  	case "$from" in
    80  		oraclelinux:7)
    81  			# Enable the optional repository
    82  			packages=( --enablerepo=ol7_optional_latest "${packages[*]}" )
    83  			;;
    84  	esac
    85  
    86  	# opensuse & oraclelinx:6 do not have the right libseccomp libs
    87  	# centos:7 and oraclelinux:7 have a libseccomp < 2.2.1 :(
    88  	case "$from" in
    89  		opensuse:*|oraclelinux:*|centos:7)
    90  			packages=( "${packages[@]/libseccomp-devel}" )
    91  			;;
    92  		*)
    93  			extraBuildTags+=' seccomp'
    94  			;;
    95  	esac
    96  
    97  	case "$from" in
    98  		opensuse:*)
    99  			packages=( "${packages[@]/btrfs-progs-devel/libbtrfs-devel}" )
   100  			# use zypper
   101  			echo "RUN zypper --non-interactive install ${packages[*]}" >> "$version/Dockerfile"
   102  			;;
   103  		*)
   104  			echo "RUN ${installer} install -y ${packages[*]}" >> "$version/Dockerfile"
   105  			;;
   106  	esac
   107  
   108  	echo >> "$version/Dockerfile"
   109  
   110  	# fedora does not have a libseccomp.a for compiling static dockerinit
   111  	# ONLY install libseccomp.a from source, this can be removed once dockerinit is removed
   112  	# TODO remove this manual seccomp compilation once dockerinit is gone or no longer needs to be statically compiled
   113  	case "$from" in
   114  		fedora:*)
   115  			awk '$1 == "ENV" && $2 == "SECCOMP_VERSION" { print; exit }' ../../../Dockerfile >> "$version/Dockerfile"
   116  			cat <<-'EOF' >> "$version/Dockerfile"
   117  			RUN buildDeps=' \
   118  				automake \
   119  				libtool \
   120  			' \
   121  			&& set -x \
   122  			&& yum install -y $buildDeps \
   123  			&& export SECCOMP_PATH=$(mktemp -d) \
   124  			&& git clone -b "$SECCOMP_VERSION" --depth 1 https://github.com/seccomp/libseccomp.git "$SECCOMP_PATH" \
   125  			&& ( \
   126  				cd "$SECCOMP_PATH" \
   127  				&& ./autogen.sh \
   128  				&& ./configure --prefix=/usr \
   129  				&& make \
   130  				&& install -c src/.libs/libseccomp.a /usr/lib/libseccomp.a \
   131  				&& chmod 644 /usr/lib/libseccomp.a \
   132  				&& ranlib /usr/lib/libseccomp.a \
   133  				&& ldconfig -n /usr/lib \
   134  			) \
   135  			&& rm -rf "$SECCOMP_PATH"
   136  			EOF
   137  
   138  			echo >> "$version/Dockerfile"
   139  			;;
   140  		*) ;;
   141  	esac
   142  
   143  	awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../Dockerfile >> "$version/Dockerfile"
   144  	echo 'RUN curl -fSL "https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile"
   145  	echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile"
   146  
   147  	echo >> "$version/Dockerfile"
   148  
   149  	echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile"
   150  
   151  	echo >> "$version/Dockerfile"
   152  
   153  	# print build tags in alphabetical order
   154  	buildTags=$( echo "selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' )
   155  
   156  	echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile"
   157  done