Skip to content

Commit

Permalink
Prepare for multiple registries.
Browse files Browse the repository at this point in the history
  • Loading branch information
kportertx committed Nov 9, 2023
1 parent 3f9b371 commit 7a7c2a4
Show file tree
Hide file tree
Showing 72 changed files with 132 additions and 89 deletions.
47 changes: 22 additions & 25 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ EOF
}

function parse_args() {
g_registry='dockerhub'
g_dry_run='false'
g_push_build='false'
g_test_build='false'
Expand Down Expand Up @@ -145,9 +146,8 @@ function do_bake_test_group_targets() {
}

function do_bake_group() {
local version_path=$1
local group=$2
local group_targets=$3
local group=$1
local group_targets=$2

local output="#------------------------------------ ${group} -----------------------------------\n\n"

Expand All @@ -160,7 +160,8 @@ function do_bake_group() {

function get_product_tags() {
local product=$1
local distro=$2
local version=$2
local distro=$3

if [ -z "${distro}" ]; then
local distro_prefix=
Expand All @@ -171,32 +172,29 @@ function get_product_tags() {
local output="\"${product}:${g_server_version}${distro_prefix}\""

output+=", \"${product}:${g_server_version}${distro_prefix}-${g_container_release}\""

local short_version="${version_path#*/}"

output+=", \"${product}:${short_version}${distro_prefix}\""
output+=", \"${product}:${version}${distro_prefix}\""

echo "${output}"
}

function do_bake_test_target() {
local version_path=$1
local version=$1
local distro=$2
local edition=$3

local short_version="${version_path#*/}"
local version_path="${g_images_dir}/${g_registry}/${version}"
local output=""

for platform in "${c_platforms[@]}"; do
local short_platform="${platform#*/}"
local target_str=
target_str="$(get_target_name "${short_version}" "${distro}" \
target_str="$(get_target_name "${version}" "${distro}" \
"${edition}" "${short_platform}")"
local product="aerospike/aerospike-server-${edition}-${short_platform}"

output+="target \"${target_str}\" {\n"
output+=" tags=["
output+="$(get_product_tags "${product}" "${distro}")"
output+="$(get_product_tags "${product}" "${version}" "${distro}")"
output+="]\n"
output+=" platforms=[\"${platform}\"]\n"
output+=" context=\"./${version_path}/${edition}/${distro}\"\n"
Expand All @@ -207,7 +205,7 @@ function do_bake_test_target() {
}

function do_bake_push_target() {
local version_path=$1
local version=$1
local distro=$2
local edition=$3

Expand All @@ -222,10 +220,12 @@ function do_bake_push_target() {
product+="-${edition}"
fi

local version_path="${g_images_dir}/${g_registry}/${version}"

output+=" tags=["

if [ "${distro}" == "${c_distro_default}" ]; then
output+="$(get_product_tags "${product}" "")"
output+="$(get_product_tags "${product}" "${version}" "")"

if [ "${g_latest_version}" = "${g_server_version}" ]; then
output+=", \"${product}:latest\""
Expand All @@ -234,7 +234,7 @@ function do_bake_push_target() {
output+=",\n "
fi

output+="$(get_product_tags "${product}" "${distro}")"
output+="$(get_product_tags "${product}" "${version}" "${distro}")"

output+="]\n"
output+=" platforms=[\"${platforms_str}\"]\n"
Expand All @@ -253,34 +253,31 @@ function build_bake_file() {
local group_test_targets=""
local group_push_targets=""

for version_path in "${g_images_dir}"/*; do
local version=
version="$(basename "${version_path}")"

for version in $(support_versions "${g_registry}"); do
if support_config_filter "${version}" "${g_filter_versions[@]}"; then
continue
fi

# HACK - artifacts for server need first 3 digits.
g_server_version=$(find_latest_server_version_for_lineage "${version}.0")

support_source_config "${version_path}" ""
support_source_config "${g_registry}" "${version}" ""

for edition in "${c_editions[@]}"; do
if support_config_filter "${edition}" "${g_filter_editions[@]}"; then
continue
fi

support_source_config "${version_path}" "${edition}"
support_source_config "${g_registry}" "${version}" "${edition}"

for distro in "${c_distros[@]}"; do
if support_config_filter "${distro}" "${g_filter_distros[@]}"; then
continue
fi

test_targets_str+="$(do_bake_test_target "${version_path}" \
test_targets_str+="$(do_bake_test_target "${version}" \
"${distro}" "${edition}")"
push_targets_str+="$(do_bake_push_target "${version_path}" \
push_targets_str+="$(do_bake_push_target "${version}" \
"${distro}" "${edition}")"
group_test_targets+="$(do_bake_test_group_targets "${distro}" \
"${edition}" "${version}")"
Expand All @@ -299,9 +296,9 @@ function build_bake_file() {
group_push_targets=${group_push_targets%",\n "}

local test_group_str
test_group_str="$(do_bake_group "${version_path}" "test" "${group_test_targets}")"
test_group_str="$(do_bake_group "test" "${group_test_targets}")"
local push_group_str
push_group_str="$(do_bake_group "${version_path}" "push" "${group_push_targets}")"
push_group_str="$(do_bake_group "push" "${group_push_targets}")"

mkdir -p "${g_target_dir}"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
73 changes: 64 additions & 9 deletions lib/support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,75 @@ function support_platform_to_arch() {
}

function support_source_config() {
local version_path=$1
local edition=$2
local registry=$1
local version=$2
local edition=$3

local version=
version="$(basename "${version_path}")"
local config_dir="${g_data_config_dir}/${version}"
# Apply registry config.
local registry_config_dir="${g_data_config_dir}/${registry}"
local registry_config="${registry_config_dir}/config.sh"

# shellcheck source=data/config/6.4/config.sh
source "${config_dir}/config.sh"
if [ -f "${registry_config}" ]; then
# shellcheck source=data/config/dockerhub/config.sh
source "${registry_config}"
fi

# Apply version config (required).
local version_config_dir="${registry_config_dir}/${version}"

# shellcheck source=data/config/dockerhub/6.4/config.sh
source "${version_config_dir}/config.sh"

if [ -z "${edition}" ]; then
return
fi

local edition_config="${config_dir}/config_${edition}.sh"
# Apply edition config (required).
local edition_config="${version_config_dir}/${edition}/config.sh"

if [ -f "${edition_config}" ]; then
# shellcheck source=data/config/6.4/config_federal.sh
# shellcheck source=data/config/dockerhub/6.4/federal/config.sh
source "${edition_config}"
fi
}

function _dir_dirs() {
local search_dir=$1

while IFS= read -r -d '' dir; do
local found_dir=
found_dir=$(basename "${dir}")
echo "${found_dir}"
done < <(find "${search_dir}" -mindepth 1 -maxdepth 1 -type d -print0)
}

function support_registries() {
_dir_dirs "${g_data_config_dir}" | sort
}

function support_versions() {
local registry=$1

_dir_dirs "${g_data_config_dir}/${registry}" | sort
}

function support_editions() {
local registry=$1
local version=$2

_dir_dirs "${g_data_config_dir}/${registry}/${version}" | sort
}

function support_configs() {
local prev
local leaf_config_path

while IFS= read -r -d '' leaf_config_path; do
if [[ ${prev} =~ ${leaf_config_path} ]]; then
continue
fi

prev="${leaf_config_path}"
echo "${leaf_config_path}"
done < <(find "${g_data_config_dir}" -depth -type d -print0)
}
11 changes: 7 additions & 4 deletions lib/version.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# shellcheck shell=bash

source lib/fetch.sh
source lib/globals.sh

ARTIFACTS_DOMAIN=${ARTIFACTS_DOMAIN:="https://artifacts.aerospike.com"}
RE_VERSION='[0-9]+[.][0-9]+[.][0-9]+([.][0-9]+)+(-rc[0-9]+)*'
Expand Down Expand Up @@ -125,9 +126,11 @@ function fetch_package_sha() {
}

function get_version_from_dockerfile() {
local version_path=$1
local distro=$2
local edition=$3
local registry=$1
local version=$2
local distro=$3
local edition=$4

grep "ARG AEROSPIKE_X86_64_LINK=" "${version_path}/${edition}/${distro}/Dockerfile" | grep -oE "/[0-9.]+(-rc[0-9]+)?/" | tr -d '/'
grep "ARG AEROSPIKE_X86_64_LINK=" "${g_images_dir}/${registry}/${version}/${edition}/${distro}/Dockerfile" \
| grep -oE "/[0-9.]+(-rc[0-9]+)?/" | tr -d '/'
}
40 changes: 19 additions & 21 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ EOF
}

function parse_args() {
g_registry='dockerhub'
g_clean="false"

while getopts "ch" opt; do
Expand All @@ -45,19 +46,19 @@ function parse_args() {
}

function run_docker() {
local version=$1
local version_short=$1
local edition=$2
local platform=$3
local container=$4
local image_tag=$5

log_info "running docker image '${image_tag}'"

if [ "${edition}" = "community" ] || version_compare_gt "${version}" "6.1"; then
if [ "${edition}" = "community" ] || version_compare_gt "${version_short}" "6.1"; then
verbose_call docker run -td --name "${container}" \
"${platform/#/"--platform="}" "${image_tag}"
else
# Must supply a feature key when version is prior to 6.1.
# Must supply a feature key when version_short is prior to 6.1.
verbose_call docker run -td --name "${container}" \
"${platform/#/"--platform="}" -v "$(pwd)/${g_data_res_dir}/":/asfeat/ \
-e "FEATURE_KEY_FILE=/asfeat/eval_features.conf" "${image_tag}"
Expand All @@ -83,12 +84,12 @@ function try() {
}

function check_container() {
local version=$1
local version_short=$1
local edition=$2
local platform=$3
local container=$4

log_info "verifying container '${container}' version '${version}' platform '${platform}' ..."
log_info "verifying container '${container}' version_short '${version_short}' platform '${platform}' ..."

if [ "$(docker container inspect -f '{{.State.Status}}' "${container}")" == "running" ]; then
log_success "Container '${container}' started and running"
Expand Down Expand Up @@ -123,12 +124,12 @@ function check_container() {
fi

build=$(try 5 docker exec -t "${container}" bash -c \
'asadm -e "enable; asinfo -v build"' | grep -oE "^${version}")
'asadm -e "enable; asinfo -v build"' | grep -oE "^${version_short}")

if [ -n "${build}" ]; then
log_success "(asadm) Aerospike database has correct version - '${build}'"
log_success "(asadm) Aerospike database has correct version_short - '${build}'"
else
log_failure "**(asadm) Aerospike database has incorrect version - '${build}'**"
log_failure "**(asadm) Aerospike database has incorrect version_short - '${build}'**"
exit 1
fi

Expand All @@ -142,7 +143,7 @@ function check_container() {
exit 1
fi

if version_compare_gt "${version}" "6.2"; then
if version_compare_gt "${version_short}" "6.2"; then
tool="asinfo"
namespace=$(try 5 docker exec -t "${container}" bash -c \
'asinfo -v namespaces' | grep -o "test")
Expand Down Expand Up @@ -192,30 +193,27 @@ function clean_docker() {
function main() {
parse_args "$@"

for version_path in images/*; do
local short_version=
short_version="$(basename "${version_path}")"

support_source_config "${version_path}" ""
for version_short in $(support_versions "${g_registry}"); do
support_source_config "${g_registry}" "${version_short}" ""

for edition in "${c_editions[@]}"; do
local container="aerospike-server-${edition}"
local edition_config="${version_path}/config_${edition}.sh"

support_source_config "${version_path}" "${edition}"
support_source_config "${g_registry}" "${version_short}" "${edition}"

for distro in "${c_distros[@]}"; do
local version
version="$(get_version_from_dockerfile "${version_path}" "${distro}" "${edition}")"
local version_full
version_full="$(get_version_from_dockerfile "${g_registry}" \
"${version_short}" "${distro}" "${edition}")"

for platform in "${c_platforms[@]}"; do
local short_platform=
short_platform="$(basename "${platform}")"
local image_tag="aerospike/aerospike-server-${edition}-${short_platform}:${short_version}-${distro}"
local image_tag="aerospike/aerospike-server-${edition}-${short_platform}:${version_full}-${distro}"

try_stop_docker "${container}"
run_docker "${version}" "${edition}" "${platform}" "${container}" "${image_tag}"
check_container "${version}" "${edition}" "${platform}" "${container}" "${image_tag}"
run_docker "${version_full}" "${edition}" "${platform}" "${container}" "${image_tag}"
check_container "${version_full}" "${edition}" "${platform}" "${container}" "${image_tag}"
clean_docker "${container}" "${image_tag}"
done
done
Expand Down
Loading

0 comments on commit 7a7c2a4

Please sign in to comment.