# Cloud Native Buildpacks on Podman
#### What is Cloud Native Buildpacks?
<!-- TODO -->
#### What is Podman?
To quote from the official documentation:
> Podman is a daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative (OCI) Containers and Container Images.
It can be used as a standalone daemonless CLI with sub-commands and flags almost identical the standard `docker` CLI. You can even alias `docker=podman` and everything should work as expected.
Beside running as a standalone daemonles CLI `podman` can also serve as a `docker` API daemon using `pomdan system service` sub-command. You just need to set the `DOCKER_HOST` environment and most applications will pick it up (`pack` is one of them).
While `podman` is native to Linux you still can enjoy it on `macOS` using virtual machine. There is sub-command `podman machine` facilitating VM creation making it really easy.
## Setup
You will need:
* `podman v3.3.0` or newer
* `pack v0.22.0` or newer
### macOS
#### Installation
```shell=zsh
brew install podman
```
#### Virtual Machine
##### 1. Init

```shell=zsh
podman machine init --cpus=2 --disk-size=30 --memory=8192
```
Where:
- `--cpus` is the number of CPUs we'll allocate to the VM.
- `--disk-size` is the amount of disk space we'll give the VM. (GBs)
- `--memory` is the amount of memory we'll allocate to the VM. (MBs)
##### 2. Start

```shell=zsh
podman machine start
```
#### Connection

<!-- TODO: Describe what is happening -->
1. Add the SSH key for the podman VM to your keychain:
```shell=zsh
ssh-add -k "$HOME/.ssh/podman-machine-default"
```
2. Configure `DOCKER_HOST` with the connection information:
```shell=zsh
export DOCKER_HOST="$(podman system connection ls --format="{{.URI}}" | grep root)"
```
**Tip**: put the commands into your shell init file (e.g `~/.zshrc`).
### Fedora
#### Installation
```shell
sudo dnf -y install podman
```
For installation on other distributions check out [offical documentation](https://podman.io/getting-started/installation#linux-distributions).
#### Service
Expose the service using `systemd`:
```shell
systemctl enable --user podman.socket
systemctl start --user podman.socket
```
#### Connection
```shell
export DOCKER_HOST="unix://$(podman info -f "{{.Host.RemoteSocket.Path}}")"
```
**Tip**: put the command into your shell init file (e.g `~/.bashrc`).
# Usage
## Build
### Source

```shell=bash
git clone https://github.com/buildpacks/samples
```
### `pack build`

```shell=bash
pack build sample-app -p samples/apps/ruby-bundler/ -B cnbs/sample-builder:bionic
```
Where:
- `sample-app` is the image name of the image to be created.
- `-p` is the **path** to the application source.
- `-B` is the **[builder][builder]** to use.
### Results

```shell=bash
podman images
```
[builder]: https://buildpacks.io/docs/concepts/components/builder/
# Known Issues & Limitations
* On `macOS` bind mounts do not work since the VM cannot access host file system.
* With more time consuming builds and `--trust-builder=true` following error may occur:
```
ERROR: failed to image: error during connect: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.40/info": EOF
```
There is a workaround for this, increase timeout of podman service:
```shell=bash
cat <<EOF > /etc/systemd/user/podman.service
[Unit]
Description=Podman API Service
Requires=podman.socket
After=podman.socket
Documentation=man:podman-system-service(1)
StartLimitIntervalSec=0
[Service]
Type=exec
KillMode=process
Environment=LOGGING="--log-level=info"
ExecStart=/usr/bin/podman $LOGGING system service --time=1800
[Install]
WantedBy=multi-user.target
EOF
systemctl --user daemon-reload
systemctl restart --user podman.socket
```
On `macOS` you need to run this in the VM (use `podman machine ssh`).