generate.sh 6.3 KB

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