Skip to content

Commit

Permalink
Merge pull request #23 from canonical/update-deploy-minio
Browse files Browse the repository at this point in the history
Update deploy minio
  • Loading branch information
PietroPasotti authored Aug 21, 2024
2 parents ddf39d1 + 044a46e commit e0de0f8
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions scripts/deploy_minio.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,33 @@ def get_minio_status(status):
def _run(cmd: str):
return subprocess.check_call(shlex.split(cmd))


def _check_juju_status(status, name):
return status and (status['juju-status']['current'] == name)


def _check_workload_status(status, name):
return status and (status['workload-status']['current'] == name)


def deploy(bucket_name: str,
def deploy(s3_app_name: str,
minio_app_name: str,
user: str,
password: str,
bucket_name: str,
model: str = None):
"""Deploy minio and s3 integrator."""

if model:
_run(f"juju switch {model}")

_run(f"juju deploy minio --channel edge --trust --config access-key=accesskey --config secret-key=secretkey")
_run("juju deploy s3-integrator --channel edge --trust s3")
print("deploying minio and s3 integrator...")

print("waiting for minio to become active...", end='')
_run(
f"juju deploy minio --channel edge --trust --config access-key={user} --config secret-key={password} {minio_app_name}")
_run(f"juju deploy s3-integrator --channel edge --trust {s3_app_name}")

print(f"waiting for minio ({minio_app_name}) to become active...", end='')
while True:
status = get_status()
minio = get_minio_status(status)
Expand All @@ -75,24 +86,34 @@ def deploy(bucket_name: str,

mc_client = Minio(
f"{minio_addr}:9000",
access_key="accesskey",
secret_key="secretkey",
access_key=user,
secret_key=password,
secure=False,
)

# create tempo bucket
found = mc_client.bucket_exists(bucket_name)
if not found:
if found:
print(f"bucket {bucket_name} already exists!")
else:
print("making bucket...")
mc_client.make_bucket(bucket_name)

print("syncing s3 credentials...")
# configure s3-integrator
model_name = get_model_name(status)
_run(f"juju config s3 endpoint=minio-0.minio-endpoints.{model_name}.svc.cluster.local:9000 bucket={bucket_name}")
_run(f"juju run s3/0 sync-s3-credentials access-key=accesskey secret-key=secretkey")
_run(
f"juju config {s3_app_name} endpoint={minio_app_name}-0.minio-endpoints.{model_name}.svc.cluster.local:9000 bucket={bucket_name}")
_run(f"juju run {s3_app_name}/leader sync-s3-credentials access-key={user} secret-key={password}")

print("all done! have fun.")


if __name__ == '__main__':
deploy(
bucket_name=os.getenv("MINIO_ENDPOINT", "tempo"),
s3_app_name=os.getenv("MINIO_S3_APP", "s3"),
minio_app_name=os.getenv("MINIO_APP", "minio"),
user=os.getenv("MINIO_USER", "accesskey"),
password=os.getenv("MINIO_PASSWORD", "secretkey"),
bucket_name=os.getenv("MINIO_BUCKET", "tempo"),
model=os.getenv("MINIO_MODEL", None),
)

0 comments on commit e0de0f8

Please sign in to comment.