Skip to content

Commit bb40261

Browse files
committed
feat ✨ (podman): implement podman functions (#40)
Signed-off-by: Luis Mayta <luis@hadenlabs.com>
1 parent 32191f8 commit bb40261

10 files changed

Lines changed: 112 additions & 14 deletions

File tree

config/base.zsh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# -*- coding: utf-8 -*-
33

44
export ZSH_DOCKER_PACKAGE_NAME=docker
5-
export DOCKER_MESSAGE_BREW="Please install brew or use antibody bundle hadenlabs/zsh-brew"
6-
export DOCKER_MESSAGE_YAY="Please install Go or use antibody bundle hadenlabs/zsh-goenv"
7-
export DOCKER_MESSAGE_RVM="Please install rvm or use antibody bundle hadenlabs/zsh-rvm"
8-
export DOCKER_MESSAGE_NVM="Please install nvm or use antibody bundle hadenlabs/zsh-nvm"
5+
export ZSH_DOCKER_CONTAINER_APP_NAME="podman"
6+
export ZSH_DOCKER_PODMAN_MACHINE_NAME="podman-machine-default"
7+
export ZSH_DOCKER_MESSAGE_BREW="Please install brew or use antibody bundle hadenlabs/zsh-brew"
8+
export ZSH_DOCKER_MESSAGE_YAY="Please install Go or use antibody bundle hadenlabs/zsh-goenv"
9+
export ZSH_DOCKER_MESSAGE_RVM="Please install rvm or use antibody bundle hadenlabs/zsh-rvm"
10+
export ZSH_DOCKER_MESSAGE_NVM="Please install nvm or use antibody bundle hadenlabs/zsh-nvm"

config/docker.zsh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env ksh
2+
# -*- coding: utf-8 -*-
3+
4+
function container::core {
5+
alias docker=docker
6+
}

config/main.zsh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ function docker::config::main::factory {
1414
source "${ZSH_DOCKER_PATH}"/config/linux.zsh
1515
;;
1616
esac
17+
18+
case "${ZSH_DOCKER_CONTAINER_APP_NAME}" in
19+
podman*)
20+
# shellcheck source=/dev/null
21+
source "${ZSH_DOCKER_PATH}"/config/podman.zsh
22+
;;
23+
docker*)
24+
# shellcheck source=/dev/null
25+
source "${ZSH_DOCKER_PATH}"/config/docker.zsh
26+
;;
27+
esac
1728
}
1829

19-
docker::config::main::factory
30+
docker::config::main::factory
31+
container::core

config/podman.zsh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env ksh
2+
# -*- coding: utf-8 -*-
3+
4+
function container::core {
5+
alias docker=podman
6+
}

internal/base.zsh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,4 @@ function docker::internal::container::stop::dangling {
7474

7575
function docker::internal::network::delete::all {
7676
docker network ls -q | xargs docker network rm -f
77-
}
78-
79-
function docker::internal::install {
80-
message_info "Installing ${ZSH_DOCKER_PACKAGE_NAME}"
81-
core::install orbstack
82-
message_success "Installed ${ZSH_DOCKER_PACKAGE_NAME}"
8377
}

internal/docker.zsh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ksh
2+
# -*- coding: utf-8 -*-
3+
4+
function container::internal::container::install {
5+
if core::exists docker; then
6+
return
7+
fi
8+
message_info "Installing ${ZSH_DOCKER_PACKAGE_NAME}"
9+
core::install docker
10+
message_success "Installed ${ZSH_DOCKER_PACKAGE_NAME}"
11+
}
12+
13+
function container::internal::container::load {
14+
return
15+
}

internal/helper.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env ksh
2-
# -*- coding: utf-8 -*-
2+
# -*- coding: utf-8 -*-

internal/main.zsh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@ function docker::internal::main::factory {
1414
source "${ZSH_DOCKER_PATH}"/internal/linux.zsh
1515
;;
1616
esac
17+
18+
case "${ZSH_DOCKER_CONTAINER_APP_NAME}" in
19+
podman*)
20+
# shellcheck source=/dev/null
21+
source "${ZSH_DOCKER_PATH}"/internal/podman.zsh
22+
;;
23+
docker*)
24+
# shellcheck source=/dev/null
25+
source "${ZSH_DOCKER_PATH}"/internal/docker.zsh
26+
;;
27+
esac
1728
# shellcheck source=/dev/null
1829
source "${ZSH_DOCKER_PATH}"/internal/helper.zsh
1930
}
2031

2132
docker::internal::main::factory
2233

23-
if ! core::exists docker; then docker::internal::install; fi
34+
container::internal::container::install
35+
container::internal::container::load

internal/podman.zsh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env ksh
2+
# -*- coding: utf-8 -*-
3+
4+
function container::internal::container::install {
5+
if core::exists podman; then
6+
return
7+
fi
8+
message_info "Installing ${ZSH_DOCKER_PACKAGE_NAME}"
9+
core::install podman
10+
message_success "Installed ${ZSH_DOCKER_PACKAGE_NAME}"
11+
}
12+
13+
function container::internal::container::load {
14+
set -euo pipefail
15+
16+
local machine_name="${ZSH_DOCKER_PODMAN_MACHINE_NAME:-podman-machine-default}"
17+
18+
# Check if jq is installed
19+
if ! command -v jq >/dev/null 2>&1; then
20+
echo "❌ 'jq' is required but not installed. Please install it with: brew install jq"
21+
return 1
22+
fi
23+
24+
# Check if the Podman machine exists
25+
if ! podman machine list | grep -q "${machine_name}"; then
26+
echo "🔧 Podman machine '${machine_name}' not found. Initializing..."
27+
podman machine init --now --name "${machine_name}"
28+
return
29+
fi
30+
31+
# Check if the machine is running
32+
local running
33+
running=$(podman machine list --format json | jq -r \
34+
--arg name "$machine_name" '.[] | select(.Name == $name) | .Running')
35+
36+
if [[ "${running}" != "true" ]]; then
37+
echo "🚀 Podman machine '${machine_name}' exists but is not running. Starting..."
38+
podman machine start "${machine_name}"
39+
else
40+
echo "✅ Podman machine '${machine_name}' is already running."
41+
fi
42+
}

provision/templates/README.tpl.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@
4545
{{ if has (ds "config") "features" }}
4646

4747
## Features
48+
4849
{{ range $feature := (ds "config").features }}{{printf "- %s\n" $feature}}{{ end }}
50+
4951
{{ end }}
5052

53+
{{ if has (ds "config") "modules" }}
54+
55+
## Modules
56+
57+
{{ range $module := (ds "config").modules }}{{printf "- %s\n" $module}}{{ end }} {{ end }}
58+
5159
{{ if has (ds "config") "introduction" }}
5260

5361
## Introduction
@@ -127,7 +135,8 @@ For additional context, refer to some of these links.
127135

128136
## Help
129137

130-
**Got a question?**
138+
### Got a question?
139+
131140
{{ if has (ds "config") "github_repo" }}
132141
File a GitHub [issue]({{ printf "https://github.com/%s/issues" (ds "config").github_repo}}).
133142
{{ else if has (ds "config") "gitlab_host" }}

0 commit comments

Comments
 (0)