forked from mtusi2026/mtusi2026lab4
Реализована лабораторная 4: MinIO и вложения
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
FROM alpine:3.21.3@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c
|
||||
|
||||
ARG MINIO_RELEASE=RELEASE.2025-02-07T23-21-09Z
|
||||
ARG MINIO_SHA256=5a1b5bc661f0b8fd55eee530ea472205e77624718e31f7b4402bc269299501d5
|
||||
|
||||
RUN apk add --no-cache ca-certificates curl \
|
||||
&& curl --fail --location --silent --show-error \
|
||||
"https://github.com/minio/minio/releases/download/${MINIO_RELEASE}/minio.linux-amd64.${MINIO_RELEASE}" \
|
||||
--output /usr/local/bin/minio \
|
||||
&& echo "${MINIO_SHA256} /usr/local/bin/minio" | sha256sum -c - \
|
||||
&& chmod 0755 /usr/local/bin/minio \
|
||||
&& apk del curl
|
||||
|
||||
EXPOSE 9000 9001
|
||||
ENTRYPOINT ["/usr/local/bin/minio"]
|
||||
CMD ["server", "/data", "--console-address", ":9001"]
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Idempotently create the private MinIO bucket before starting the API."""
|
||||
import os
|
||||
import time
|
||||
|
||||
import boto3
|
||||
from botocore.config import Config
|
||||
from botocore.exceptions import BotoCoreError, ClientError
|
||||
|
||||
|
||||
def main():
|
||||
endpoint = os.environ.get("S3_ENDPOINT", "").strip()
|
||||
region = os.environ.get("S3_REGION", "us-east-1").strip()
|
||||
bucket = os.environ.get("S3_BUCKET", "").strip()
|
||||
access_key = os.environ.get("MINIO_ROOT_USER", "").strip()
|
||||
secret_key = os.environ.get("MINIO_ROOT_PASSWORD", "")
|
||||
if not all((endpoint, region, bucket, access_key, secret_key)):
|
||||
raise SystemExit("S3 bootstrap configuration is incomplete")
|
||||
|
||||
client = boto3.client(
|
||||
"s3",
|
||||
endpoint_url=endpoint,
|
||||
region_name=region,
|
||||
aws_access_key_id=access_key,
|
||||
aws_secret_access_key=secret_key,
|
||||
config=Config(
|
||||
signature_version="s3v4",
|
||||
s3={"addressing_style": "path"},
|
||||
connect_timeout=3,
|
||||
read_timeout=5,
|
||||
retries={"max_attempts": 1, "mode": "standard"},
|
||||
),
|
||||
)
|
||||
for attempt in range(30):
|
||||
try:
|
||||
client.head_bucket(Bucket=bucket)
|
||||
print("S3 bucket is ready")
|
||||
return
|
||||
except ClientError as error:
|
||||
code = error.response.get("Error", {}).get("Code", "")
|
||||
if code not in ("404", "NoSuchBucket", "NotFound"):
|
||||
raise SystemExit("S3 bucket bootstrap failed") from None
|
||||
try:
|
||||
client.create_bucket(Bucket=bucket)
|
||||
print("S3 bucket created and ready")
|
||||
return
|
||||
except ClientError as create_error:
|
||||
create_code = create_error.response.get("Error", {}).get("Code", "")
|
||||
if create_code not in ("BucketAlreadyExists", "BucketAlreadyOwnedByYou"):
|
||||
raise SystemExit("S3 bucket bootstrap failed") from None
|
||||
except BotoCoreError:
|
||||
if attempt == 29:
|
||||
raise SystemExit("S3 endpoint did not become available") from None
|
||||
time.sleep(2)
|
||||
raise SystemExit("S3 bucket bootstrap timed out")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user