chore(compose):lab4 add MinIO service with volume and healthcheck
This commit is contained in:
@@ -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
|
S3_SECRET_ACCESS_KEY_FILE=/run/secrets/s3_secret_access_key
|
||||||
MAX_UPLOAD_BYTES=10485760
|
MAX_UPLOAD_BYTES=10485760
|
||||||
MAX_IMAGE_PIXELS=40000000
|
MAX_IMAGE_PIXELS=40000000
|
||||||
|
MINIO_ROOT_USER=...
|
||||||
|
MINIO_CPUS=0.5
|
||||||
|
MINIO_MEMORY=512M
|
||||||
@@ -24,6 +24,9 @@ type Config struct {
|
|||||||
S3Region string
|
S3Region string
|
||||||
S3AccessKey string
|
S3AccessKey string
|
||||||
S3SecretKey string
|
S3SecretKey string
|
||||||
|
|
||||||
|
MaxUploadBytes int64
|
||||||
|
MaxImagePixels int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load() (*Config, error) {
|
func Load() (*Config, error) {
|
||||||
@@ -76,15 +79,31 @@ func Load() (*Config, error) {
|
|||||||
}
|
}
|
||||||
s3Region := getenv("S3_REGION", "us-east-1")
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("s3 access key: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("s3 secret key: %w", err)
|
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{
|
return &Config{
|
||||||
Host: getenv("APP_HOST", "0.0.0.0"),
|
Host: getenv("APP_HOST", "0.0.0.0"),
|
||||||
Port: getenv("APP_PORT", "8080"),
|
Port: getenv("APP_PORT", "8080"),
|
||||||
@@ -101,8 +120,12 @@ func Load() (*Config, error) {
|
|||||||
S3Region: s3Region,
|
S3Region: s3Region,
|
||||||
S3AccessKey: s3AccessKey,
|
S3AccessKey: s3AccessKey,
|
||||||
S3SecretKey: s3SecretKey,
|
S3SecretKey: s3SecretKey,
|
||||||
|
|
||||||
|
MaxUploadBytes: maxUploadBytes,
|
||||||
|
MaxImagePixels: maxImagePixels,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) S3Configured() bool {
|
func (c *Config) S3Configured() bool {
|
||||||
return c.S3Endpoint != "" &&
|
return c.S3Endpoint != "" &&
|
||||||
c.S3Bucket != "" &&
|
c.S3Bucket != "" &&
|
||||||
@@ -129,6 +152,18 @@ func readInt(key string, def int) (int, error) {
|
|||||||
return n, nil
|
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) {
|
func readBool(key string, def bool) (bool, error) {
|
||||||
v := os.Getenv(key)
|
v := os.Getenv(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
|
|||||||
@@ -64,6 +64,33 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- internal
|
- 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:
|
migrate:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
@@ -146,6 +173,7 @@ services:
|
|||||||
memory: 128M
|
memory: 128M
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
postgres_password:
|
postgres_password:
|
||||||
file: ./secrets/postgres_password
|
file: ./secrets/postgres_password
|
||||||
@@ -153,10 +181,19 @@ secrets:
|
|||||||
file: ./secrets/database_url
|
file: ./secrets/database_url
|
||||||
cache_url:
|
cache_url:
|
||||||
file: ./secrets/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:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
redis_data:
|
redis_data:
|
||||||
|
minio_data:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
internal:
|
internal:
|
||||||
|
|||||||
Reference in New Issue
Block a user