|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# Script that generates the `adoptopenjdk` config file for the official docker |
| 16 | +# image github repo and the doc updates for the unofficial docker image repo. |
| 17 | +# Process to update the official docker image repo |
| 18 | +# 1. Run ./update_all.sh to update all the dockerfiles in the current repo. |
| 19 | +# 2. Submit PR to push the newly generated dockerfiles to the current repo. |
| 20 | +# 3. After above PR is merged, git pull the latest changes. |
| 21 | +# 4. Run this command |
| 22 | +# |
| 23 | +set -o pipefail |
| 24 | + |
| 25 | +source ./common_functions.sh |
| 26 | + |
| 27 | +official_docker_image_file="adoptopenjdk" |
| 28 | +oses="ubuntu alpine debian windows" |
| 29 | + |
| 30 | +latest_version="12" |
| 31 | +hotspot_latest_tags="hotspot, latest" |
| 32 | +openj9_latest_tags="openj9" |
| 33 | + |
| 34 | +git_repo="https://github.com/AdoptOpenJDK/openjdk-docker/blob/master" |
| 35 | + |
| 36 | +# Get the latest git commit of the current repo. |
| 37 | +# This is assumed to have all the latest dockerfiles already. |
| 38 | +gitcommit=$(git log | head -1 | awk '{ print $2 }') |
| 39 | + |
| 40 | +print_official_text() { |
| 41 | + echo "$*" >> ${official_docker_image_file} |
| 42 | +} |
| 43 | + |
| 44 | +print_unofficial_tags() { |
| 45 | + for tag in $* |
| 46 | + do |
| 47 | + echo -n "\`${tag}\`, " >> ${ver}_${vm}.txt |
| 48 | + done |
| 49 | +} |
| 50 | + |
| 51 | +print_official_header() { |
| 52 | + print_official_text "# AdoptOpenJDK official images for OpenJDK with HotSpot and OpenJDK with Eclipse OpenJ9." |
| 53 | + print_official_text |
| 54 | + print_official_text "Maintainers: Dinakar Guniguntala <[email protected]> (@dinogun)" |
| 55 | + print_official_text "GitRepo: https://github.com/AdoptOpenJDK/openjdk-docker.git" |
| 56 | +} |
| 57 | + |
| 58 | +function generate_unofficial_image_info() { |
| 59 | + full_version=$(grep "VERSION" ${file} | awk '{ print $3 }') |
| 60 | + # Replace "+" with "_" in the version info as docker does not support "+" |
| 61 | + full_version=$(echo ${full_version} | sed 's/+/_/') |
| 62 | + if [ "${pkg}" == "jre" ]; then |
| 63 | + full_version=$(echo ${full_version} | sed 's/jdk/jre/') |
| 64 | + fi |
| 65 | + |
| 66 | + # Suffix nightly and slim builds accordingly |
| 67 | + if [ "${build}" == "nightly" ]; then |
| 68 | + full_version="${full_version}-${build}" |
| 69 | + fi |
| 70 | + if [ "${btype}" == "slim" ]; then |
| 71 | + full_version="${full_version}-${btype}" |
| 72 | + fi |
| 73 | + |
| 74 | + # Build a lit of super tags (in addition to the non arch specific tags) |
| 75 | + super_tags=""; |
| 76 | + case ${os} in |
| 77 | + ubuntu) |
| 78 | + # JRE ubuntu builds have a `jre` tag |
| 79 | + if [ "${pkg}" == "jre" ]; then |
| 80 | + super_tags="${pkg}"; |
| 81 | + fi |
| 82 | + # Nightly ubuntu builds have a `nightly` tag |
| 83 | + if [ "${build}" == "nightly" ]; then |
| 84 | + if [ "${super_tags}" == "" ]; then |
| 85 | + super_tags="${build}"; |
| 86 | + else |
| 87 | + super_tags="${super_tags}-${build}" |
| 88 | + fi |
| 89 | + fi |
| 90 | + # Slim ubuntu builds have a `slim` tag |
| 91 | + if [ "${btype}" == "slim" ]; then |
| 92 | + if [ "${super_tags}" == "" ]; then |
| 93 | + super_tags="${btype}" |
| 94 | + else |
| 95 | + super_tags="${super_tags}-${btype}" |
| 96 | + fi |
| 97 | + fi |
| 98 | + # If none of the above, it has to be the `latest` build |
| 99 | + if [ "${super_tags}" == "" ]; then |
| 100 | + super_tags="latest"; |
| 101 | + fi |
| 102 | + ;; |
| 103 | + alpine|debian|windows) |
| 104 | + # Non Ubuntu builds all have the `$os` tag prepended |
| 105 | + super_tags="${os}"; |
| 106 | + if [ "${pkg}" == "jre" ]; then |
| 107 | + super_tags="${super_tags}-${pkg}"; |
| 108 | + fi |
| 109 | + if [ "${build}" == "nightly" ]; then |
| 110 | + super_tags="${super_tags}-${build}"; |
| 111 | + fi |
| 112 | + if [ "${btype}" == "slim" ]; then |
| 113 | + super_tags="${super_tags}-${btype}" |
| 114 | + fi |
| 115 | + ;; |
| 116 | + esac |
| 117 | + |
| 118 | + # Unofficial images support x86_64, aarch64, s390x and ppc64le |
| 119 | + # Remove ppc64el, amd64 and arm64 |
| 120 | + # Retain ppc64le, x86_64 and aarch64 |
| 121 | + arches=$(echo $(grep ') \\' ${file} | \ |
| 122 | + sed 's/\(ppc64el\|amd64\|arm64\)//g' | \ |
| 123 | + sort | grep -v "*" | \ |
| 124 | + sed 's/) \\//g; s/|/ /g')) |
| 125 | + if [ "${os}" == "alpine" ]; then |
| 126 | + # Alpine builds are only available for x86_64 currently |
| 127 | + arches="x86_64" |
| 128 | + fi |
| 129 | + print_unofficial_tags "${super_tags} ${full_version}" |
| 130 | + for arch in ${arches} |
| 131 | + do |
| 132 | + print_unofficial_tags "${arch}-${os}-${full_version}" >> ${ver}_${vm}.txt |
| 133 | + done |
| 134 | + # Remove the leading "./" from the file name |
| 135 | + file=$(echo ${file} | cut -c 3-) |
| 136 | + echo "(*${file}*)](${git_repo}/${file})" >> ${ver}_${vm}.txt |
| 137 | +} |
| 138 | + |
| 139 | +function generate_official_image_tags() { |
| 140 | + # Generate the tags |
| 141 | + full_version=$(grep "VERSION" ${file} | awk '{ print $3 }') |
| 142 | + |
| 143 | + # Remove any `jdk` references in the version |
| 144 | + ojdk_version=$(echo ${full_version} | sed 's/\(jdk\|jdk-\)//' | awk -F '_' '{ print $1 }') |
| 145 | + # Replace "+" with "_" in the version info as docker does not support "+" |
| 146 | + ojdk_version=$(echo ${ojdk_version} | sed 's/+/_/') |
| 147 | + |
| 148 | + # Official image build tags are as below |
| 149 | + # 8u212-jre-openj9_0.12.1 |
| 150 | + # 8-jre-openj9 |
| 151 | + # 8u212-jdk-hotspot |
| 152 | + full_ver_tag="${ojdk_version}-${pkg}" |
| 153 | + # Add the openj9 version |
| 154 | + if [ "${vm}" == "openj9" ]; then |
| 155 | + openj9_version=$(echo ${full_version} | awk -F '_' '{ print $2 }') |
| 156 | + full_ver_tag="${full_ver_tag}-${openj9_version}" |
| 157 | + else |
| 158 | + full_ver_tag="${full_ver_tag}-${vm}" |
| 159 | + fi |
| 160 | + ver_tag="${ver}-${pkg}-${vm}" |
| 161 | + all_tags="${full_ver_tag}, ${ver_tag}" |
| 162 | + # jdk builds also have additional tags |
| 163 | + if [ "${pkg}" == "jdk" ]; then |
| 164 | + jdk_tag="${ver}-${vm}" |
| 165 | + all_tags="${all_tags}, ${jdk_tag}" |
| 166 | + # Add the "latest", "hotspot" and "openj9" tags for the right version |
| 167 | + if [ "${ver}" == "${latest_version}" ]; then |
| 168 | + vm_tags="${vm}_latest_tags" |
| 169 | + eval vm_tags_val=\${$vm_tags} |
| 170 | + all_tags="${all_tags}, ${vm_tags_val}" |
| 171 | + fi |
| 172 | + fi |
| 173 | +} |
| 174 | + |
| 175 | +function generate_official_image_arches() { |
| 176 | + # Generate the supported arches for the above tags. |
| 177 | + # Official images supports amd64, arm64vX, s390x and ppc64le |
| 178 | + # Remove ppc64el, x86_64 and aarch64 |
| 179 | + # Retain ppc64le, amd64 and arm64 |
| 180 | + arches=$(echo $(grep ') \\' ${file} | \ |
| 181 | + sed 's/\(ppc64el\|x86_64\|aarch64\)//g' | \ |
| 182 | + # armhf is arm32v7 and arm64 is arm64v8 for docker builds |
| 183 | + sed 's/armhf/arm32v7/' | \ |
| 184 | + sed 's/arm64/arm64v8/' | \ |
| 185 | + sort | grep -v "*" | \ |
| 186 | + sed 's/) \\//g; s/|/ /g')) |
| 187 | + # Add a "," after each arch |
| 188 | + arches=$(echo ${arches} | sed 's/ /, /g') |
| 189 | +} |
| 190 | + |
| 191 | +function print_official_image_file() { |
| 192 | + # Print them all |
| 193 | + echo "Tags: ${all_tags}" >> ${official_docker_image_file} |
| 194 | + echo "Architectures: ${arches}" >> ${official_docker_image_file} |
| 195 | + echo "GitCommit: ${gitcommit}" >> ${official_docker_image_file} |
| 196 | + echo "Directory: ${dfdir}" >> ${official_docker_image_file} |
| 197 | + echo "File: ${dfname}" >> ${official_docker_image_file} |
| 198 | +} |
| 199 | + |
| 200 | +rm -f ${official_docker_image_file} |
| 201 | +print_official_header |
| 202 | + |
| 203 | +# Currently we are not pushing official docker images for Alpine, Debian and Windows |
| 204 | +official_os_ignore_array=(alpine debian windows) |
| 205 | + |
| 206 | +# Generate config and doc info only for "supported" official builds. |
| 207 | +function generate_official_image_info() { |
| 208 | + # If it is an unsupported OS from the array above, return. |
| 209 | + for arr_os in "${official_os_ignore_array[@]}"; |
| 210 | + do |
| 211 | + if [ "${os}" == "${arr_os}" ]; then |
| 212 | + return; |
| 213 | + fi |
| 214 | + done |
| 215 | + # We do not push our nightly and slim images either. |
| 216 | + if [ "${build}" == "nightly" -o "${btype}" == "slim" ]; then |
| 217 | + return; |
| 218 | + fi |
| 219 | + |
| 220 | + generate_official_image_tags |
| 221 | + generate_official_image_arches |
| 222 | + print_official_image_file |
| 223 | +} |
| 224 | + |
| 225 | +# Iterate through all the VMs, for each supported version and packages to |
| 226 | +# generate the config file for the official docker images. |
| 227 | +# Official docker images = https://hub.docker.com/_/adoptopenjdk |
| 228 | +for vm in ${all_jvms} |
| 229 | +do |
| 230 | + for ver in ${supported_versions} |
| 231 | + do |
| 232 | + print_official_text |
| 233 | + print_official_text "#------------------------------${vm} v${ver} images-------------------------------" |
| 234 | + for pkg in ${all_packages} |
| 235 | + do |
| 236 | + print_official_text |
| 237 | + # Iterate through each of the Dockerfiles. |
| 238 | + for file in $(find . -name "Dockerfile.*" | grep "/${ver}" | grep "${vm}" | grep "${pkg}") |
| 239 | + do |
| 240 | + # file will look like ./12/jdk/debian/Dockerfile.openj9.nightly.slim |
| 241 | + # dockerfile name |
| 242 | + dfname=$(basename ${file}) |
| 243 | + # dockerfile dir |
| 244 | + dfdir=$(dirname ${file} | cut -c 3-) |
| 245 | + os=$(echo ${file} | awk -F '/' '{ print $4 }') |
| 246 | + # build = release or nightly |
| 247 | + build=$(echo ${dfname} | awk -F "." '{ print $3 }') |
| 248 | + # btype = full or slim |
| 249 | + btype=$(echo ${dfname} | awk -F "." '{ print $4 }') |
| 250 | + |
| 251 | + generate_official_image_info |
| 252 | + done |
| 253 | + done |
| 254 | + done |
| 255 | +done |
| 256 | + |
| 257 | +# This loop generated the documentation for the unofficial docker images |
| 258 | +# Unofficial docker images = https://hub.docker.com/r/adoptopenjdk |
| 259 | +for vm in ${all_jvms} |
| 260 | +do |
| 261 | + for ver in ${supported_versions} |
| 262 | + do |
| 263 | + # Remove any previous doc files |
| 264 | + rm -f ${ver}_${vm}.txt |
| 265 | + for build in ${supported_builds} |
| 266 | + do |
| 267 | + if [ "${build}" == "releases" ]; then |
| 268 | + echo "**Release Builds**" >> ${ver}_${vm}.txt |
| 269 | + else |
| 270 | + echo "**Nightly Builds**" >> ${ver}_${vm}.txt |
| 271 | + fi |
| 272 | + for os in ${oses} |
| 273 | + do |
| 274 | + for pkg in ${all_packages} |
| 275 | + do |
| 276 | + for file in $(find . -name "Dockerfile.*" | grep "/${ver}" | grep "${vm}" | grep "${build}" | grep "${os}" | grep "${pkg}") |
| 277 | + do |
| 278 | + echo -n "- [" >> ${ver}_${vm}.txt |
| 279 | + dfname=$(basename ${file}) |
| 280 | + # dockerfile dir |
| 281 | + dfdir=$(dirname ${file} | cut -c 3-) |
| 282 | + pkg=$(echo ${file} | awk -F '/' '{ print $3 }') |
| 283 | + os=$(echo ${file} | awk -F '/' '{ print $4 }') |
| 284 | + # build = release or nightly |
| 285 | + build=$(echo ${dfname} | awk -F "." '{ print $3 }') |
| 286 | + # btype = full or slim |
| 287 | + btype=$(echo ${dfname} | awk -F "." '{ print $4 }') |
| 288 | + |
| 289 | + generate_unofficial_image_info |
| 290 | + done |
| 291 | + done |
| 292 | + echo >> ${ver}_${vm}.txt |
| 293 | + done |
| 294 | + echo >> ${ver}_${vm}.txt |
| 295 | + done |
| 296 | + done |
| 297 | +done |
0 commit comments