The hapistrano package

[ Tags: library, mit, program, system ] [ Propose Tags ]

Hapistrano makes it easy to reliably deploy Haskell applications to a server.

Following popular libraries like Ruby's < Capistrano>, Hapistrano does the work of building the application with dependencies into a distinct folder, and then atomically moves a symlink to the latest complete build.

This allows for atomic switchovers to new application code after the build is complete. Rollback is even simpler, since Hapistrano can just point the current symlink to the previous release.

See the project readme on GitHub for more information.

[Skip to Readme]


Versions,,,,, 0.2.1,,,,,,,,,,,
Change log
Dependencies aeson (>=0.11 && <1.3), async (>= && <2.2), base (>=4.8 && <5.0), filepath (>=1.2 && <1.5), hapistrano, mtl (>=2.0 && <3.0), optparse-applicative (>=0.11 && <0.15), path (>=0.5 && <0.7), path-io (>=1.2 && <1.4), process (>=1.4 && <1.7), stm (==2.4.*), time (>=1.5 && <1.9), transformers (>=0.4 && <0.6), yaml (==0.8.*) [details]
License MIT
Copyright 2015-2017 Stack Builders Inc.
Author Justin Leitgeb
Category System
Home page
Bug tracker
Source repository head: git clone
Uploaded Mon Sep 4 21:04:58 UTC 2017 by juanpaucar
Distributions LTSHaskell:, NixOS:, Stackage:, Tumbleweed:
Executables hap
Downloads 1727 total (84 in the last 30 days)
Rating 2.25 (2 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-09-04 [all 1 reports]
Hackage Matrix CI





Turn on development settings.


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees

Readme for hapistrano-

[back to package description]

Build Status Hackage version


Hapistrano is a deployment library for Haskell applications similar to Ruby's Capistrano.


We created Hapistrano because:

  • Deploys should be simple, but as close to atomic as possible (eg, they shouldn't require much application downtime).
  • Rollback should be trivial to achieve to bring the application back to the last-deployed state.
  • Deploys shouldn't fail because of dependency problems.

How it Works

Hapistrano (like Capistrano for Ruby) deploys applications to a new directory marked with a timestamp on the remote host. It creates this new directory quickly by placing a git repository for caching purposes on the remote server.

When the build process completes, it switches a symlink to the current release directory, and optionally restarts the web server.

By default, Hapistrano keeps the last five releases on the target host filesystem and deletes previous releases to avoid filling up the disk.


Hapistrano looks for a configuration file called hap.yaml that typically looks like this:

deploy_path: '/var/projects/my-project'
port: 2222
repo: ''
revision: origin/master
  - stack setup
  - stack build
restart_command: systemd restart my-app-service

The following parameters are required:

  • deploy_path — the root of the deploy target on the remote host.
  • repo — the origin repository.
  • revision — the SHA1 or branch to deploy. If a branch, you will need to specify it as origin/branch_name due to the way that the cache repo is configured.

The following parameters are optional:

  • host — the target host, if missing, localhost will be assumed (which is useful for testing and playing with hap locally).
  • port — SSH port number to use. If missing, 22 will be used.
  • build_script — instructions how to build the application in the form of shell commands.
  • restart_command — if you need to restart a remote web server after a successful rollback, specify the command that you use in this variable. It will be run after both deploy and rollback.
  • vc_action - Controls if version control related activity should take place. It defaults to true. When you don't want activity like cloning, fetching etc. to take place, set this to false.
  • run_locally:- Instructions to run locally on your machine in the form of shell commands. Example:
  - pwd
  - bash

Note how we are even able to execute a bash script named above. Be sure to use set -e in your bash script to avoid headaches. Hapistrano will stop the execution on non zero exit codes. Without the usage of set -e, there is a possiblity that your bash script may return a zero exit code even if your intermediate command resulted in an error.

After creating a configuration file as above, deploying is as simple as:

$ hap deploy

Rollback is also trivial:

$ hap rollback # to rollback to previous successful deploy
$ hap rollback -n 2 # go two deploys back in time, etc.

What to do when compiling on server is not viable

Sometimes the target machine (server) is not capable of compiling your application because e.g. it has not enough memory and GHC exhausts it all. You can copy pre-compiled files from local machine or CI server using copy_files and copy_dirs parameters:

  - src: '/home/stackbuilders/my-file.txt'
    dest: 'my-file.txt'
  - src: .stack-work
    dest: .stack-work

src maybe absolute or relative, it's path to file or directory on local machine, dest may only be relative (it's expanded relatively to cloned repo) and specifies where to put the files/directories on target machine. Directories and files with clashing names will be overwritten. Directories are copied recursively.

Deploying to multiple machines concurrently

Beginning with Hapistrano it's possible to deploy to several machines concurrently. The only things you need to do is to adjust your configuration file and use targets parameter instead of host and port, like this:

  - host:
    port: 2222
  - host:
# the rest is the same…

A few things to note here:

  • host item is required for every target, but port may be omitted and then it defaults to 22.

  • The deployment will run concurrently and finish when interactions with all targets have finished either successfully or not. If at least one interaction was unsuccessful, the hap tool will exit with non-zero exit code.

  • The log is printed in such a way that messages from several machines get intermixed, but it's guaranteed that they won't overlap (printing itself is sequential) and the headers will tell you exactly which machine was executing which command.

If you don't specify host and targets, hap will assume localhost as usually, which is mainly useful for testing.


MIT, see the LICENSE file.


Pull requests for modifications to this program are welcome. Fork and open a PR. Feel free to email me if you have questions about what may be accepted before working on a PR.

If you're looking for a place to start, you may want to check the open issue.