Improve coding style of shell scripts
This commit is contained in:
parent
16a8690e1d
commit
bb92568f3a
54
functions.sh
54
functions.sh
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
# Utlity functions
|
# Utlity functions
|
||||||
|
|
||||||
info() {
|
info() {
|
||||||
|
@ -37,12 +37,12 @@ function get_arch() {
|
||||||
arch="arm32v7"
|
arch="arm32v7"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "$0 does not support architecture $arch ... aborting"
|
echo "$0 does not support architecture ${arch} ... aborting"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo "$arch"
|
echo "${arch}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get corresponding variants based on the architecture.
|
# Get corresponding variants based on the architecture.
|
||||||
|
@ -62,12 +62,12 @@ function get_variants() {
|
||||||
|
|
||||||
arch=$(get_arch)
|
arch=$(get_arch)
|
||||||
variantsfilter=("$@")
|
variantsfilter=("$@")
|
||||||
IFS=' ' read -ra availablevariants <<<"$(grep "^$arch" "$dir/architectures" | sed -E 's/'"$arch"'[[:space:]]*//' | sed -E 's/,/ /g')"
|
IFS=' ' read -ra availablevariants <<<"$(grep "^${arch}" "${dir}/architectures" | sed -E 's/'"${arch}"'[[:space:]]*//' | sed -E 's/,/ /g')"
|
||||||
|
|
||||||
if [ ${#variantsfilter[@]} -gt 0 ]; then
|
if [ ${#variantsfilter[@]} -gt 0 ]; then
|
||||||
for variant1 in "${availablevariants[@]}"; do
|
for variant1 in "${availablevariants[@]}"; do
|
||||||
for variant2 in "${variantsfilter[@]}"; do
|
for variant2 in "${variantsfilter[@]}"; do
|
||||||
if [[ "$variant1" == "$variant2" ]]; then
|
if [ "$variant1" = "$variant2" ]; then
|
||||||
variants+=("$variant1")
|
variants+=("$variant1")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -100,16 +100,16 @@ function get_supported_arches() {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Get default supported arches
|
# Get default supported arches
|
||||||
lines=$(grep "$variant" "$(dirname "$version")"/architectures 2>/dev/null | cut -d' ' -f1)
|
lines=$(grep "$variant" "$(dirname "${version}")"/architectures 2>/dev/null | cut -d' ' -f1)
|
||||||
|
|
||||||
# Get version specific supported architectures if there is specialized information
|
# Get version specific supported architectures if there is specialized information
|
||||||
if [ -a "$version"/architectures ]; then
|
if [ -a "${version}"/architectures ]; then
|
||||||
lines=$(grep "$variant" "$version"/architectures 2>/dev/null | cut -d' ' -f1)
|
lines=$(grep "$variant" "${version}"/architectures 2>/dev/null | cut -d' ' -f1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while IFS='' read -r line; do
|
while IFS='' read -r line; do
|
||||||
arches+=("$line")
|
arches+=("${line}")
|
||||||
done <<<"$lines"
|
done <<<"${lines}"
|
||||||
|
|
||||||
echo "${arches[@]}"
|
echo "${arches[@]}"
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ function get_config() {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
local value
|
local value
|
||||||
value=$(grep "^$name" "$dir/config" | sed -E 's/'"$name"'[[:space:]]*//')
|
value=$(grep "^$name" "${dir}/config" | sed -E 's/'"$name"'[[:space:]]*//')
|
||||||
echo "$value"
|
echo "$value"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,13 +150,13 @@ function get_versions() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for dir in "${dirs[@]}"; do
|
for dir in "${dirs[@]}"; do
|
||||||
if [ -a "$dir/config" ]; then
|
if [ -a "${dir}/config" ]; then
|
||||||
local subdirs
|
local subdirs
|
||||||
IFS=' ' read -ra subdirs <<<"$(get_versions "${dir#./}")"
|
IFS=' ' read -ra subdirs <<<"$(get_versions "${dir#./}")"
|
||||||
for subdir in "${subdirs[@]}"; do
|
for subdir in "${subdirs[@]}"; do
|
||||||
versions+=("$subdir")
|
versions+=("$subdir")
|
||||||
done
|
done
|
||||||
elif [ -a "$dir/Dockerfile" ]; then
|
elif [ -a "${dir}/Dockerfile" ]; then
|
||||||
versions+=("${dir#./}")
|
versions+=("${dir#./}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -171,7 +171,7 @@ function get_fork_name() {
|
||||||
version=$1
|
version=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
IFS='/' read -ra versionparts <<<"$version"
|
IFS='/' read -ra versionparts <<<"${version}"
|
||||||
if [ ${#versionparts[@]} -gt 1 ]; then
|
if [ ${#versionparts[@]} -gt 1 ]; then
|
||||||
echo "${versionparts[0]}"
|
echo "${versionparts[0]}"
|
||||||
fi
|
fi
|
||||||
|
@ -182,7 +182,7 @@ function get_full_version() {
|
||||||
version=$1
|
version=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
grep -m1 'ENV NODE_VERSION ' "$version/Dockerfile" | cut -d' ' -f3
|
grep -m1 'ENV NODE_VERSION ' "${version}/Dockerfile" | cut -d' ' -f3
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_major_minor_version() {
|
function get_major_minor_version() {
|
||||||
|
@ -191,9 +191,9 @@ function get_major_minor_version() {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
local fullversion
|
local fullversion
|
||||||
fullversion=$(get_full_version "$version")
|
fullversion=$(get_full_version "${version}")
|
||||||
|
|
||||||
echo "$(echo "$fullversion" | cut -d'.' -f1).$(echo "$fullversion" | cut -d'.' -f2)"
|
echo "$(echo "${fullversion}" | cut -d'.' -f1).$(echo "${fullversion}" | cut -d'.' -f2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_tag() {
|
function get_tag() {
|
||||||
|
@ -206,14 +206,14 @@ function get_tag() {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
local tagversion
|
local tagversion
|
||||||
if [ "$versiontype" = full ]; then
|
if [ "${versiontype}" = full ]; then
|
||||||
tagversion=$(get_full_version "$version")
|
tagversion=$(get_full_version "${version}")
|
||||||
elif [ "$versiontype" = majorminor ]; then
|
elif [ "${versiontype}" = majorminor ]; then
|
||||||
tagversion=$(get_major_minor_version "$version")
|
tagversion=$(get_major_minor_version "${version}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local tagparts
|
local tagparts
|
||||||
IFS=' ' read -ra tagparts <<<"$(get_fork_name "$version") $tagversion"
|
IFS=' ' read -ra tagparts <<<"$(get_fork_name "${version}") ${tagversion}"
|
||||||
IFS='-'
|
IFS='-'
|
||||||
echo "${tagparts[*]}"
|
echo "${tagparts[*]}"
|
||||||
unset IFS
|
unset IFS
|
||||||
|
@ -230,12 +230,12 @@ function sort_versions() {
|
||||||
unset IFS
|
unset IFS
|
||||||
|
|
||||||
while IFS='' read -r line; do
|
while IFS='' read -r line; do
|
||||||
sorted+=("$line")
|
sorted+=("${line}")
|
||||||
done <<<"$(echo "$lines" | grep "^[0-9]" | sort -r)"
|
done <<<"$(echo "${lines}" | grep "^[0-9]" | sort -r)"
|
||||||
|
|
||||||
while IFS='' read -r line; do
|
while IFS='' read -r line; do
|
||||||
sorted+=("$line")
|
sorted+=("${line}")
|
||||||
done <<<"$(echo "$lines" | grep -v "^[0-9]" | sort -r)"
|
done <<<"$(echo "${lines}" | grep -v "^[0-9]" | sort -r)"
|
||||||
|
|
||||||
echo "${sorted[@]}"
|
echo "${sorted[@]}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
. functions.sh
|
. functions.sh
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ fileCommit() {
|
||||||
git log -1 --format='format:%H' HEAD -- "$@"
|
git log -1 --format='format:%H' HEAD -- "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "# this file is generated via ${url}/blob/$(fileCommit "$self")/$self"
|
echo "# this file is generated via ${url}/blob/$(fileCommit "${self}")/${self}"
|
||||||
echo
|
echo
|
||||||
echo "Maintainers: The Node.js Docker Team <${url}> (@nodejs)"
|
echo "Maintainers: The Node.js Docker Team <${url}> (@nodejs)"
|
||||||
echo "GitRepo: ${url}.git"
|
echo "GitRepo: ${url}.git"
|
||||||
|
@ -49,7 +50,7 @@ join() {
|
||||||
get_stub() {
|
get_stub() {
|
||||||
local version="$1"
|
local version="$1"
|
||||||
shift
|
shift
|
||||||
IFS='/' read -ra versionparts <<<"$version"
|
IFS='/' read -ra versionparts <<<"${version}"
|
||||||
local stub
|
local stub
|
||||||
eval stub="$(join '_' "${versionparts[@]}" | awk -F. '{ print "$array_" $1 }')"
|
eval stub="$(join '_' "${versionparts[@]}" | awk -F. '{ print "$array_" $1 }')"
|
||||||
echo "$stub"
|
echo "$stub"
|
||||||
|
@ -57,16 +58,16 @@ get_stub() {
|
||||||
|
|
||||||
for version in "${versions[@]}"; do
|
for version in "${versions[@]}"; do
|
||||||
# Skip "docs" and other non-docker directories
|
# Skip "docs" and other non-docker directories
|
||||||
[ -f "$version/Dockerfile" ] || continue
|
[ -f "${version}/Dockerfile" ] || continue
|
||||||
|
|
||||||
stub=$(get_stub "$version")
|
stub=$(get_stub "${version}")
|
||||||
commit="$(fileCommit "$version")"
|
commit="$(fileCommit "${version}")"
|
||||||
fullVersion="$(get_tag "$version" full)"
|
fullVersion="$(get_tag "${version}" full)"
|
||||||
majorMinorVersion="$(get_tag "$version" majorminor)"
|
majorMinorVersion="$(get_tag "${version}" majorminor)"
|
||||||
|
|
||||||
IFS=' ' read -ra versionAliases <<<"$fullVersion $majorMinorVersion $stub"
|
IFS=' ' read -ra versionAliases <<<"$fullVersion $majorMinorVersion $stub"
|
||||||
# Get supported architectures for a specific version. See details in function.sh
|
# Get supported architectures for a specific version. See details in function.sh
|
||||||
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "$version" "default")"
|
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "${version}" "default")"
|
||||||
|
|
||||||
echo "Tags: $(join ', ' "${versionAliases[@]}")"
|
echo "Tags: $(join ', ' "${versionAliases[@]}")"
|
||||||
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
|
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
|
||||||
|
@ -76,19 +77,19 @@ for version in "${versions[@]}"; do
|
||||||
|
|
||||||
# Get supported variants according to the target architecture.
|
# Get supported variants according to the target architecture.
|
||||||
# See details in function.sh
|
# See details in function.sh
|
||||||
IFS=' ' read -ra variants <<<"$(get_variants "$(dirname "$version")")"
|
IFS=' ' read -ra variants <<<"$(get_variants "$(dirname "${version}")")"
|
||||||
for variant in "${variants[@]}"; do
|
for variant in "${variants[@]}"; do
|
||||||
# Skip non-docker directories
|
# Skip non-docker directories
|
||||||
[ -f "$version/$variant/Dockerfile" ] || continue
|
[ -f "${version}/${variant}/Dockerfile" ] || continue
|
||||||
|
|
||||||
commit="$(fileCommit "$version/$variant")"
|
commit="$(fileCommit "${version}/${variant}")"
|
||||||
|
|
||||||
slash='/'
|
slash='/'
|
||||||
variantAliases=("${versionAliases[@]/%/-${variant//$slash/-}}")
|
variantAliases=("${versionAliases[@]/%/-${variant//$slash/-}}")
|
||||||
variantAliases=("${variantAliases[@]//latest-/}")
|
variantAliases=("${variantAliases[@]//latest-/}")
|
||||||
# Get supported architectures for a specific version and variant.
|
# Get supported architectures for a specific version and variant.
|
||||||
# See details in function.sh
|
# See details in function.sh
|
||||||
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "$version" "$variant")"
|
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "${version}" "${variant}")"
|
||||||
|
|
||||||
echo "Tags: $(join ', ' "${variantAliases[@]}")"
|
echo "Tags: $(join ', ' "${variantAliases[@]}")"
|
||||||
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
|
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
. functions.sh
|
. functions.sh
|
||||||
|
|
||||||
|
@ -16,19 +17,19 @@ else
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$COMMIT_MESSAGE" =~ Merge\ pull\ request\ \#([0-9]*) ]]; then
|
if [[ "${COMMIT_MESSAGE}" =~ Merge\ pull\ request\ \#([0-9]*) ]]; then
|
||||||
|
|
||||||
# This is a merge from a pull request
|
# This is a merge from a pull request
|
||||||
PR_NUMBER="${BASH_REMATCH[1]}"
|
PR_NUMBER="${BASH_REMATCH[1]}"
|
||||||
COMMIT_MESSAGE="$(printf "%s" "$COMMIT_MESSAGE" | tail -n 1)"
|
COMMIT_MESSAGE="$(printf "%s" "${COMMIT_MESSAGE}" | tail -n 1)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IMAGES_FILE="library/node"
|
IMAGES_FILE="library/node"
|
||||||
REPO_NAME="official-images"
|
REPO_NAME="official-images"
|
||||||
ORIGIN_SLUG="$GITHUB_USERNAME/$REPO_NAME"
|
ORIGIN_SLUG="${GITHUB_USERNAME}/${REPO_NAME}"
|
||||||
UPSTREAM_SLUG="docker-library/$REPO_NAME"
|
UPSTREAM_SLUG="docker-library/${REPO_NAME}"
|
||||||
DOCKER_SLUG="nodejs/docker-node"
|
DOCKER_SLUG="nodejs/docker-node"
|
||||||
gitpath="../$REPO_NAME"
|
gitpath="../${REPO_NAME}"
|
||||||
|
|
||||||
function updated() {
|
function updated() {
|
||||||
local versions
|
local versions
|
||||||
|
@ -38,13 +39,12 @@ function updated() {
|
||||||
IFS=','
|
IFS=','
|
||||||
get_versions
|
get_versions
|
||||||
)"
|
)"
|
||||||
images_changed=$(git diff --name-only "$COMMIT_ID".."$COMMIT_ID"~1 "${versions[@]}")
|
images_changed=$(git diff --name-only "${COMMIT_ID}".."${COMMIT_ID}"~1 "${versions[@]}")
|
||||||
|
|
||||||
if [ -z "$images_changed" ]; then
|
if [ -z "$images_changed" ]; then
|
||||||
return 1
|
return 1
|
||||||
else
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function auth_header() {
|
function auth_header() {
|
||||||
|
@ -60,48 +60,48 @@ function permission_check() {
|
||||||
-s \
|
-s \
|
||||||
"https://api.github.com")"
|
"https://api.github.com")"
|
||||||
|
|
||||||
if [ "$(echo "$auth" | jq .message)" = "\"Bad credentials\"" ]; then
|
if [ "$(echo "$auth" | jq -r .message)" = "Bad credentials" ]; then
|
||||||
fatal "Authentication Failed! Invalid \$GITHUB_API_TOKEN"
|
fatal "Authentication Failed! Invalid \$GITHUB_API_TOKEN"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
auth="$(curl -H "$(auth_header)" \
|
auth="$(curl -H "$(auth_header)" \
|
||||||
-s \
|
-s \
|
||||||
"https://api.github.com/repos/$ORIGIN_SLUG/collaborators/$GITHUB_USERNAME/permission")"
|
"https://api.github.com/repos/${ORIGIN_SLUG}/collaborators/${GITHUB_USERNAME}/permission")"
|
||||||
if [ "$(echo "$auth" | jq .message)" != "null" ]; then
|
if [ "$(echo "$auth" | jq -r .message)" != "null" ]; then
|
||||||
fatal "\$GITHUB_API_TOKEN can't push to https://github.com/$ORIGIN_SLUG.git"
|
fatal "\$GITHUB_API_TOKEN can't push to https://github.com/${ORIGIN_SLUG}.git"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_git_author() {
|
function setup_git_author() {
|
||||||
GIT_AUTHOR_NAME="$(git show -s --format="%aN" "$COMMIT_ID")"
|
GIT_AUTHOR_NAME="$(git show -s --format="%aN" "${COMMIT_ID}")"
|
||||||
GIT_AUTHOR_EMAIL="$(git show -s --format="%aE" "$COMMIT_ID")"
|
GIT_AUTHOR_EMAIL="$(git show -s --format="%aE" "${COMMIT_ID}")"
|
||||||
GIT_COMMITTER_NAME="$(git show -s --format="%cN" "$COMMIT_ID")"
|
GIT_COMMITTER_NAME="$(git show -s --format="%cN" "${COMMIT_ID}")"
|
||||||
GIT_COMMITTER_EMAIL="$(git show -s --format="%cN" "$COMMIT_ID")"
|
GIT_COMMITTER_EMAIL="$(git show -s --format="%cN" "${COMMIT_ID}")"
|
||||||
|
|
||||||
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
|
||||||
}
|
}
|
||||||
|
|
||||||
function message() {
|
function message() {
|
||||||
echo "Node: $COMMIT_MESSAGE"
|
echo "Node: ${COMMIT_MESSAGE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function pr_payload() {
|
function pr_payload() {
|
||||||
local escaped_message
|
local escaped_message
|
||||||
escaped_message="$(echo "$COMMIT_MESSAGE" | sed -E -e "s/\"/\\\\\"/g")"
|
escaped_message="$(echo "${COMMIT_MESSAGE}" | sed -E -e "s/\"/\\\\\"/g")"
|
||||||
echo '{
|
echo "{
|
||||||
"title": "Node: '"$escaped_message"'",
|
'title': 'Node: ${escaped_message}',
|
||||||
"body": "Commit: nodejs/docker-node@'"$COMMIT_ID"'",
|
'body': 'Commit: nodejs/docker-node@${COMMIT_ID}',
|
||||||
"head": "'"$GITHUB_USERNAME"':'"$BRANCH_NAME"'",
|
'head': '${GITHUB_USERNAME}:${BRANCH_NAME}',
|
||||||
"base": "master"
|
'base': 'master'
|
||||||
}'
|
}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function comment_payload() {
|
function comment_payload() {
|
||||||
local pr_url
|
local pr_url
|
||||||
pr_url="$1"
|
pr_url="$1"
|
||||||
echo '{
|
echo "{
|
||||||
"body": "Created PR to the '"$REPO_NAME"' repo ('"$pr_url"')"
|
'body': 'Created PR to the ${REPO_NAME} repo (${pr_url})'
|
||||||
}'
|
}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated; then
|
if updated; then
|
||||||
|
@ -112,19 +112,19 @@ if updated; then
|
||||||
setup_git_author
|
setup_git_author
|
||||||
|
|
||||||
info "Cloning..."
|
info "Cloning..."
|
||||||
git clone --depth 50 "https://github.com/$UPSTREAM_SLUG.git" $gitpath 2>/dev/null
|
git clone --depth 50 "https://github.com/${UPSTREAM_SLUG}.git" ${gitpath} 2>/dev/null
|
||||||
|
|
||||||
stackbrew="$(./generate-stackbrew-library.sh)"
|
stackbrew="$(./generate-stackbrew-library.sh)"
|
||||||
|
|
||||||
cd $gitpath
|
cd $gitpath
|
||||||
|
|
||||||
echo "$stackbrew" >"$IMAGES_FILE"
|
echo "${stackbrew}" >"{$IMAGES_FILE}"
|
||||||
git checkout -b "$BRANCH_NAME"
|
git checkout -b "${BRANCH_NAME}"
|
||||||
git add "$IMAGES_FILE"
|
git add "${IMAGES_FILE}"
|
||||||
git commit -m "$(message)"
|
git commit -m "$(message)"
|
||||||
|
|
||||||
info "Pushing..."
|
info "Pushing..."
|
||||||
git push "https://$GITHUB_API_TOKEN:x-oauth-basic@github.com/$ORIGIN_SLUG.git" -f "$BRANCH_NAME" 2>/dev/null || fatal "Error pushing the updated stackbrew"
|
git push "https://${GITHUB_API_TOKEN}:x-oauth-basic@github.com/${ORIGIN_SLUG}.git" -f "${BRANCH_NAME}" 2>/dev/null || fatal "Error pushing the updated stackbrew"
|
||||||
|
|
||||||
cd - && rm -rf $gitpath
|
cd - && rm -rf $gitpath
|
||||||
|
|
||||||
|
@ -133,16 +133,16 @@ if updated; then
|
||||||
-s \
|
-s \
|
||||||
-X POST \
|
-X POST \
|
||||||
-d "$(pr_payload)" \
|
-d "$(pr_payload)" \
|
||||||
"https://api.github.com/repos/$UPSTREAM_SLUG/pulls")"
|
"https://api.github.com/repos/${UPSTREAM_SLUG}/pulls")"
|
||||||
|
|
||||||
url="$(echo "$pr_response_payload" | jq -r .html_url)"
|
url="$(echo "${pr_response_payload}" | jq -r .html_url)"
|
||||||
if [ "$url" != "null" ]; then
|
if [ "$url" != "null" ]; then
|
||||||
info "Pull request created at $url"
|
info "Pull request created at $url"
|
||||||
|
|
||||||
if [ ! -z "$PR_NUMBER" ]; then
|
if [ ! -z "${PR_NUMBER}" ]; then
|
||||||
comment_endpoint="https://api.github.com/repos/$DOCKER_SLUG/issues/$PR_NUMBER/comments"
|
comment_endpoint="https://api.github.com/repos/${DOCKER_SLUG}/issues/${PR_NUMBER}/comments"
|
||||||
else
|
else
|
||||||
comment_endpoint="https://api.github.com/repos/$DOCKER_SLUG/commits/$COMMIT_ID/comments"
|
comment_endpoint="https://api.github.com/repos/${DOCKER_SLUG}/commits/${COMMIT_ID}/comments"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Creating Commit Comment"
|
info "Creating Commit Comment"
|
||||||
|
@ -152,15 +152,15 @@ if updated; then
|
||||||
-d "$(comment_payload "$url")" \
|
-d "$(comment_payload "$url")" \
|
||||||
"$comment_endpoint")"
|
"$comment_endpoint")"
|
||||||
|
|
||||||
if [ "$(echo "$commit_response_payload" | jq .message)" != "null" ]; then
|
if [ "$(echo "${commit_response_payload}" | jq -r .message)" != "null" ]; then
|
||||||
fatal "Error linking the pull request ($error_message)"
|
fatal "Error linking the pull request (${error_message})"
|
||||||
else
|
else
|
||||||
comment_url="$(echo "$commit_response_payload" | jq -r .html_url)"
|
comment_url="$(echo "${commit_response_payload}" | jq -r .html_url)"
|
||||||
info "Created comment at $comment_url"
|
info "Created comment at ${comment_url}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
error_message=$(echo "$pr_response_payload" | jq .message)
|
error_message=$(echo "${pr_response_payload}" | jq -r .message)
|
||||||
fatal "Error creating pull request ($error_message)"
|
fatal "Error creating pull request (${error_message})"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
info "No change!"
|
info "No change!"
|
||||||
|
|
|
@ -25,23 +25,23 @@ function build() {
|
||||||
tag="$1"
|
tag="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ -z "$variant" ]; then
|
if [ -z "${variant}" ]; then
|
||||||
full_tag="$tag"
|
full_tag="${tag}"
|
||||||
path="$version/$variant"
|
path="${version}/${variant}"
|
||||||
else
|
else
|
||||||
full_tag="$tag-$variant"
|
full_tag="${tag}-${variant}"
|
||||||
path="$version/$variant"
|
path="${version}/${variant}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Building $full_tag..."
|
info "Building ${full_tag}..."
|
||||||
|
|
||||||
if ! docker build --cpuset-cpus="0,1" -t node:"$full_tag" "$path"; then
|
if ! docker build --cpuset-cpus="0,1" -t node:"${full_tag}" "${path}"; then
|
||||||
fatal "Build of $full_tag failed!"
|
fatal "Build of ${full_tag} failed!"
|
||||||
fi
|
fi
|
||||||
info "Build of $full_tag succeeded."
|
info "Build of ${full_tag} succeeded."
|
||||||
|
|
||||||
info "Testing $full_tag"
|
info "Testing ${full_tag}"
|
||||||
docker run --rm -v "$PWD/test-image.sh:/usr/local/bin/test.sh" node:"$full_tag" test.sh "$full_version"
|
docker run --rm -v "$PWD/test-image.sh:/usr/local/bin/test.sh" node:"${full_tag}" test.sh "${full_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
cd "$(cd "${0%/*}" && pwd -P)" || exit
|
cd "$(cd "${0%/*}" && pwd -P)" || exit
|
||||||
|
@ -53,25 +53,25 @@ fi
|
||||||
|
|
||||||
for version in "${versions[@]}"; do
|
for version in "${versions[@]}"; do
|
||||||
# Skip "docs" and other non-docker directories
|
# Skip "docs" and other non-docker directories
|
||||||
[ -f "$version/Dockerfile" ] || continue
|
[ -f "${version}/Dockerfile" ] || continue
|
||||||
|
|
||||||
tag=$(get_tag "$version")
|
tag=$(get_tag "${version}")
|
||||||
full_version=$(get_full_version "$version")
|
full_version=$(get_full_version "${version}")
|
||||||
|
|
||||||
# Get supported variants according to the target architecture.
|
# Get supported variants according to the target architecture.
|
||||||
# See details in function.sh
|
# See details in function.sh
|
||||||
IFS=' ' read -ra variants <<<"$(get_variants "$(dirname "$version")" "${variant_arg[@]}")"
|
IFS=' ' read -ra variants <<<"$(get_variants "$(dirname "${version}")" "${variant_arg[@]}")"
|
||||||
|
|
||||||
# Only build the default Dockerfile if "default" is in the variant list
|
# Only build the default Dockerfile if "default" is in the variant list
|
||||||
if [[ "${variants[*]}" =~ "default" ]] || [[ "${variants[*]}" =~ "onbuild" ]]; then
|
if [[ "${variants[*]}" =~ "default" ]] || [[ "${variants[*]}" =~ "onbuild" ]]; then
|
||||||
build "$version" "" "$tag"
|
build "${version}" "" "${tag}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for variant in "${variants[@]}"; do
|
for variant in "${variants[@]}"; do
|
||||||
# Skip non-docker directories
|
# Skip non-docker directories
|
||||||
[ -f "$version/$variant/Dockerfile" ] || continue
|
[ -f "${version}/${variant}/Dockerfile" ] || continue
|
||||||
|
|
||||||
build "$version" "$variant" "$tag"
|
build "${version}" "${variant}" "${tag}"
|
||||||
done
|
done
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
|
@ -29,7 +29,7 @@ function update_node_version() {
|
||||||
local dockerfile=$1
|
local dockerfile=$1
|
||||||
shift
|
shift
|
||||||
local variant
|
local variant
|
||||||
if [[ $# -eq 1 ]]; then
|
if [ $# -eq 1 ]; then
|
||||||
variant=$1
|
variant=$1
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
@ -38,7 +38,7 @@ function update_node_version() {
|
||||||
(
|
(
|
||||||
cp "$template" "$dockerfile"
|
cp "$template" "$dockerfile"
|
||||||
local fromprefix=""
|
local fromprefix=""
|
||||||
if [[ "$arch" != "amd64" && "$variant" != "onbuild" ]]; then
|
if [ "$arch" != "amd64" ] && [ "$variant" != "onbuild" ]; then
|
||||||
fromprefix="$arch\\/"
|
fromprefix="$arch\\/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -59,10 +59,10 @@ function update_node_version() {
|
||||||
sed -E -i.bak "/$pattern/d" "$dockerfile" && rm "$dockerfile".bak
|
sed -E -i.bak "/$pattern/d" "$dockerfile" && rm "$dockerfile".bak
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "${version/.*/}" -ge 10 ]]; then
|
if [ "${version/.*/}" -ge 10 ]; then
|
||||||
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.7/' "$dockerfile"
|
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.7/' "$dockerfile"
|
||||||
rm "$dockerfile.bak"
|
rm "$dockerfile.bak"
|
||||||
elif [[ "${version/.*/}" -ge 8 || "$arch" == "ppc64le" || "$arch" == "s390x" || "$arch" == "arm64" || "$arch" == "arm32v7" ]]; then
|
elif [ "${version/.*/}" -ge 8 ] || [ "$arch" = "ppc64le" ] || [ "$arch" = "s390x" ] || [ "$arch" == "arm64" ] || [ "$arch" == "arm32v7" ]; then
|
||||||
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.6/' "$dockerfile"
|
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.6/' "$dockerfile"
|
||||||
rm "$dockerfile.bak"
|
rm "$dockerfile.bak"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue