github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/pkg/ddevapp/dotddev_assets/providers/platform.yaml (about)

     1  #ddev-generated
     2  # Example Platform.sh provider configuration.
     3  
     4  # Consider using `ddev get drud/ddev-platformsh` (https://github.com/drud/ddev-platformsh) for more
     5  # complete platform integration.
     6  
     7  # To use this configuration,
     8  
     9  # 1. Check out the site from platform.sh and then configure it with `ddev config`. You'll want to use `ddev start` and make sure the basic functionality is working.
    10  # 2. Obtain and configure an API token.
    11  #    a. Login to the Platform.sh Dashboard and go to Account->API Tokens to create an API token for ddev to use.
    12  #    b. Add the API token to the `web_environment` section in your global ddev configuration at ~/.ddev/global_config.yaml:
    13  #    ```yaml
    14  #    web_environment:
    15  #    - PLATFORMSH_CLI_TOKEN=abcdeyourtoken
    16  #    ```
    17  # 3. Add PLATFORM_PROJECT and PLATFORM_ENVIRONMENT variables to your project `.ddev/config.yaml` or a `.ddev/config.platform.yaml`
    18  #    ```yaml
    19  #    web_environment:
    20  #    - PLATFORM_PROJECT=nf4amudfn23biyourproject
    21  #    - PLATFORM_ENVIRONMENT=main
    22  # 4. `ddev restart`
    23  # 5. Run `ddev pull platform`. After you agree to the prompt, the current upstream database and files will be downloaded.
    24  # 6. Optionally use `ddev push platform` to push local files and database to platform.sh. Note that `ddev push` is a command that can potentially damage your production site, so this is not recommended.
    25  
    26  # If you have more than one database on your Platform.sh project,
    27  # you will likely to choose which one you want to use
    28  # as the primary database ('db').
    29  # Do this by setting PLATFORM_PRIMARY_RELATIONSHIP, for example, `ddev config --web-environment-add=PLATFORM_PRIMARY_RELATIONSHIP=main`
    30  # or run `ddev pull platform` with the environment variable, for example
    31  # `ddev pull platform -y --environment=PLATFORM_PRIMARY_RELATIONSHIP=main`
    32  # If you need to change this `platform.yaml` recipe, you can change it to suit your needs, but remember to remove the "ddev-generated" line from the top.
    33  
    34  # Debugging: Use `ddev exec platform` to see what platform.sh knows about
    35  # your configuration and whether it's working correctly.
    36  
    37  auth_command:
    38    command: |
    39      set -eu -o pipefail
    40      if [ -z "${PLATFORMSH_CLI_TOKEN:-}" ]; then echo "Please make sure you have set PLATFORMSH_CLI_TOKEN." && exit 1; fi
    41      if [ -z "${PLATFORM_PROJECT:-}" ]; then echo "Please make sure you have set PLATFORM_PROJECT." && exit 1; fi
    42      if [ -z "${PLATFORM_ENVIRONMENT:-}" ]; then echo "Please make sure you have set PLATFORM_ENVIRONMENT." && exit 1; fi
    43  
    44  db_pull_command:
    45    command: |
    46      # set -x   # You can enable bash debugging output by uncommenting
    47      set -eu -o pipefail
    48      export PLATFORMSH_CLI_NO_INTERACTION=1
    49      ls /var/www/html/.ddev >/dev/null # This just refreshes stale NFS if possible
    50      # /tmp/db_relationships.yaml is the full yaml output of the database relationships
    51      db_relationships_file=/tmp/db_relationships.yaml
    52      PLATFORM_RELATIONSHIPS="" platform relationships -y  -e "${PLATFORM_ENVIRONMENT}" | yq 'with_entries(select(.[][].type == "mariadb:*" or .[][].type == "*mysql:*" or .[][].type == "postgresql:*")) ' >${db_relationships_file}
    53      db_relationships=($(yq ' keys | .[] ' ${db_relationships_file}))
    54      db_names=($(yq '.[][].path' ${db_relationships_file}))
    55      db_count=${#db_relationships[@]}
    56      # echo "db_relationships=${db_relationships} sizeof db_relationships=${#db_relationships[@]} db_names=${db_names} db_count=${db_count} PLATFORM_PRIMARY_RELATIONSHIP=${PLATFORM_PRIMARY_RELATIONSHIP}"
    57      # If we have only one database, import it into local database named 'db'
    58      if [ ${#db_names[@]} -eq 1 ]; then db_names[0]="db"; fi
    59  
    60      for (( i=0; i<${#db_relationships[@]}; i++ )); do
    61        db_name=${db_names[$i]}
    62        rel=${db_relationships[$i]}
    63        # if PLATFORM_PRIMARY_RELATIONSHIP is set, then when doing that one, import it into local database 'db'
    64        if [ "${rel}" = "${PLATFORM_PRIMARY_RELATIONSHIP:-notset}" ] ; then
    65          echo "PLATFORM_PRIMARY_RELATIONSHIP=${PLATFORM_PRIMARY_RELATIONSHIP:-} so using it as database 'db' instead of the upstream '${db_name}'"
    66          db_name="db"
    67        fi
    68  
    69        platform db:dump --yes --relationship=${rel} --gzip --file=/var/www/html/.ddev/.downloads/${db_name}.sql.gz --project="${PLATFORM_PROJECT:-setme}" --environment="${PLATFORM_ENVIRONMENT:-setme}"
    70      done
    71      echo "Downloaded db dumps for databases '${db_names[@]}'"
    72  
    73  files_import_command:
    74    command: |
    75      #set -x   # You can enable bash debugging output by uncommenting
    76      set -eu -o pipefail
    77      export PLATFORMSH_CLI_NO_INTERACTION=1
    78      # Use $PLATFORM_MOUNTS if it exists to get list of mounts to download, otherwise just web/sites/default/files (drupal)
    79      declare -a mounts=(${PLATFORM_MOUNTS:-/web/sites/default/files})
    80      platform mount:download --all --yes --quiet --project="${PLATFORM_PROJECT}" --environment="${PLATFORM_ENVIRONMENT}"  --target=/var/www/html
    81  
    82  
    83  # push is a dangerous command. If not absolutely needed it's better to delete these lines.
    84  db_push_command:
    85    command: |
    86      # set -x   # You can enable bash debugging output by uncommenting
    87      set -eu -o pipefail
    88      export PLATFORMSH_CLI_NO_INTERACTION=1
    89      ls /var/www/html/.ddev >/dev/null # This just refreshes stale NFS if possible
    90      pushd /var/www/html/.ddev/.downloads >/dev/null;
    91      if [ "${PLATFORM_PRIMARY_RELATIONSHIP:-}" != "" ] ; then
    92        rel="--relationship ${PLATFORM_PRIMARY_RELATIONSHIP}"
    93      fi
    94      gzip -dc db.sql.gz | platform db:sql --project="${PLATFORM_PROJECT}" ${rel:-} --environment="${PLATFORM_ENVIRONMENT}"
    95  
    96  # push is a dangerous command. If not absolutely needed it's better to delete these lines.
    97  # TODO: This is a naive, Drupal-centric push, which needs adjustment for the mount to be pushed.
    98  files_push_command:
    99    command: |
   100      # set -x   # You can enable bash debugging output by uncommenting
   101      set -eu -o pipefail
   102      export PLATFORMSH_CLI_NO_INTERACTION=1
   103      ls "${DDEV_FILES_DIR}" >/dev/null # This just refreshes stale NFS if possible
   104      platform mount:upload --yes --quiet --project="${PLATFORM_PROJECT}" --environment="${PLATFORM_ENVIRONMENT}" --source="${DDEV_FILES_DIR}" --mount=web/sites/default/files
   105