58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
"""Construye y publica el Bot Digitador en el prefijo latest de MinIO."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import boto3
|
|
from botocore.config import Config
|
|
|
|
from package_bot import DEFAULT_OUTPUT, build_package, sha256
|
|
|
|
|
|
DEFAULT_ENDPOINT = "https://s3.builker.xyz"
|
|
DEFAULT_BUCKET = "apps-versions"
|
|
DEFAULT_KEY = "BotDigitadorPYSCuentasMedicas/latest/bot_digitador.zip"
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--output", type=Path, default=DEFAULT_OUTPUT)
|
|
parser.add_argument("--build-only", action="store_true")
|
|
args = parser.parse_args()
|
|
artifact = build_package(output=args.output.resolve(), require_templates=True)
|
|
print(f"Paquete validado: {artifact} ({sha256(artifact)})")
|
|
if args.build_only:
|
|
return 0
|
|
|
|
access = os.getenv("MINIO_ACCESS_KEY") or os.getenv("AWS_ACCESS_KEY_ID")
|
|
secret = os.getenv("MINIO_SECRET_KEY") or os.getenv("AWS_SECRET_ACCESS_KEY")
|
|
if not access or not secret:
|
|
print("Faltan MINIO_ACCESS_KEY/MINIO_SECRET_KEY para publicar.", file=sys.stderr)
|
|
return 2
|
|
endpoint = os.getenv("MINIO_ENDPOINT", DEFAULT_ENDPOINT).rstrip("/")
|
|
bucket = os.getenv("MINIO_APPS_BUCKET", DEFAULT_BUCKET)
|
|
key = os.getenv("DIGITADOR_PACKAGE_KEY", DEFAULT_KEY).strip("/")
|
|
client = boto3.client(
|
|
"s3",
|
|
endpoint_url=endpoint,
|
|
aws_access_key_id=access,
|
|
aws_secret_access_key=secret,
|
|
region_name=os.getenv("MINIO_REGION", "us-east-1"),
|
|
config=Config(s3={"addressing_style": "path"}),
|
|
)
|
|
client.upload_file(
|
|
str(artifact),
|
|
bucket,
|
|
key,
|
|
ExtraArgs={"ContentType": "application/zip"},
|
|
)
|
|
print(f"Publicado: {endpoint}/{bucket}/{key}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|