smira/aptly — pull request #96 by queeno (2014-08-16 23:34:01+00:00)
Title: Introducing aptly task

With this PR, I'd like to introduce the concept of *aptly task*.

An aptly task is a sequence of multiple aptly commands run within a single aptly thread.

For example, a task could be to create a new repository, add packages to it, create a snapshot and serve it.
Four commands can be now run in a single command.

Three reasons why I have chosen this approach:
1. *Easiness*: I quite like to do many things with a single command rather than many things with many commands.
1. *Single thread*: If aptly is called by multiple entities in order to perform a set of actions, the atomic commands may conflict with each other, introducing inconsistency in the DB. If they use this new feature, they will run tasks rather than atomic operations, greatly reducing this risk.
1. *Automation*: Looking forward, aptly could automate these tasks, especially if we find a way to inject parameters in the commands (we can store them in a file, set them in aptly, or use environment variables).
A practical user case could be to periodically update some mirrors and republish the snapshots, or to periodically drop an old snapshot, take a new one and republish it.
NB: People would object this is already possible today by using scripting languages.
`aptly task run` is not a replacement for scripting languages. It's a tool to simplify the life of a sys admin that could even reuse the same aptly tasks within multiple scripts.

How it works:

Three ways to make use of this new feature:
1. If the `-filename="filename"` flag is set, `aptly task run` will run the commands contained in the text file. The commands must be written on separate lines.
1. If no args are passed, then `aptly task run` assumes the use wants to input the commands manually falling into a kind of shell, where the user can type one command per line leaving a blank one when finished.
1. If multiple args are passed, `aptly task run` assumes it's a sequence of aptly commands separated by a coma ','.

The commands are run sequentially. If one returns an error, the remaining commands in the queue will not run.

A practical example:
I want to create a new repository, add a package, create a snapshot, verify it, publish and start serving it. All in one command.

```
root@precise64:~# aptly task run repo create local, repo add local jenkins_1.575_all.deb, snapshot create snap1 from repo local, snapshot verify -architectures=amd64 snap1, publish snapshot -distribution=main -architectures=amd64 snap1, serve
1) [Running]: repo create local

Begin command output: ----------------------------

Local repo [local] successfully added.
You can run 'aptly repo add local ...' to add packages to repository.

End command output: ------------------------------

2) [Running]: repo add local jenkins_1.575_all.deb

Begin command output: ----------------------------

Loading packages...
[+] jenkins_1.575_all added

End command output: ------------------------------

3) [Running]: snapshot create snap1 from repo local

Begin command output: ----------------------------

Snapshot snap1 successfully created.
You can run 'aptly publish snapshot snap1' to publish snapshot as Debian repository.

End command output: ------------------------------

4) [Running]: snapshot verify -architectures=amd64 snap1

Begin command output: ----------------------------

Loading packages...
Verifying...
Missing dependencies (5):
adduser [amd64]
daemon [amd64]
default-jre-headless [amd64]
java-runtime-headless [amd64]
psmisc [amd64]

End command output: ------------------------------

5) [Running]: publish snapshot -distribution=main -architectures=amd64 snap1

Begin command output: ----------------------------

Loading packages...
Generating metadata files and linking package files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:

Snapshot snap1 has been successfully published.
Please setup your webserver to serve directory '/home/vagrant/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ main main
Don't forget to add your GPG key to apt with apt-key.

You can also use `aptly serve` to publish your repositories over HTTP quickly.

End command output: ------------------------------

6) [Running]: serve

Begin command output: ----------------------------

Serving published repositories, recommended apt sources list:

# ./main [amd64] publishes {main: [snap1]: Snapshot from local repo [local]}
deb http://precise64.localdomain:8080/ main main

Starting web server at: :8080 (press Ctrl+C to quit)...
^Croot@precise64:~#
```