name: sylius

type: php:8.3

relationships:
    database: "db:mysql"

disk: 2048

mounts:
    "config/jwt":
        source: local
        source_path: jwt
    "/var/cache":
        source: local
        source_path: cache
    "/var/log":
        source: local
        source_path: log
    "/var/sessions":
        source: local
        source_path: sessions
    "/public/assets":
        source: local
        source_path: assets
    "/public/bundles":
        source: local
        source_path: bundles
    "/public/uploads":
        source: local
        source_path: uploads
    "/public/media":
        source: local
        source_path: media

web:
    locations:
        "/":
            root: "public"
            passthru: "/index.php"
            allow: true
            expires: -1
            scripts: true
        '/assets/shop':
            expires: 2w
            passthru: true
            allow: false
            rules:
                '\.(css|js|jpe?g|png|gif|svgz?|ico|bmp|tiff?|wbmp|ico|jng|bmp|html|pdf|otf|woff2|woff|eot|ttf|jar|swf|ogx|avi|wmv|asf|asx|mng|flv|webm|mov|ogv|mpe|mpe?g|mp4|3gpp|weba|ra|m4a|mp3|mp2|mpe?ga|midi?)$':
                    allow: true
        '/media/image':
            expires: 2w
            passthru: true
            allow: false
            rules:
                '\.(jpe?g|png|gif|svgz?)$':
                    allow: true
        '/media/cache/resolve':
            passthru: "/index.php"
            expires: -1
            allow: true
            scripts: true
        '/media/cache':
            expires: 2w
            passthru: true
            allow: false
            rules:
                '\.(jpe?g|png|gif|svgz?)$':
                    allow: true

variables:
    env:
        APP_ENV: 'prod'
        APP_DEBUG: 0
        N_PREFIX: /app/.global

build:
    flavor: composer

dependencies:
    nodejs:
        n: "*"
        yarn: "*"
    php:
        composer/composer: '^2'

runtime:
    extensions:
        - sodium

crons:
    sylius-cancel-unpaid-orders:
        spec: "0 2 * * *"
        cmd: "php bin/console --env=prod sylius:cancel-unpaid-orders"
    sylius-remove-expired-carts:
        spec: "0 2 * * *"
        cmd: "php bin/console --env=prod sylius:remove-expired-carts"

hooks:
    build: |
        set -e
        n auto
        hash -r
        curl -sS https://get.symfony.com/cli/installer | bash
        mv "$PLATFORM_APP_DIR/.symfony5/bin/symfony" "$PLATFORM_APP_DIR/.global/bin/symfony"
        cat >> "$PLATFORM_APP_DIR/.global/environment" <<EOS
            export \$(symfony var:export)
        EOS
        yarn install --frozen-lockfile
        yarn build:prod

    deploy: |
        set -e
        rm -rf var/cache/*
        mkdir -p public/media/image
        bin/console doctrine:database:create --if-not-exists
        bin/console doctrine:migrations:migrate -n
        bin/console sylius:fixtures:load -n
        bin/console lexik:jwt:generate-keypair --skip-if-exists
        bin/console assets:install --symlink --relative public
        bin/console cache:clear
