-
Notifications
You must be signed in to change notification settings - Fork 4
/
podman-desktop
executable file
·172 lines (141 loc) · 4.56 KB
/
podman-desktop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/zsh
set -e
show_help() {
echo >&2 "podman-desktop
--name <name=podman> virtual machine name
--identity <path=~/.ssh/podman> user ssh key
<image=20.04> ubuntu identifier (see multipass fetch)
-- separator to pass options to `multipass launch`
--cpus <#=1> # of cpus
--mem <size=1G> amount of memeory
--disk <size=5G> disk size
--network see multipass launch --help
"
}
die() {
echo >&2 "$@"
exit 1
}
install_cmd() {
set +e
if [ -z "$(command -v brew)" ]; then
echo "# Install homebrew for easier MacOS management\n"
# shellcheck disable=SC2016
echo ' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"'
fi
set -e
echo "brew install $1"
}
validate() {
cmd=$1
if [ ! -x "$(command -v "$cmd")" ]; then
echo "ERROR: \`$cmd\` command not found. Please install $cmd." >&2
echo "Instructions are:"
install_cmd "$cmd"
exit 1
fi
}
validate "podman"
validate "multipass"
while [ $# -gt 0 ]; do
key="$1"
case $key in
-h|--help)
show_help; exit ;;
-n|--name)
INSTANCE_NAME="$2"; shift 2 ;;
-i|--identity)
IDENTITY="$2"; shift 2 ;;
--) shift ; break ;;
*)
[ -n "$VERSION_ID" ] && die "already set version"
VERSION_ID="$1"; shift ;;
esac
done
INSTANCE_NAME="${INSTANCE_NAME:-podman}"
IDENTITY="${IDENTITY:-$HOME/.ssh/podman}"
PUBKEYFILE=${IDENTITY}.pub
VERSION_ID="${VERSION_ID:-20.04}"
MOUNTS=${MOUNTS-/Users /Volumes /private /tmp /var/folders} # Docker Desktop Defaults
test -f "$IDENTITY" || die "cannot find identity $IDENTITY"
test -f "$PUBKEYFILE" || die "cannot find pubkey $PUBKEYFILE"
PUBKEY=$(cat "$PUBKEYFILE")
PRIMARY=$(multipass get client.primary-name)
if [ "$PRIMARY" != "$INSTANCE_NAME" ] && [ "$PRIMARY" != "primary" ]; then
die "client.primary-name already set ($PRIMARY) for multipass"
fi
if ! pgrep multipassd 1>/dev/null 2>/dev/null; then
echo multipassd not running, please run the following command and try again
echo
echo sudo launchctl start com.canonical.multipassd
exit 1
fi
multipass set client.primary-name="$INSTANCE_NAME"
echo >&2 "this may take a while - to view progress:
multipass exec $INSTANCE_NAME -- tail -f /var/log/cloud-init-output.log
"
echo "
users:
- name: ubuntu
ssh-authorized-keys:
- ${PUBKEY}
apt:
preserve_sources_list: true
sources:
libcontainers.list:
source: \"deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /\"
keyid: 4D64390375060AA4
package_upgrade: true
packages:
- podman
- containerd
- fuse-overlayfs
write_files:
- path: /lib/systemd/system/buildkitd.service
owner: root:root
permissions: \"0755\"
content: |
[Unit]
Description=Buildkitd
After=network.target
[Service]
Type=simple
ExecStart=/opt/buildkit/bin/buildkitd --addr tcp://0.0.0.0:1234
[Install]
WantedBy=multi-user.target
runcmd:
- systemctl daemon-reload
- mkdir /opt/buildkit
- cd /opt/buildkit
- curl -L https://github.com/moby/buildkit/releases/download/v0.9.3/buildkit-v0.9.3.linux-amd64.tar.gz > buildkit.tar.gz
- tar -xvf buildkit.tar.gz
- systemctl daemon-reload
- sudo systemctl enable --now buildkitd.service
- sudo systemctl start buildkitd.service
" | multipass launch \
--name "${INSTANCE_NAME}" \
--cloud-init - \
"$@" \
"${VERSION_ID}"
multipass exec "$INSTANCE_NAME" -- systemctl --user enable --now podman.socket
multipass exec "$INSTANCE_NAME" -- sudo loginctl enable-linger ubuntu
multipass exec "$INSTANCE_NAME" -- sudo systemctl enable --now ssh.service
IP=$(multipass info "${INSTANCE_NAME}" | grep IPv4: | cut -d ':' -f2 | tr -ds ' ' '')
CONNECTION=ssh://ubuntu@"${IP}"/run/user/1000/podman/podman.sock
_IDENTITY=$(podman system connection list --format '{{.URI}} {{.Name}}' | grep "$CONNECTION" | cut -d' ' -f2)
if [ "$_IDENTITY" ]; then echo "podman has a connection named $_IDENTITY"; else
podman system connection add "$INSTANCE_NAME" --identity "${IDENTITY}" "$CONNECTION"
fi
for mount in $MOUNTS; do multipass mount "$mount" "$INSTANCE_NAME"; done
printf "%s\n" "$INSTANCE_NAME"
echo >&2 "You may want to add the following to your ~/.ssh/config:
Host podman
Hostname ${IP}
User ubuntu
"
echo >&2 "To remove:
podman system connection remove \"$INSTANCE_NAME\"
multipass stop \"$INSTANCE_NAME\"
multipass delete \"$INSTANCE_NAME\"
multipass purge
"