.platform.app.yaml 5.92 KB
# This file describes an application. You can have multiple applications
# in the same project.
#
# See https://docs.platform.sh/configuration/app.html

# The name of this app. Must be unique within a project.
# Must be lowercase alphanumeric characters. Changing the name destroys data associated with the app.
name: 'platform-app-name'

# The runtime the application uses.
type: 'php:8.1'

dependencies:
  php:
    composer/composer: '^2.1'
    drush/drush: '^12'
  nodejs:
    n: "*"

runtime:
  # Enable the redis extension so Drupal can communicate with the Redis cache.
  extensions:
    - redis
    - sodium
    - apcu
    - blackfire

# The relationships of the application with services or other applications.
#
# The left-hand side is the name of the relationship as it will be exposed
# to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand
# side is in the form `<service name>:<endpoint name>`.
relationships:
  database: 'db:mysql'
  redis: 'cache:redis'

# The size of the persistent disk of the application (in MB).
disk: 2048

# The 'mounts' describe writable, persistent filesystem mounts in the application.
mounts:
  # The default Drupal files directory.
  '/web/sites/default/files':
    source: local
    source_path: 'files'
  # Drupal gets its own dedicated tmp directory. The settings.platformsh.php
  # file will automatically configure Drupal to use this directory.
  '/tmp':
    source: local
    source_path: 'tmp'
  # Private file uploads are stored outside the web root. The settings.platformsh.php
  # file will automatically configure Drupal to use this directory.
  '/private':
    source: local
    source_path: 'private'
  # Drush needs a scratch space for its own caches.
  '/.drush':
    source: local
    source_path: 'drush'
  # Drush will try to save backups to this directory, so it must be
  # writeable even though you will almost never need to use it.
  '/drush-backups':
    source: local
    source_path: 'drush-backups'
  # Drupal Console will try to save backups to this directory, so it must be
  # writeable even though you will almost never need to use it.
  '/.console':
    source: local
    source_path: 'console'

# Configuration of the build of this application.
build:
  flavor: composer

variables:
  env:
    N_PREFIX: /app/.global

# The hooks executed at various points in the lifecycle of the application.
hooks:
  # The build hook runs after Composer to finish preparing up your code.
  # No services are available but the disk is writeable.
  build: |
    set -e

    if [ "$PLATFORM_ENVIRONMENT_TYPE" != production ]; then
      curl -fsS https://platform.sh/cli/installer | php

      # Install the version specified in the .nvmrc file
      n auto

      # Reset the location hash to recognize the newly installed version
      hash -r

      # Install npm packages for droopler_theme, compile sass, and compile js
      echo "Install npm packages for droopler_subtheme, compile sass, and compile js"

      cd web/profiles/contrib/droopler/themes/custom/droopler_theme/
      npm install
      cd -

      # Install npm packages for droopler_subtheme, compile sass, and compile js
      echo "Install npm packages for droopler_subtheme, compile sass, and compile js"

      cd web/themes/custom/droopler_subtheme/
      npm install
      npm run production
    fi

  # The deploy hook runs after your application has been deployed and started.
  # Code cannot be modified at this point but the database is available.
  # The site is not accepting requests while this script runs so keep it
  # fast.
  deploy: |
    set -e
    php ./drush/platformsh_generate_drush_yml.php
    # if drupal is installed, will call the following drush commands:
    #   - `cache-rebuild`
    #   - `updatedb`
    #   - and if config files are present, `config-import`
    cd web
    bash $PLATFORM_APP_DIR/drush/platformsh_deploy_drupal.sh

# The configuration of app when it is exposed to the web.
web:
  locations:
    # All requests not otherwise specified follow these rules.
    '/':
      # The folder from which to serve static assets, for this location.
      #
      # This is a filesystem path, relative to the application root.
      root: 'web'

      # How long to allow static assets from this location to be cached.
      #
      # Can be a time in seconds, or -1 for no caching. Times can be
      # suffixed with "s" (seconds), "m" (minutes), "h" (hours), "d"
      # (days), "w" (weeks), "M" (months, as 30 days) or "y" (years, as
      # 365 days).
      expires: 5m

      # Redirect any incoming request to Drupal's front controller.
      passthru: '/index.php'

      # Deny access to all static files, except those specifically allowed below.
      allow: false

      # Rules for specific URI patterns.
      rules:
        # Allow access to common static files.
        '\.(jpe?g|png|gif|svgz?|css|js|map|ico|bmp|eot|woff2?|otf|ttf)$':
          allow: true
        '^/robots\.txt$':
          allow: true
        '^/sitemap\.xml$':
          allow: true

        # Deny direct access to configuration files.
        '^/sites/sites\.php$':
          scripts: false
        '^/sites/[^/]+/settings.*?\.php$':
          scripts: false

    # The files directory has its own special configuration rules.
    '/sites/default/files':
      # Allow access to all files in the public files directory.
      allow: true
      expires: 5m
      passthru: '/index.php'
      root: 'web/sites/default/files'

      # Do not execute PHP scripts from the writeable mount.
      scripts: false

      rules:
        # Provide a longer TTL (2 weeks) for aggregated CSS and JS files.
        '^/sites/default/files/(css|js)':
          expires: 2w

crons:
  # Run Drupal's cron tasks every 19 minutes.
  drupal:
    spec: '*/19 * * * *'
    commands:
      start: 'cd web ; drush core-cron'

source:
  operations:
    auto-update:
      command: |
        curl -fsS https://raw.githubusercontent.com/platformsh/source-operations/main/setup.sh | { bash /dev/fd/3 sop-autoupdate; } 3<&0