Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change order of initialization, fixes #1059 #1062

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 60 additions & 60 deletions charts/nexus3/scripts/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,66 @@ if [[ -f "${json_file}" ]]; then
echo "Realms configured."
fi

echo "Configuring blob stores..."
for json_file in "${CONFIG_DIR}"/conf/*-blobstore.json; do
if [[ -f "${json_file}" ]]; then
type="$(jq -r '.type' "${json_file}")"
name="$(jq -r '.name' "${json_file}")"

status_code=$(curl -sS -o /dev/null -w "%{http_code}" -X GET -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" "${NEXUS_HOST}/service/rest/v1/blobstores/${type}/${name}")
if [[ "${status_code}" -eq 200 ]]; then
status_code="$(curl -sS -o /dev/null -w "%{http_code}" -X PUT -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" -d "@${json_file}" "${NEXUS_HOST}/service/rest/v1/blobstores/${type}/${name}")"
if [[ "${status_code}" -ne 204 ]]; then
error "Could not update blob store '${name}'."
fi
else
status_code="$(curl -sS -o /dev/null -w "%{http_code}" -X POST -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" -d "@${json_file}" "${NEXUS_HOST}/service/rest/v1/blobstores/${type}")"
if [[ "${status_code}" -ne 204 ]] && [[ "${status_code}" -ne 201 ]]; then
error "Could not create blob store '${name}'."
fi
fi

echo "Blob store '${name}' configured."
fi
done

echo "Configuring repositories..."
for json_file in "${CONFIG_DIR}"/conf/*-repo.json; do
if [[ -f "${json_file}" ]]; then
name="$(jq -r '.name' "${json_file}")"
format="$(jq -r '.format' "${json_file}")"
type="$(jq -r '.type' "${json_file}")"

tmp_file="$(mktemp -p "${tmp_dir}")"
jq -r 'del(.format,.type)' "${json_file}" >"${tmp_file}"
json_file="${tmp_file}"

if [[ "${type}" == "proxy" ]]; then
password_file="${CONFIG_DIR}/secret/repo-credentials/${name}"
if [[ -f "${password_file}" ]]; then
tmp_file="$(mktemp -p "${tmp_dir}")"
jq -r --arg password "$(cat "${password_file}")" '. * {httpClient: {authentication: {password: $password}}}' "${json_file}" >"${tmp_file}"
json_file="${tmp_file}"
fi
fi

status_code=$(curl -sS -o /dev/null -w "%{http_code}" -X GET -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" "${NEXUS_HOST}/service/rest/v1/repositories/${format}/${type}/${name}")
if [[ "${status_code}" -eq 200 ]]; then
status_code="$(curl -sS -o /dev/null -w "%{http_code}" -X PUT -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" -d "@${json_file}" "${NEXUS_HOST}/service/rest/v1/repositories/${format}/${type}/${name}")"
if [[ "${status_code}" -ne 204 ]]; then
error "Could not update repository '${name}'."
fi
else
status_code="$(curl -sS -o /dev/null -w "%{http_code}" -X POST -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" -d "@${json_file}" "${NEXUS_HOST}/service/rest/v1/repositories/${format}/${type}")"
if [[ "${status_code}" -ne 201 ]]; then
error "Could not create repository '${name}'."
fi
fi

echo "Repository '${name}' configured."
fi
done

echo "Configuring roles..."
for json_file in "${CONFIG_DIR}"/conf/*-role.json; do
if [[ -f "${json_file}" ]]; then
Expand Down Expand Up @@ -137,29 +197,6 @@ if [[ -f "${json_file}" ]]; then
echo "LDAP '${name}' configured."
fi

echo "Configuring blob stores..."
for json_file in "${CONFIG_DIR}"/conf/*-blobstore.json; do
if [[ -f "${json_file}" ]]; then
type="$(jq -r '.type' "${json_file}")"
name="$(jq -r '.name' "${json_file}")"

status_code=$(curl -sS -o /dev/null -w "%{http_code}" -X GET -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" "${NEXUS_HOST}/service/rest/v1/blobstores/${type}/${name}")
if [[ "${status_code}" -eq 200 ]]; then
status_code="$(curl -sS -o /dev/null -w "%{http_code}" -X PUT -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" -d "@${json_file}" "${NEXUS_HOST}/service/rest/v1/blobstores/${type}/${name}")"
if [[ "${status_code}" -ne 204 ]]; then
error "Could not update blob store '${name}'."
fi
else
status_code="$(curl -sS -o /dev/null -w "%{http_code}" -X POST -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" -d "@${json_file}" "${NEXUS_HOST}/service/rest/v1/blobstores/${type}")"
if [[ "${status_code}" -ne 204 ]] && [[ "${status_code}" -ne 201 ]]; then
error "Could not create blob store '${name}'."
fi
fi

echo "Blob store '${name}' configured."
fi
done

echo "Configuring scripts..."
for script_file in /scripts/*.groovy; do
if [[ -f "${script_file}" ]]; then
Expand Down Expand Up @@ -200,43 +237,6 @@ for json_file in "${CONFIG_DIR}"/conf/*-cleanup.json; do
fi
done

echo "Configuring repositories..."
for json_file in "${CONFIG_DIR}"/conf/*-repo.json; do
if [[ -f "${json_file}" ]]; then
name="$(jq -r '.name' "${json_file}")"
format="$(jq -r '.format' "${json_file}")"
type="$(jq -r '.type' "${json_file}")"

tmp_file="$(mktemp -p "${tmp_dir}")"
jq -r 'del(.format,.type)' "${json_file}" >"${tmp_file}"
json_file="${tmp_file}"

if [[ "${type}" == "proxy" ]]; then
password_file="${CONFIG_DIR}/secret/repo-credentials/${name}"
if [[ -f "${password_file}" ]]; then
tmp_file="$(mktemp -p "${tmp_dir}")"
jq -r --arg password "$(cat "${password_file}")" '. * {httpClient: {authentication: {password: $password}}}' "${json_file}" >"${tmp_file}"
json_file="${tmp_file}"
fi
fi

status_code=$(curl -sS -o /dev/null -w "%{http_code}" -X GET -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" "${NEXUS_HOST}/service/rest/v1/repositories/${format}/${type}/${name}")
if [[ "${status_code}" -eq 200 ]]; then
status_code="$(curl -sS -o /dev/null -w "%{http_code}" -X PUT -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" -d "@${json_file}" "${NEXUS_HOST}/service/rest/v1/repositories/${format}/${type}/${name}")"
if [[ "${status_code}" -ne 204 ]]; then
error "Could not update repository '${name}'."
fi
else
status_code="$(curl -sS -o /dev/null -w "%{http_code}" -X POST -H 'Content-Type: application/json' -u "${NEXUS_USER}:${password}" -d "@${json_file}" "${NEXUS_HOST}/service/rest/v1/repositories/${format}/${type}")"
if [[ "${status_code}" -ne 201 ]]; then
error "Could not create repository '${name}'."
fi
fi

echo "Repository '${name}' configured."
fi
done

echo "Configuring tasks..."
for json_file in "${CONFIG_DIR}"/conf/*-task.json; do
if [[ -f "${json_file}" ]]; then
Expand Down