Platform.sh User Documentation

Automate your code updates

Try for 30 days
Flexible, version-controlled infrastructure provisioning and development-to-production workflows
Activate your trial

Platform.sh allows you to update your dependencies through source operations.

Before you start Anchor to this heading

You need:

1. Define a source operation to update your dependencies Anchor to this heading

To facilitate updating your dependencies in your project, define a source operation in your .platform.app.yaml file depending on your dependency manager:

.platform.app.yaml
source:
  operations:
    update:
      command: |
        set -e
        composer update
        git add composer.lock
        git add -A
        git diff-index --quiet HEAD || git commit --allow-empty -m "Update Composer dependencies"        
.platform.app.yaml
source:
  operations:
    update:
      command: |
        set -e
        npm update
        git add package.json package-lock.json
        git add -A
        git diff-index --quiet HEAD || git commit --allow-empty -m "Update npm dependencies"        
.platform.app.yaml
source:
  operations:
    update:
      command: |
        set -e
        yarn upgrade
        git add yarn.lock
        git add -A
        git diff-index --quiet HEAD || git commit --allow-empty -m "Update yarn dependencies"        
.platform.app.yaml
source:
  operations:
    update:
      command: |
        set -e
        go get -u
        go mod tidy
        git add go.mod go.sum
        git add -A
        git diff-index --quiet HEAD || git commit --allow-empty -m "Update Go dependencies"        
.platform.app.yaml
source:
  operations:
    update:
      command: |
        set -e
        pipenv update
        git add Pipfile Pipfile.lock
        git add -A
        git diff-index --quiet HEAD || git commit --allow-empty -m "Update Python dependencies"        
.platform.app.yaml
source:
  operations:
    update:
      command: |
        set -e
        bundle update --all
        git add Gemfile Gemfile.lock
        git add -A
        git diff-index --quiet HEAD || git commit --allow-empty -m "Update Ruby dependencies"        

2. Automate your dependency updates with a cron job Anchor to this heading

After you’ve defined a source operation to update your dependencies on your project, you can automate it using a cron job.

Note that it’s best not to run source operations on your production environment, but rather on a dedicated environment where you can test changes.

Make sure you have the Platform.sh CLI installed and an API token so you can run a cron job in your app container.

  1. Set your API token as a top-level environment variable:

Run the following command:

platform variable:create --environment main --level environment --prefix 'env' --name PLATFORMSH_CLI_TOKEN --sensitive true --value 'YOUR_PLATFORMSH_CLI_TOKEN' --inheritable false --visible-build true --json false --enabled true --visible-runtime true
  1. Open the environment where you want to add the variable.
  2. Click Settings.
  3. Click Variables.
  4. Click + Add variable.
  5. In the Variable name field, enter env:PLATFORMSH_CLI_TOKEN.
  6. In the Value field, enter your API token.
  7. Make sure the Available at runtime and Sensitive variable options are selected.
  8. Click Add variable.
  1. Add a build hook to your app configuration to install the CLI as part of the build process:

    .platform.app.yaml
    hooks:
      build: |
        set -e
        echo "Installing Platform.sh CLI"
        curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash
    
        echo "Testing Platform.sh CLI"
        platform    
  2. Then, to configure a cron job to automatically update your dependencies once a day, use a configuration similar to the following:

    .platform.app.yaml
    crons:
      update:
        # Run the code below every day at midnight.
        spec: '0 0 * * *'
        commands:
          start: |
            set -e
            platform sync -e development code data --no-wait --yes
            platform source-operation:run update --no-wait --yes        

The example above synchronizes the development environment with its parent and then runs the update source operation defined previously.

3. Configure notifications about dependency updates Anchor to this heading

To get notified every time a source operation is triggered and therefore every time a dependency is updated, you can configure activity scripts or webhooks.

Notifications through an activity script Anchor to this heading

After you’ve defined a source operation to update your dependencies on your project, you can configure an activity script to receive notifications every time a dependency update is triggered.

Notifications through a webhook Anchor to this heading

After you’ve defined a source operation to update your dependencies on your project, you can configure a webhook to receive notifications every time a dependency update is triggered.

Webhooks allow you to host a script yourself externally. This script receives the same payload as an activity script and responds to the same events, but can be hosted on your own server and in your own language.

To configure the integration between your webhook and your source operation, run the following Platform.sh CLI command:

platform integration:add --type=webhook --url=URL_TO_RECEIVE_JSON --events=environment.source-operation

Optional: to only get notifications about specific environments, add the following flag to the command: --environments=your_environment_name.

To test the integration and the JSON response, you can generate a URL from a service such as webhook.site and use the generated URL as URL_TO_RECEIVE_JSON. This URL then receives the JSON response when a source operation is triggered.

Anytime a dependency is updated via a source operation, the webhook now receives a POST message. This POST message contains complete information about the entire state of the project at that time.

Is this page helpful?