Skip to content

Instantly share code, notes, and snippets.

@030
Last active Nov 29, 2021
Embed
What would you like to do?
#!/bin/bash -e
NEXUS_VERSION="${1:-3.21.1}"
NEXUS_API_VERSION="${2:-v1}"
NEXUS_DOCKER_NAME="${3:-nexus}"
NEXUS_DOCKER_PORT="${4:-9999}"
NEXUS_PW_ON_DISK="${5:-/tmp/nexus-tst-pass}"
validate() {
if [ -z "${NEXUS_VERSION}" ] || [ -z "${NEXUS_API_VERSION}" ]; then
echo "NEXUS_VERSION and NEXUS_API_VERSION should be specified."
exit 1
fi
}
nexus() {
docker run --rm -d -p ${NEXUS_DOCKER_PORT}:8081 --name ${NEXUS_DOCKER_NAME} "sonatype/nexus3:${NEXUS_VERSION}"
}
readiness() {
until docker logs ${NEXUS_DOCKER_NAME} | grep -q 'Started Sonatype Nexus OSS'; do
sleep 3
done
}
# Since nexus 3.17.0 the default 'admin123' was changed by an autogenerated
# one. This function retrieves the autogenerated password and if this file
# is unavailable, the default 'admin123' is returned.
password() {
mkdir -p "${NEXUS_PW_ON_DISK}"
pw=$(docker exec -i ${NEXUS_DOCKER_NAME} cat /nexus-data/admin.password || true)
if [[ "${pw}" =~ [0-9a-z-]{36} ]]; then
echo "admin.password file found"
else
echo "no admin.password file found. Setting password to old default admin pass..."
pw=admin123
fi
export PASSWORD=$pw
echo "${pw}" >${NEXUS_PW_ON_DISK}/${NEXUS_DOCKER_NAME}.txt
}
cleanup() {
docker stop ${NEXUS_DOCKER_NAME}
}
main() {
validate
nexus
readiness
password
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment