Recently, a new specification reached version 1. The Cloud Native Application Bundle is designed to help take application packaging, particularly in the serverless/cloud world, to the next level. It is designed to compliment existing tool sets such as Terraform and Docker. This snip-it from the Porter FAQ is pretty telling:
Porter is an implementation of the CNAB specification. Cloud Native Application Bundles is a different way of answering “How do I reliably, securely deploy an application and its infrastructure?”. It isn’t replacing Ansible or Terraform but adding some concepts on top. For example, packaging together the Terraform binary and your Terraform scripts into an immutable bundle with a digest that attests that the contents haven’t been altered, that can be distributed via OCI (docker) registries or USB sticks to get into air-gapped networks.
The CNAB spec is pretty open-ended about how to implement the spec, but Porter took the route of making it incredibly easy to take existing tools, like kubectl, Terraform, the azure/aws/gcloud CLIs, and use them inside a bundle. So that you don’t need to rewrite existing scripts.
The goal of this post is to walk through getting started with Porter on windows.
The first step, according to the Install page, is to download and install porter. It installs locally and within a given directory. I generally don’t like to just randomly execute code from the web, so I recommend downloading the powershell file first and then taking a look.
One key thing to understand at this junction is that porter makes use of the docker engine by default. You will want to make sure you have docker installed and up and running (using linux containers) prior to executing these steps.
The next thing you will want to watch out for is the directory that porter installs to. By default (as you can see in the first line of the file) it installs in to your home directory under a “.porter” directory. This is all well and good, however, if you are like me and use Azure AD logins, you will run in to issues when you try and install the bundle (I’ll get to this later). For now, I recommend putting the porter files in a directory that is accessible to all users of your system.
After this, I was able to run the portal install successfully and without issues. As per the documentation, you get porter along with the current list of stable mixins. Remember to add the porter directory to your PATH variable or be prepared to fully qualify the porter location.
Now it’s time to move on to the quickstart page/instructions. A key piece of information here is that every porter command you run can be run with the –debug flag which will give you more information about what it’s doing. Create a directory of your choosing and run:
porter create --debug
This command will create the basics, which consists of 5 files.
.README.md –> gives some information about the files that have been deployed
.dockerignore –> a file that controls which files can get copied in to a docker container
.gitignore –> like above, but for git
porter.yaml –> the main file for defining the packages
Dockerfile.tmpl –> a template of a custom docker file, should you need it (this is used to create the image that creates the image)
The basic porter file basically executes a container that echos “hello world” to the console. (Yay!)
Running the next command in debug mode will give you an idea of what it is doing.
porter build --debug
What you can see from the output is the following:
Cool, so now we have a working project. There are a couple of other important steps that happen during the build phase, and you can read about it here.
At this point, you can install the bundle and watch it execute.
porter install --debug
You should see a “Hello World” appear followed by a “execution completed successfully”. Congratulations, you’ve just created and run your first CNAB bundle.
Note on directory for install
As I mentioned above, by default porter installs to your home directory. On my windows machine, I am logged in with my Azure AD credentials. This posed a problem when I tried to mount my host drive in docker, which forced me to create a local account to facilitate that task. Of course, that user does not have access to my home directory, and was not able to execute the porter install step. This is why you will want to edit the install location for porter.
Shamir is a Microsoft Most Valuable Professional (MVP – Azure) and has extensive experience building solutions in the cloud, from strategy to deployment to automation