Skip to content

Commit

Permalink
refs platform/#2978: improve bootup of the minio service
Browse files Browse the repository at this point in the history
  • Loading branch information
Monska85 committed Aug 6, 2024
1 parent a24bdfe commit 36d1c39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 14 additions & 14 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ minio_wait_for_readiness() {
CNT=0
TRESHOLD=10
while [ "${CNT}" -lt 10 ]; do
if [ -n "$(mc admin info 2>&1 || true)" ]; then
if mc config host add "${MC_HOST}" http://localhost:9000 "${MINIO_ROOT_USER}" "${MINIO_ROOT_PASSWORD}" &>/dev/null && mc admin info "${MC_HOST}" &>/dev/null; then
minio_note "Minio server is ready."
return 0
fi
Expand All @@ -30,14 +30,26 @@ minio_wait_for_readiness() {
minio_error "Minio server is not ready in ${TRESHOLD} seconds."
}

docker_create_bucket() {
# Check if bucket exists, otherwise create it.
if mc ls "minio/${BUCKET_NAME}" &>/dev/null; then
minio_note "Bucket '${BUCKET_NAME}' already exists."
else
minio_note "Creating bucket '${BUCKET_NAME}'."
mc config host add minio http://localhost:9000 "${MINIO_ROOT_USER}" "${MINIO_ROOT_PASSWORD}" | minio_note
mc mb -p "minio/${BUCKET_NAME}" | minio_note
mc anonymous set download "minio/${BUCKET_NAME}" | minio_note
fi
}

docker_process_init_files() {
if [ "$(mc ls "minio/${BUCKET_NAME}/" | wc -l)" -ne 0 ]; then
minio_note "Bucket '${BUCKET_NAME}' is not empty. Skipping initialization files."
return
fi

minio_note "Bucket '${BUCKET_NAME}' is empty. Processing initialization files."
if [ "$(ls "${INITFILES_FOLDER}" | wc -l)" -gt 0 ]; then
if [ "$(ls "${INITFILES_FOLDER}" 2>/dev/null | wc -l)" -gt 0 ]; then
minio_note "Uploading files to bucket '${BUCKET_NAME}'."
# Note the trailing slash in the source folder. This is required to copy the CONTENTS of the folder and not the folder itself.
mc cp --recursive "${INITFILES_FOLDER}/" "minio/${BUCKET_NAME}" 1>/dev/null 2>/tmp/minio_error.log
Expand All @@ -51,18 +63,6 @@ docker_process_init_files() {
minio_note "No files found in '${INITFILES_FOLDER}'. The bucket '${BUCKET_NAME}' will remain empty."
}

docker_create_bucket() {
# Check if bucket exists, otherwise create it.
if [ -z "$(mc ls "minio/${BUCKET_NAME}" 2>&1 || true)" ]; then
minio_note "Bucket '${BUCKET_NAME}' already exists."
else
minio_note "Creating bucket '${BUCKET_NAME}'."
mc config host add minio http://localhost:9000 "${MINIO_ROOT_USER}" "${MINIO_ROOT_PASSWORD}" | minio_note
mc mb -p "minio/${BUCKET_NAME}" | minio_note
mc anonymous set download "minio/${BUCKET_NAME}" | minio_note
fi
}

# Logging functions.
minio_log() {
local type="$1"
Expand Down
2 changes: 2 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export DO_NOT_PROCESS_INITFILES=${DO_NOT_PROCESS_INITFILES:-"0"}
export MINIO_BROWSER=${MINIO_BROWSER:-"off"}
export MINIO_CONSOLE_PORT=${MINIO_CONSOLE_PORT:-"9001"}
export MINIO_OPTS=${MINIO_OPTS:-""}
# Host to configure the local MinIO client.
export MC_HOST="${MC_HOST:-"minio"}"

# Backward compatibility for OSB_BUCKET.
# If `BUCKET_NAME` variable is not set, then `OSB_BUCKET` variable is used to set `BUCKET_NAME`.
Expand Down

0 comments on commit 36d1c39

Please sign in to comment.