Upsun User Documentation

Automate your code updates

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!¹ A monthly $19 perk!
¹Terms and conditions apply
Activate your 15-day trial

Upsun 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 .upsun/config.yaml file depending on your dependency manager:

.upsun/config.yaml
applications:
  # The name of the app container. Must be unique within a project.
  myapp:
    # The location of the application's code.
    source:
      root: "myapp"
    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"            
.upsun/config.yaml
applications:
  # The name of the app container. Must be unique within a project.
  myapp:
    # The location of the application's code.
    source:
      root: "myapp"
    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"            
.upsun/config.yaml
applications:
  # The name of the app container. Must be unique within a project.
  myapp:
    # The location of the application's code.
    source:
      root: "myapp"
    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"            
.upsun/config.yaml
applications:
  # The name of the app container. Must be unique within a project.
  myapp:
    # The location of the application's code.
    source:
      root: "myapp"
    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"            
.upsun/config.yaml
applications:
  # The name of the app container. Must be unique within a project.
  myapp:
    # The location of the application's code.
    source:
      root: "myapp"
    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"            
.upsun/config.yaml
applications:
  # The name of the app container. Must be unique within a project.
  myapp:
    # The location of the application's code.
    source:
      root: "myapp"
    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 Upsun 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:

upsun variable:create --environment main --level environment --prefix 'env' --name UPSUN_CLI_TOKEN --sensitive true --value 'YOUR_UPSUN_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:UPSUN_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:
.upsun/config.yaml
applications:
  myapp:
    hooks:
      build: |
        set -e
        echo "Installing Upsun CLI"
        curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash

        echo "Testing Upsun CLI"
        upsun        
  1. Then, to configure a cron job to automatically update your dependencies once a day, use a configuration similar to the following:
.upsun/config.yaml
applications:
  myapp:
    # ...
    crons:
      update:
        # Run the code below every day at midnight.
        spec: '0 0 * * *'
        commands:
          start: |
            set -e
            upsun sync -e development code data --no-wait --yes
            upsun 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 Upsun CLI command:

upsun 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?