Skip to content

Commit

Permalink
Added dockerfiles updating script
Browse files Browse the repository at this point in the history
Signed-off-by: bharathappali <bharath.appali@gmail.com>
  • Loading branch information
bharathappali committed Dec 21, 2020
1 parent 8e5550b commit 99967b8
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 2 deletions.
9 changes: 7 additions & 2 deletions update_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down
125 changes: 125 additions & 0 deletions update_dockerfiles_on_merge.sh
Original file line number Diff line number Diff line change
@@ -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 "$(date '+%d-%m-%Y %H:%M:%S') : Auto-updating dockerfiles for PR #${PR_NUM}" -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 <Pull request id/number >"
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
6 changes: 6 additions & 0 deletions update_multiarch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -43,6 +45,10 @@ do
btypes=$(parse_vm_entry "${vm}" "${version}" "${package}" "${os}" "Type:")
dir=$(parse_vm_entry "${vm}" "${version}" "${package}" "${os}" "Directory:")

if [ ! -z "${build_arg}" ]; then
builds="${build_arg}"
fi

for build in ${builds}
do
echo "Getting latest shasum info for [ ${version} ${vm} ${package} ${build} ]"
Expand Down

0 comments on commit 99967b8

Please sign in to comment.