From d2d981ea6f411b60ee89411703138fdf2cb35d64 Mon Sep 17 00:00:00 2001 From: bharathappali Date: Tue, 20 Oct 2020 04:12:02 +0530 Subject: [PATCH] Added dockerfiles updating script Signed-off-by: bharathappali --- update_all.sh | 9 ++- update_dockerfiles_on_merge.sh | 125 +++++++++++++++++++++++++++++++++ update_multiarch.sh | 8 ++- 3 files changed, 139 insertions(+), 3 deletions(-) create mode 100755 update_dockerfiles_on_merge.sh diff --git a/update_all.sh b/update_all.sh index 269299121..bee0724cd 100755 --- a/update_all.sh +++ b/update_all.sh @@ -17,6 +17,11 @@ set -o pipefail # shellcheck source=common_functions.sh source ./common_functions.sh +if [ -n "$1" ]; then + build_arg="$1" +fi + + for ver in ${supported_versions} do # Cleanup any old containers and images @@ -32,7 +37,7 @@ do echo " " echo "===============================================================================" # Generate the Dockerfiles for the unofficial images. - ./update_multiarch.sh "${ver}" + ./update_multiarch.sh "${ver}" "${build_arg}" # hotspot.config and openj9.config now only contain the unofficial image list. # hotspot-official.config and openj9-official.config contain the officially supported list. @@ -41,7 +46,7 @@ do cp config/openj9-official.config config/openj9.config # Now generate the Dockerfiles for the official images. - ./update_multiarch.sh "${ver}" + ./update_multiarch.sh "${ver}" "${build_arg}" # Restore the original files. git checkout config/hotspot.config config/openj9.config diff --git a/update_dockerfiles_on_merge.sh b/update_dockerfiles_on_merge.sh new file mode 100755 index 000000000..9a02c6464 --- /dev/null +++ b/update_dockerfiles_on_merge.sh @@ -0,0 +1,125 @@ +#!/bin/bash + +source common_functions.sh + +REMOTE_UPSTREAM="upstream" +BRANCH_NAME="automated-branch-for-dockerfiles" + +function proceed_to_update() { + UPSTREAM=$(cat .git/config | grep -m 1 -B 1 "https://github.com/AdoptOpenJDK/openjdk-docker" | head -n 1 | cut -d '"' -f 2) + if [ -z $UPSTREAM ]; then + if cat .git/config | grep -Fxq "[remote \"upstream\"]"; then + git remote add temp-upstream https://github.com/AdoptOpenJDK/openjdk-docker + REMOTE_UPSTREAM="temp-upstream" + else + git remote add upstream https://github.com/AdoptOpenJDK/openjdk-docker + fi + else + REMOTE_UPSTREAM="$UPSTREAM" + fi + git checkout master + git fetch ${REMOTE_UPSTREAM} + git merge ${REMOTE_UPSTREAM}/master + local CHECK_LOCAL=$(git branch --list ${BRANCH_NAME}) + if [[ -z ${CHECK_LOCAL} ]]; then + git checkout -b ${BRANCH_NAME} + else + git branch -D ${BRANCH_NAME} + git checkout -b ${BRANCH_NAME} + fi + source update_all.sh releases + git add ${supported_versions} + git commit -m "Updating dockerfiles via update_dockerfiles_on_merge.sh script" -s + git push -f origin ${BRANCH_NAME} + echo "Please raise a PR to AdoptOpenJDK/openjdk-docker master from branch ${BRANCH_NAME}" + echo "Exiting." + exit 0 +} + +function script_usage() { + echo "USAGE:" + echo "" + echo " update_dockerfiles_on_merge.sh " + echo "" + echo "EXAMPLE:" + echo "" + echo "To update the dockerfiles if the PR 444 is merged, you need to ENTER the following command :" + echo "" + echo " ./update_dockerfiles_on_merge.sh 444" + echo "" +} + + +function check_for_result() { + local RESULT=$(curl -fs https://api.github.com/repos/AdoptOpenJDK/openjdk-docker/pulls/${PR_NUM} | grep "\"merged\"" | tr ',' ' ' | tr -d " " | cut -d ":" -f 2) + + if [ -z $RESULT ]; then + echo "" + echo "INVALID PR. PLEASE CHECK AGAIN AND RUN THE SCRIPT" + echo "" + exit 1 + fi + + local ITERATION=1 + while [ "$RESULT" == "false" ] + do + echo "TRAIL : $ITERATION - PR Haven't been merged, Retrying after 1 minute" + ITERATION=$(expr $ITERATION + 1) + sleep 60 + RESULT=$(curl -fs https://api.github.com/repos/AdoptOpenJDK/openjdk-docker/pulls/${PR_NUM} | grep "\"merged\"" | tr ',' ' ' | tr -d " " | cut -d ":" -f 2) + done + + if [ "$RESULT" != "true" ]; then + echo "Unexpected Error. Exiting" + exit 1 + fi +} + +if [ "$#" -ne 1 ]; then + echo "You must enter only the PR number as an argument. See the usage below." + echo "" + script_usage + exit 1 +fi + +PR_NUM=$1 + +NUM_REGEX='^[0-9]+$' + +if ! [[ $PR_NUM =~ $NUM_REGEX ]] ; then + echo "Expected PR number as arg. See the usage below." + echo "" + script_usage + exit 1 +fi + +NOCOLOR='\033[0m' # No Color - Color Reset + +# Normal Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' + +# Bold Colors +BRED='\033[1;31m' +BGREEN='\033[1;32m' +BBLUE='\033[1;34m' +BCYAN='\033[1;36m' + +echo "" +echo -e "This script calls the ${BBLUE}'update_all.sh'${NOCOLOR} to update the dockerfiles" +echo "" +echo -e "It pulls ${BCYAN}AdoptOpenJDK/openjdk-docker${NOCOLOR} ${BLUE}master${NOCOLOR} branch latest changes and" +echo -e "merges local master. Later creates a new branch to update dockerfiles" +echo "" +echo -e "${BGREEN}New branch name${NOCOLOR} : ${BLUE}${BRANCH_NAME}${NOCOLOR}" +echo "" +echo -e "If the branch exists, it ${RED}deletes${NOCOLOR} existing branch and creates new" +echo -e "branch which is even with master" +echo "" +echo -e "${BRED}CAUTION${NOCOLOR} : Please run this script after saving your work (commiting) as ${RED}it may mess up your changes${NOCOLOR}." +echo "" +echo "" +check_for_result +proceed_to_update diff --git a/update_multiarch.sh b/update_multiarch.sh index a518a3972..fadefca22 100755 --- a/update_multiarch.sh +++ b/update_multiarch.sh @@ -25,6 +25,8 @@ if [ -n "$1" ]; then set_version "$1" fi +build_arg="$2" + # Set the OSes that will be built on based on the current arch set_arch_os @@ -43,7 +45,11 @@ do btypes=$(parse_vm_entry "${vm}" "${version}" "${package}" "${os}" "Type:") dir=$(parse_vm_entry "${vm}" "${version}" "${package}" "${os}" "Directory:") - for build in ${builds} + if [ ! -z "${build_arg}" ]; then + builds="${build_arg}" + fi + + for build in ${builds} do echo "Getting latest shasum info for [ ${version} ${vm} ${package} ${build} ]" get_shasums "${version}" "${vm}" "${package}" "${build}"