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. We do not modify the name of the environment variable along the way. So, for example, if your parameter name is my_parameter
, you can find it in os.getenv("my_parameter")
.
In a future release of Tower, this will change. We'll modify the parameters to be populated in the environment with a prefix of TOWER_PARAMETER_
, and a modified syntax (no special characters, all upper case letters).
In the above example, in the future, my_parameter
would become TOWER_PARAMETER_MY_PARAMETER
and can be found under os.getenv("TOWER_PARAMETER_MY_PARAMETER")
.
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 os
import time
# This task does nothing at all, really.
count = 0
friend = os.getenv("friend")
foe = os.getenv("foe")
while count < 5:
count += 1
print("Hello, {friend}! Boo to {foe}".format(friend=friend, foe=foe))
time.sleep(1)
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.