Apps
Apps are packages of Python code, shell scripts, requirements.txt and other config files that you deploy to and manage with Tower. You describe how to package and invoke your app to Tower using a Towerfile.
Apps can implement ETL or ELT pipelines, batch inference jobs, web scraping tasks and other common data application types. Tower executes your apps in the Tower cloud and can also run these apps locally on your development machine.
Example app
A very simple app could be structured as follows.
my-app
├── Towerfile
└── task.py
The code that the app will actually execute is in the task.py file.
cat task.py
import os
import time
count = 0
while count < 5:
count += 1
print("Hello, world!")
time.sleep(1)
The Towerfile describes how to package and invoke this app. You can learn a bit more about what goes into a Towerfile in the Towerfile reference.
cat Towerfile
[app]
name = "hello-world"
script = "./task.py"
source = [
"./task.py",
]
Versions
When you deploy an app to the Tower cloud, you create a new version. You can use the tower deploy command to do this.
tower deploy
✔ Building package... Done!
Deploying to Tower... [00:00:00] [████████████████████████████████████████] 611 B/611 B (0s)
Success! Version `v10` has been deployed to Tower!
Parameters
To parameterize the way that applications behave at runtime, you can configure parameters in your Towerfile. When you run the app, you can pass in --parameter flags to set parameter values. When you're defining the parameter in the Towerfile, you specify a default value so you can always assume that a value will be present.
Parameters are passed in to your application's runtime environment as environment variables. You can access them using the Tower SDK — for example, if your parameter name is my_parameter, access it with tower.parameter('my_parameter').
Note: In the future, parameters will be scoped under TOWER__PARAMETER__* in the environment. For example, a parameter named MY_PARAMETER will be stored as TOWER__PARAMETER__MY_PARAMETER. Using tower.parameter('MY_PARAMETER') will continue to work — the SDK handles the resolution automatically.
Updating parameter definitions
Parameter definitions are updated every time your application is deployed.
Example app with parameters
Here's an example of the syntax for an app with two parameters defined.
cat Towerfile
[app]
name = "hello-world"
script = "./task.py"
source = [
"./task.py",
]
[[parameters]]
name = "friend"
description = "Someone that is close to you."
default = "Steve"
[[parameters]]
name = "foe"
description = "Something that you'd prefer to avoid."
default = "Carl"
And here's the example app Python for using the parameter.
import time
import tower
# This task does nothing at all, really.
count = 0
friend = tower.parameter("friend")
foe = tower.parameter("foe")
while count < 5:
count += 1
print("Hello, {friend}! Boo to {foe}".format(friend=friend, foe=foe))
time.sleep(1)
Hidden parameters
Sometimes you have sensitive data that you don't want to expose in the Tower UI or the REST API. For example, you might have an API key that your app needs to access a third-party service. You can mark parameters as "hidden" in your Towerfile to prevent them from being exposed in the UI and API.
[app]
name = "hello-world"
script = "./task.py"
source = [
"./task.py",
]
[[parameters]]
name = "friend"
description = "A secret friend that you have."
hidden = true
[[parameters]]
name = "foe"
description = "Something that you'd prefer to avoid."
default = "Carl"
Note that hidden parameters may only have empty default values, so if your app needs a non-empty value for a hidden parameter, you must pass it in when you run the app. You can pass in hidden parameters using the --parameter flag when you run the app.
When you run the app above, the value that you pass in for the friend
parameter will not be visible in the Tower UI or the REST API. However, your
app will still be able to access the value of the friend parameter using
tower.parameter("friend").
Running apps
You can use the tower run command in the terminal, the "Run App" feature in the Tower UI, or the REST API to execute (initiate a run) an app. Learn more about it in the Runs section.
More examples
You can find more examples in the tower-examples repository on GitHub.