github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/contrib/builder/rpm/amd64/generate.sh (about)

     1  #!/usr/bin/env 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 centos-7
     8  #        to only update centos-7/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  
    26  	if [[ "$distro" == "fedora" ]]; then
    27  		installer=dnf
    28  	fi
    29  	if [[ "$distro" == "photon" ]]; then
    30  		installer=tdnf
    31  	fi
    32  
    33  	mkdir -p "$version"
    34  	echo "$version -> FROM $from"
    35  	cat > "$version/Dockerfile" <<-EOF
    36  		#
    37  		# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"!
    38  		#
    39  
    40  		FROM $from
    41  	EOF
    42  
    43  	echo >> "$version/Dockerfile"
    44  
    45  	extraBuildTags=
    46  	runcBuildTags=
    47  
    48  	case "$from" in
    49  		oraclelinux:6)
    50  			# We need a known version of the kernel-uek-devel headers to set CGO_CPPFLAGS, so grab the UEKR4 GA version
    51  			# This requires using yum-config-manager from yum-utils to enable the UEKR4 yum repo
    52  			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"
    53  			echo "RUN yum install -y kernel-uek-devel-4.1.12-32.el6uek"  >> "$version/Dockerfile"
    54  			echo >> "$version/Dockerfile"
    55  			;;
    56  		fedora:*)
    57  			echo "RUN ${installer} -y upgrade" >> "$version/Dockerfile"
    58  			;;
    59  		*) ;;
    60  	esac
    61  
    62  	case "$from" in
    63  		centos:*|amazonlinux:latest)
    64  			# get "Development Tools" packages dependencies
    65  			echo 'RUN yum groupinstall -y "Development Tools"' >> "$version/Dockerfile"
    66  
    67  			if [[ "$version" == "centos-7" ]]; then
    68  				echo 'RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs' >> "$version/Dockerfile"
    69  			fi
    70  			;;
    71  		oraclelinux:*)
    72  			# get "Development Tools" packages and dependencies
    73  			# we also need yum-utils for yum-config-manager to pull the latest repo file
    74  			echo 'RUN yum groupinstall -y "Development Tools"' >> "$version/Dockerfile"
    75  			;;
    76  		opensuse:*)
    77  			# get rpm-build and curl packages and dependencies
    78  			echo 'RUN zypper --non-interactive install ca-certificates* curl gzip rpm-build' >> "$version/Dockerfile"
    79  			;;
    80  		photon:*)
    81  			echo "RUN ${installer} install -y wget curl ca-certificates gzip make rpm-build sed gcc linux-api-headers glibc-devel binutils libseccomp elfutils" >> "$version/Dockerfile"
    82  			;;
    83  		*)
    84  			echo "RUN ${installer} install -y @development-tools fedora-packager" >> "$version/Dockerfile"
    85  			;;
    86  	esac
    87  
    88  	packages=(
    89  		btrfs-progs-devel # for "btrfs/ioctl.h" (and "version.h" if possible)
    90  		device-mapper-devel # for "libdevmapper.h"
    91  		glibc-static
    92  		libseccomp-devel # for "seccomp.h" & "libseccomp.so"
    93  		libselinux-devel # for "libselinux.so"
    94  		pkgconfig # for the pkg-config command
    95  		selinux-policy
    96  		selinux-policy-devel
    97  		systemd-devel # for "sd-journal.h" and libraries
    98  		tar # older versions of dev-tools do not have tar
    99  		git # required for containerd and runc clone
   100  		cmake # tini build
   101  		vim-common # tini build
   102  	)
   103  
   104  	case "$from" in
   105  		oraclelinux:7)
   106  			# Enable the optional repository
   107  			packages=( --enablerepo=ol7_optional_latest "${packages[*]}" )
   108  			;;
   109  	esac
   110  
   111  	case "$from" in
   112  		oraclelinux:6|amazonlinux:latest)
   113  			# doesn't use systemd, doesn't have a devel package for it
   114  			packages=( "${packages[@]/systemd-devel}" )
   115  			;;
   116  	esac
   117  
   118  	# opensuse & oraclelinx:6 do not have the right libseccomp libs
   119  	case "$from" in
   120  		opensuse:*|oraclelinux:6)
   121  			packages=( "${packages[@]/libseccomp-devel}" )
   122  			runcBuildTags="selinux"
   123  			;;
   124  		*)
   125  			extraBuildTags+=' seccomp'
   126  			runcBuildTags="seccomp selinux"
   127  			;;
   128  	esac
   129  
   130  	case "$from" in
   131  		opensuse:*)
   132  			packages=( "${packages[@]/btrfs-progs-devel/libbtrfs-devel}" )
   133  			packages=( "${packages[@]/pkgconfig/pkg-config}" )
   134  			packages=( "${packages[@]/vim-common/vim}" )
   135  			if [[ "$from" == "opensuse:13."* ]]; then
   136  				packages+=( systemd-rpm-macros )
   137  			fi
   138  
   139  			# use zypper
   140  			echo "RUN zypper --non-interactive install ${packages[*]}" >> "$version/Dockerfile"
   141  			;;
   142  		photon:*)
   143  			packages=( "${packages[@]/pkgconfig/pkg-config}" )
   144  			echo "RUN ${installer} install -y ${packages[*]}" >> "$version/Dockerfile"
   145  			;;
   146  		*)
   147  			echo "RUN ${installer} install -y ${packages[*]}" >> "$version/Dockerfile"
   148  			;;
   149  	esac
   150  
   151  	echo >> "$version/Dockerfile"
   152  
   153  
   154  	awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../../Dockerfile >> "$version/Dockerfile"
   155  	echo 'RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile"
   156  	echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile"
   157  
   158  	echo >> "$version/Dockerfile"
   159  
   160  	echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile"
   161  
   162  	echo >> "$version/Dockerfile"
   163  
   164  	# print build tags in alphabetical order
   165  	buildTags=$( echo "selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' )
   166  
   167  	echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile"
   168  	echo "ENV RUNC_BUILDTAGS $runcBuildTags" >> "$version/Dockerfile"
   169  	echo >> "$version/Dockerfile"
   170  
   171  	case "$from" in
   172                  oraclelinux:6)
   173                          # We need to set the CGO_CPPFLAGS environment to use the updated UEKR4 headers with all the userns stuff.
   174                          # The ordering is very important and should not be changed.
   175                          echo 'ENV CGO_CPPFLAGS -D__EXPORTED_HEADERS__ \'  >> "$version/Dockerfile"
   176                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/generated/uapi \'  >> "$version/Dockerfile"
   177                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/uapi \'  >> "$version/Dockerfile"
   178                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/generated/uapi \'  >> "$version/Dockerfile"
   179                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/uapi \'  >> "$version/Dockerfile"
   180                          echo '                 -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include'  >> "$version/Dockerfile"
   181                          echo >> "$version/Dockerfile"
   182                          ;;
   183                  *) ;;
   184          esac
   185  
   186  
   187  done