- Running automated tasks on a CI system
- Running automated tasks directly on app container, for example in a cron job
Before you begin
You might need the Upsun CLI to perform certain tasks. For example, you need the CLI to do the following:1. Create a machine user
To safely run automated tasks, first create machine users. Each machine user has its own Upsun account associated with a unique email address. You can grant them restrictive access permissions to handle specific automated tasks. For security purposes, create a machine user for each type of task you want to automate. To create a machine user, follow these steps:- Using the CLI
- In the Console
-
Run the following command using your machine user’s email address.
This sets your machine user as a viewer on your project and a contributor on development environments, with no access to other environment types. Note that you can further adjust user roles depending on your needs and each environment type.
- In the email invitation, click Create account.
- To create an Upsun account for the machine user, click Sign up and follow the instructions.
Machine users with an email address under your single sign-on (SSO) domain can be excluded from the SSO enforcement rule so they aren’t required to authenticate through your identity provider. See the SSO documentation for more information.
2. Create an API token
- Log in to the Console as your machine user.
- Open the user menu (your name or profile picture).
- Click My profile.
- Go to the API tokens tab and click Create API token.
- Enter a name for your API token and click Create API token.
- To copy the API token to your clipboard, click Copy. Note that after you close the API tokens tab, you can’t display the API token again.
- Store the API token somewhere secure on your computer.
Optional: check the validity of your API token
To check that your API token is valid, run the following command:3. Authenticate the CLI using your API token
After you create your API token, you can use it to do the following:- Allow a CI system to run automated tasks using the Upsun CLI.
- Run automated tasks on an app container using the Upsun CLI, for example in a cron job.
--no-wait flag.
Authenticate in a CI system
You can allow your CI system to run automated tasks using the Upsun CLI. To do so, create an environment variable namedUPSUN_CLI_TOKEN with your API token as its value.
For more information, see your CI system’s official documentation.
To run SSH-based commands that aren’t specific to the Upsun CLI,
see how to load the proper SSH certificate.
Authenticate in an environment
You can run automated tasks on an app container using the Upsun CLI. To do so, set your API token as a top-level environment variable.- Using the CLI
- In the Console
Run the following command:
.upsun/config.yaml
update source operation on your production environment,
use the following cron job:
Use the CLI SSH certificate for non-CLI commands
When you set aUPSUN_CLI_TOKEN environment variable,
the CLI authentication isn’t complete until your run a CLI command
or load the CLI SSH certificate.
For example, after setting a UPSUN_CLI_TOKEN environment variable,
you might need to run ssh, git, rsync, or scp commands before you run any CLI commands.
In this case, to ensure all your commands work, load the CLI SSH certificate first.
To do so, run the following command: