Last active
September 2, 2021 14:14
-
-
Save jedahan/e716a938bb9fe4f9782bcf6ebb650ed9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
command -v multipass 2>/dev/null || die "missing multipass" | |
command -v podman 2>/dev/null || die "missing podman" | |
INSTANCE_NAME="podman" | |
VERSION_ID="20.04" | |
IDENTITY="${IDENTITY:-~/.ssh/id_rsa}" | |
PUBKEYFILE=${PUBKEY:-${IDENTITY}.pub} | |
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}) | |
multipass set client.primary-name=$INSTANCE_NAME | |
cat <<<EOF | |
--- | |
users: | |
- name: ubuntu | |
- ssh-authorized-keys: [ ${PUBKEY} ] | |
apt: | |
sources: | |
libcontainers: | |
source: "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | |
package_upgrade: true | |
packages: ['containerd', 'fuse-overlayfs', 'podman'] | |
runcmd: | |
- systemctl --user enable --now podman.socket | |
- sudo loginctl enable-linger $USER | |
- sudo systemctl enable --now ssh.service | |
EOF | \ | |
multipass launch \ | |
--cpus 2 \ | |
--memory 2G \ | |
--disk 10G \ | |
--name ${INSTANCE_NAME} \ | |
--cloud-init - \ | |
${VERSION_ID} | |
IP=$(multipass info ${INSTANCE_NAME} | grep IPv4: | cut -d ':' -f2 | tr -ds ' ' '') | |
podman system connection add $INSTANCE_NAME --identity "${IDENTITY}" ssh://ubuntu@"${IP}"/run/user/1000/podman/podman.sock | |
for mount in $MOUNTS; do multipass mount "$mount" $INSTANCE_NAME; done | |
multipass list | |
podman system connection list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment