Exporting Packages
Chef Habitat Artifacts–.hart
files–can be exported in a number of different formats depending on what you need and where you need it. This is powerful because you can use the same immutable Chef Habitat artifact by exporting it into a format that you need for a specific job.
You can export packages to a Docker container image or a tar file.
The command to export a package is hab pkg export <FORMAT> <PKG_IDENT>
. See the Chef Habitat CLI Reference Guide for more CLI information.
Note If you specify an
origin/package
identifier, such ascore/postgresql
, the Chef Habitat CLI will check Builder for the latest stable version of the package and export that.
If you wish to export a package that is not on Builder, create a Chef Habitat artifact by running the
build
command, then pointhab pkg
to the.hart
file within the/results
directory:
hab pkg export tar ./results/example-app.hart
Read on for more detailed instructions.
Exporting to Docker
You can create a Docker container image for any package by performing the following steps:
Ensure you have a Docker daemon running on your host system. On Linux, the exporter shares the Docker socket (
unix:///var/run/docker.sock
) into the studio.Create an interactive studio with the
hab studio enter
command.Build the Chef Habitat package from which you want to create a Docker container image and then run the Docker exporter on the package.
hab pkg export docker ./results/<hart-filename>.hart
Note The command above is for local testing only. If you have uploaded your package to Builder, you can export it by calling
hab pkg export docker origin/package
. The default is to use the latest stable release; however, you can override that by specifying a different channel in an optional flag.Note On Linux, exporting your Chef Habitat artifact to a Docker image requires the Docker Engine supplied by Docker. Packages from distribution-specific or otherwise alternative providers are currently not supported.
Note In a Windows container studio, the
export
command will not be able to access the host docker engine. To export a Windows package or hart file built inside of a Windows container studio, first exit the studio and then export the.hart
file in your localresults
directory.You may now exit the studio. The new Docker image exists on your computer and can be examined with
docker images
or run withdocker run
.Please note that when you run this docker container, you will need to pass the
HAB_LICENSE
environment variable into the container in order to accept the Habitat license. If you don’t, your container will abort at a license acceptance prompt. One way to do this would bedocker run --env HAB_LICENSE=accept-no-persist IMAGE
. Alternatively, if you use a scheduler to run these docker containers, you should add that environment variable to your scheduler configuration.
Exporting to a Tarball
Enter the Chef Habitat studio by using
hab studio enter
.Install or build the Chef Habitat package from which you want to create a tarball, for example:
hab pkg install <ORIGIN>/<NAME>
Run the tar exporter on the package.
hab pkg export tar <ORIGIN>/<NAME>
If you receive an error, try running
hab pkg export tar /results/<your_package>.hart
Your package is now in a tar file that exists locally on your computer in the format
<ORIGIN>-<NAME>-<VERSION>-<TIMESTAMP>.tar.gz
and can be deployed and run on a target machine.If you wish to run this tar file on a remote machine (i.e. a virtual machine in a cloud environment), scp (or whatever transfer protocol you prefer) the file to whatever you wish to run it.
SSH into the virtual machine
Run these commands to set up the required user and group:
sudo adduser --group hab sudo useradd -g hab hab
Next, unpack the tar file:
sudo tar xf your-origin-package-version-timestamp.tar.gz sudo cp -R hab /hab
Now, start the Supervisor and load your service package using the
hab
binary, which is included in the tar archive:sudo /hab/bin/hab sup run sudo /hab/bin/hab svc load <ORIGIN>/<NAME>