From f14111ccdf9865dbb916b43a0e0289046359f5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Wed, 21 Oct 2026 12:45:26 +0300 Subject: [PATCH] chore(compose):lab4 add MinIO service with volume and healthcheck --- .env.example | 3 +++ backend/internal/config/config.go | 39 +++++++++++++++++++++++++++++-- compose.yaml | 37 +++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index d99d26a..112ef56 100644 --- a/.env.example +++ b/.env.example @@ -18,3 +18,6 @@ S3_ACCESS_KEY_ID_FILE=/run/secrets/s3_access_key_id S3_SECRET_ACCESS_KEY_FILE=/run/secrets/s3_secret_access_key MAX_UPLOAD_BYTES=10485760 MAX_IMAGE_PIXELS=40000000 +MINIO_ROOT_USER=... +MINIO_CPUS=0.5 +MINIO_MEMORY=512M \ No newline at end of file diff --git a/backend/internal/config/config.go b/backend/internal/config/config.go index 06d15db..d0cd0ee 100644 --- a/backend/internal/config/config.go +++ b/backend/internal/config/config.go @@ -24,6 +24,9 @@ type Config struct { S3Region string S3AccessKey string S3SecretKey string + + MaxUploadBytes int64 + MaxImagePixels int64 } func Load() (*Config, error) { @@ -76,15 +79,31 @@ func Load() (*Config, error) { } s3Region := getenv("S3_REGION", "us-east-1") - s3AccessKey, err := readSecretOptional("S3_ACCESS_KEY_FILE", "S3_ACCESS_KEY") + s3AccessKey, err := readSecretOptional("S3_ACCESS_KEY_ID_FILE", "S3_ACCESS_KEY_ID") if err != nil { return nil, fmt.Errorf("s3 access key: %w", err) } - s3SecretKey, err := readSecretOptional("S3_SECRET_KEY_FILE", "S3_SECRET_KEY") + s3SecretKey, err := readSecretOptional("S3_SECRET_ACCESS_KEY_FILE", "S3_SECRET_ACCESS_KEY") if err != nil { return nil, fmt.Errorf("s3 secret key: %w", err) } + maxUploadBytes, err := readInt64("MAX_UPLOAD_BYTES", 10485760) + if err != nil { + return nil, fmt.Errorf("MAX_UPLOAD_BYTES: %w", err) + } + if maxUploadBytes <= 0 { + return nil, fmt.Errorf("MAX_UPLOAD_BYTES должен быть положительным") + } + + maxImagePixels, err := readInt64("MAX_IMAGE_PIXELS", 40000000) + if err != nil { + return nil, fmt.Errorf("MAX_IMAGE_PIXELS: %w", err) + } + if maxImagePixels <= 0 { + return nil, fmt.Errorf("MAX_IMAGE_PIXELS должен быть положительным") + } + return &Config{ Host: getenv("APP_HOST", "0.0.0.0"), Port: getenv("APP_PORT", "8080"), @@ -101,8 +120,12 @@ func Load() (*Config, error) { S3Region: s3Region, S3AccessKey: s3AccessKey, S3SecretKey: s3SecretKey, + + MaxUploadBytes: maxUploadBytes, + MaxImagePixels: maxImagePixels, }, nil } + func (c *Config) S3Configured() bool { return c.S3Endpoint != "" && c.S3Bucket != "" && @@ -129,6 +152,18 @@ func readInt(key string, def int) (int, error) { return n, nil } +func readInt64(key string, def int64) (int64, error) { + v := os.Getenv(key) + if v == "" { + return def, nil + } + n, err := strconv.ParseInt(v, 10, 64) + if err != nil { + return 0, fmt.Errorf("не целое число: %q", v) + } + return n, nil +} + func readBool(key string, def bool) (bool, error) { v := os.Getenv(key) if v == "" { diff --git a/compose.yaml b/compose.yaml index ebacf84..85e4ab8 100644 --- a/compose.yaml +++ b/compose.yaml @@ -64,6 +64,33 @@ services: networks: - internal + minio: + image: pgsty/silo:RELEASE.2026-09-16T00-00-00Z + restart: unless-stopped + command: ["server", "/data"] + secrets: + - minio_root_user + - minio_root_password + environment: + MINIO_ROOT_USER_FILE: /run/secrets/minio_root_user + MINIO_ROOT_PASSWORD_FILE: /run/secrets/minio_root_password + MINIO_BROWSER: "off" + volumes: + - minio_data:/data + healthcheck: + test: ["CMD", "mc", "ready", "local"] + interval: 5s + timeout: 3s + retries: 10 + start_period: 5s + deploy: + resources: + limits: + cpus: "${MINIO_CPUS:-0.5}" + memory: ${MINIO_MEMORY:-512M} + networks: + - internal + migrate: build: context: . @@ -146,6 +173,7 @@ services: memory: 128M networks: - internal + secrets: postgres_password: file: ./secrets/postgres_password @@ -153,10 +181,19 @@ secrets: file: ./secrets/database_url cache_url: file: ./secrets/cache_url + minio_root_user: + file: ./secrets/minio_root_user + minio_root_password: + file: ./secrets/minio_root_password + s3_access_key_id: + file: ./secrets/s3_access_key_id + s3_secret_access_key: + file: ./secrets/s3_secret_access_key volumes: postgres_data: redis_data: + minio_data: networks: internal: