The autoapply configuration is specified in YAML and has the following structure:
init: cwd: ... commands: - ... loop: sleep: 60 onerror: continue cwd: ... commands: - ... server: enabled: false port: 3000 call: path: /path headers: - ... authentication: - ... stream: false onerror: fail cwd: ... commands: - ...
All sections are optional, but you have to configure at least one loop or call.
Define any commands that should be executed on startup. If any of the commands fail, autoapply will exit.
Directory in which to execute the commands (working directory). If unset, the directory in which autoapply was started will be used.
Example: cwd: /tmp
List of commands that should be run on startup. See commands.
Define the loop commands. If you only need one loop, you can just specify an object:
loop:
cwd: /tmp
commands:
- lsIf you want to run multiple loops in parallel, you can specify an array:
loop:
- cwd: .
commands:
- echo "This is loop 1"
- sleep: 120
commands:
- echo "This is loop 2"Directory in which to execute the commands (working directory). If unset, a new temporary directory will be created for each loop iteration
Time to wait (in seconds) between each iteration. A value of 0 disables sleeping, default is 60 (1 minute).
What should happen when a command fails? Possible values:
ignore- ignore the error and continue with the next commandcontinue(default) - don't execute any remaining commands and continue with the next loop iterationfail- exit the loop with an error message
Example:
loop:
onerror: ignore
commands:
- git pull
- make &> .build
- slackcli -h '#build' -m "Build status $(cat .build)"List of commands that should be run in a loop, after the commands defined in the init section have finished successfully. See commands.
Configuration of the internal HTTP server.
When the server is running, it provides the endpoint /healthz, which just
responds with OK and can be used as a liveness probe.
Set this to true if you want to enable the HTTP server (default is false).
The server will be enabled automatically when you specify calls.
The HTTP port that the server will listen on, default is 3000.
Define web commands that will be executed when the URL is called. If you only need one call, you can just specify an object:
call:
path: /echo
commands: ["echo hello"]If you want to provide multiple calls, you can specify an array:
call:
- path: /echo1
commands: ["echo hello"]
- path: /echo2
commands: ["echo world"]The following environment variables will be set for each call:
REQUEST_METHOD- the HTTP method, for exampleGETorPOSTREQUEST_URI- the requested URI, for example/echo1REMOTE_ADDR- the IP address of the requesting client
Additionally, all request HTTP headers and query parameters will be available as environment variables.
Header name environment variables will be prefixed with HTTP_ and
query parameters will be prefixed with QUERY_. Both header names
and query parameters will be converted to uppercase and all characters
other than letters or numbers will be replaced with _.
For example, the HTTP header User-Agent will be available
as HTTP_USER_AGENT, the query parameter from the URL /test?param.1=x
will be available as QUERY_PARAM_1.
The path to bind this call to:
call:
- path: /date
commands:
- dateHTTP headers to send with each response
call:
- path: /index.html
headers:
- name: Content-Type
value: text/plain; charset=utf-8
commands:
- echo '<html><body>Hello!</body></html>'You could also pass the headers as an object:
headers:
Content-Type: text/plain; charset=utf-8List of HTTP methods that this call accepts.
By default, only GET methods are supported, requests with any other method
will be answered by HTTP error 405 (method not allowed).
To support GET and POST:
call:
- path: /clear
methods: ["GET", "POST"]
commands:
- rm -rf /tmp/*If you want to support all methods:
call:
- path: /check
methods: ["*"]
commands:
- echo $REQUEST_METHODList of users that are allowed to access this call. The users will be authenticated using HTTP basic access authentication and when invalid credentials are given, the call will be answered with HTTP error 401 (unauthorized).
call:
- path: /private
authentication:
- username: user1
password: password123
- username: user2
password: password321
commands:
- cat /var/log/access.logThe list of users can also be read from an environment variable:
call:
- path: /private
authentication:
env: USER_AUTH
commands:
- cat /var/log/access.logIt's also possible to read the users from a file:
call:
- path: /private
authentication:
file: /etc/users.txt
commands:
- cat /var/log/access.logFor environment variables and files, use the following format:
user1:password123
user2:password321
Start to send available data to the client before all commands have finished?
Default is false.
Data is sent before the commands have finished, so when using stream,
the HTTP status will always be 200 (OK), regardless of any errors.
call:
- path: /access.log
stream: true
headers:
# See https://stackoverflow.com/a/35848615
- name: X-Content-Type-Options
value: nosniff
commands:
- tail -f /var/log/access.logDirectory in which to execute the commands (working directory). If unset, a new temporary directory will be created for each call.
What should happen when a command fails? Possible values:
ignore- ignore the error and continue with the next commandcontinue- don't execute any remaining commands and return HTTP status 200 (OK)fail(default) - stop the call and return HTTP status 500 (error)
Example:
call:
- path: /check
onerror: ignore
commands:
- curl https://example.com/test1
- curl https://example.com/test2
- curl https://example.com/test3List of commands that should be run when the URL is called. See commands.
An array of commands to run.
The simple string form will use the shell, so environment variables etc. can be used:
commands:
- ls ${HOME}
- "echo $(pwd)"The array form will not use the shell. In this case, ls will try to list the contents of a directory with the literal name ${HOME}. This will likely fail with "No such file or directory":
commands:
- ["ls", "${HOME}"]It is also possible to specify full scripts to be executed:
commands:
- script: |
#!/usr/bin/env node
console.log('Hello, world!');How to treat the standard output of the command? Possible values:
pipe(default) - print the output as the standard output of the autoapply processignore- discard any output (like redirecting to/dev/null)
Example:
commands:
- command: ls "${HOME}/.ssh/id_rsa"
stdout: ignoreThe same option as stdout, but for the error output of the command:
commands:
- command: curl "$URL"
stdout: ignore
stderr: ignore