|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +set -eux |
| 21 | + |
| 22 | +MINIO_ROOT_USER="${MINIO_ROOT_USER:-minio}" |
| 23 | +MINIO_ROOT_PASSWORD="${MINIO_ROOT_PASSWORD:-minio123}" |
| 24 | +MINIO_IMAGE="${MINIO_IMAGE:-minio/minio:latest}" |
| 25 | +MINIO_CONTAINER_NAME="${MINIO_CONTAINER_NAME:-iceberg-minio}" |
| 26 | +MINIO_PORT="${MINIO_PORT:-9000}" |
| 27 | +MINIO_CONSOLE_PORT="${MINIO_CONSOLE_PORT:-9001}" |
| 28 | +MINIO_BUCKET="${MINIO_BUCKET:-iceberg-test}" |
| 29 | +MINIO_ENDPOINT="${MINIO_ENDPOINT:-http://127.0.0.1:${MINIO_PORT}}" |
| 30 | + |
| 31 | +wait_for_minio() { |
| 32 | + for i in {1..30}; do |
| 33 | + if curl -fsS "${MINIO_ENDPOINT}/minio/health/ready" >/dev/null; then |
| 34 | + return 0 |
| 35 | + fi |
| 36 | + sleep 1 |
| 37 | + done |
| 38 | + echo "MinIO did not become ready after 30 seconds." >&2 |
| 39 | + echo "Endpoint: ${MINIO_ENDPOINT}" >&2 |
| 40 | + if command -v docker >/dev/null 2>&1; then |
| 41 | + docker logs "${MINIO_CONTAINER_NAME}" 2>&1 || true |
| 42 | + fi |
| 43 | + return 1 |
| 44 | +} |
| 45 | + |
| 46 | +start_minio_docker() { |
| 47 | + if ! command -v docker >/dev/null 2>&1; then |
| 48 | + return 1 |
| 49 | + fi |
| 50 | + |
| 51 | + if docker ps -a --format '{{.Names}}' | grep -q "^${MINIO_CONTAINER_NAME}\$"; then |
| 52 | + docker rm -f "${MINIO_CONTAINER_NAME}" |
| 53 | + fi |
| 54 | + |
| 55 | + docker run -d --name "${MINIO_CONTAINER_NAME}" \ |
| 56 | + -p "${MINIO_PORT}:9000" -p "${MINIO_CONSOLE_PORT}:9001" \ |
| 57 | + -e "MINIO_ROOT_USER=${MINIO_ROOT_USER}" \ |
| 58 | + -e "MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}" \ |
| 59 | + "${MINIO_IMAGE}" \ |
| 60 | + server /data --console-address ":${MINIO_CONSOLE_PORT}" |
| 61 | + |
| 62 | + wait_for_minio |
| 63 | +} |
| 64 | + |
| 65 | +start_minio_macos() { |
| 66 | + if ! command -v brew >/dev/null 2>&1; then |
| 67 | + echo "brew is required to start MinIO on macOS without Docker" >&2 |
| 68 | + return 1 |
| 69 | + fi |
| 70 | + |
| 71 | + brew install minio |
| 72 | + MINIO_ROOT_USER="${MINIO_ROOT_USER}" MINIO_ROOT_PASSWORD="${MINIO_ROOT_PASSWORD}" \ |
| 73 | + minio server /tmp/minio --console-address ":${MINIO_CONSOLE_PORT}" & |
| 74 | + wait_for_minio |
| 75 | +} |
| 76 | + |
| 77 | +download_mc() { |
| 78 | + local uname_out |
| 79 | + uname_out="$(uname -s)" |
| 80 | + |
| 81 | + local mc_dir |
| 82 | + mc_dir="${RUNNER_TEMP:-/tmp}" |
| 83 | + mkdir -p "${mc_dir}" |
| 84 | + |
| 85 | + case "${uname_out}" in |
| 86 | + Linux*) |
| 87 | + MC_BIN="${mc_dir}/mc" |
| 88 | + curl -sSL "https://dl.min.io/client/mc/release/linux-amd64/mc" -o "${MC_BIN}" |
| 89 | + chmod +x "${MC_BIN}" |
| 90 | + ;; |
| 91 | + Darwin*) |
| 92 | + MC_BIN="${mc_dir}/mc" |
| 93 | + local arch |
| 94 | + arch="$(uname -m)" |
| 95 | + if [ "${arch}" = "arm64" ]; then |
| 96 | + curl -sSL "https://dl.min.io/client/mc/release/darwin-arm64/mc" -o "${MC_BIN}" |
| 97 | + else |
| 98 | + curl -sSL "https://dl.min.io/client/mc/release/darwin-amd64/mc" -o "${MC_BIN}" |
| 99 | + fi |
| 100 | + chmod +x "${MC_BIN}" |
| 101 | + ;; |
| 102 | + MINGW*|MSYS*|CYGWIN*) |
| 103 | + MC_BIN="${mc_dir}/mc.exe" |
| 104 | + curl -sSL "https://dl.min.io/client/mc/release/windows-amd64/mc.exe" -o "${MC_BIN}" |
| 105 | + ;; |
| 106 | + *) |
| 107 | + echo "Unsupported OS for mc: ${uname_out}" >&2 |
| 108 | + return 1 |
| 109 | + ;; |
| 110 | + esac |
| 111 | +} |
| 112 | + |
| 113 | +create_bucket() { |
| 114 | + download_mc |
| 115 | + for i in {1..30}; do |
| 116 | + if "${MC_BIN}" alias set local "${MINIO_ENDPOINT}" "${MINIO_ROOT_USER}" "${MINIO_ROOT_PASSWORD}"; then |
| 117 | + break |
| 118 | + fi |
| 119 | + sleep 1 |
| 120 | + done |
| 121 | + "${MC_BIN}" mb --ignore-existing "local/${MINIO_BUCKET}" |
| 122 | +} |
| 123 | + |
| 124 | +start_minio_windows() { |
| 125 | + local minio_dir="${RUNNER_TEMP:-/tmp}" |
| 126 | + local minio_bin="${minio_dir}/minio.exe" |
| 127 | + curl -sSL "https://dl.min.io/server/minio/release/windows-amd64/minio.exe" -o "${minio_bin}" |
| 128 | + MINIO_ROOT_USER="${MINIO_ROOT_USER}" MINIO_ROOT_PASSWORD="${MINIO_ROOT_PASSWORD}" \ |
| 129 | + "${minio_bin}" server "${minio_dir}/minio-data" --console-address ":${MINIO_CONSOLE_PORT}" & |
| 130 | + wait_for_minio |
| 131 | +} |
| 132 | + |
| 133 | +case "$(uname -s)" in |
| 134 | + Darwin*) |
| 135 | + if ! start_minio_docker; then |
| 136 | + start_minio_macos |
| 137 | + fi |
| 138 | + ;; |
| 139 | + MINGW*|MSYS*|CYGWIN*) |
| 140 | + if ! start_minio_docker; then |
| 141 | + start_minio_windows |
| 142 | + fi |
| 143 | + ;; |
| 144 | + Linux*) |
| 145 | + start_minio_docker |
| 146 | + ;; |
| 147 | + *) |
| 148 | + echo "Unsupported OS: $(uname -s)" >&2 |
| 149 | + exit 1 |
| 150 | + ;; |
| 151 | +esac |
| 152 | + |
| 153 | +create_bucket |
0 commit comments