Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Last active July 15, 2024 20:03
Show Gist options
  • Save pythoninthegrass/7e9b3a8046b78a3bc8034f6aff29d1e9 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/7e9b3a8046b78a3bc8034f6aff29d1e9 to your computer and use it in GitHub Desktop.
# https://github.com/lima-vm/lima/blob/master/examples/docker-rootful.yaml
---
images:
# Hint: run `limactl prune` to invalidate the "current" cache
- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240423/ubuntu-24.04-server-cloudimg-amd64.img"
arch: "x86_64"
digest: "sha256:32a9d30d18803da72f5936cf2b7b9efcb4d0bb63c67933f17e3bdfd1751de3f3"
- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240423/ubuntu-24.04-server-cloudimg-arm64.img"
arch: "aarch64"
digest: "sha256:c841bac00925d3e6892d979798103a867931f255f28fefd9d5e07e3e22d0ef22"
# Fallback to the latest release image.
- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
arch: "aarch64"
# https://lima-vm.io/docs/config/
vmType: vz
cpus: 2 # default: 4
memory: 4GiB # default: 4GiB
disk: 30GiB # default: 100GiB
networks:
- lima: shared
interface: en0
mountType: virtiofs
mounts:
- location: "~"
writable: true
- location: "/tmp/lima"
writable: true
portForwards:
- guestPortRange:
- 1
- 65535
hostIP: 0.0.0.0
- guestSocket: "/var/run/docker.sock"
hostSocket: "{{.Dir}}/sock/docker.sock"
hostResolver:
hosts:
host.docker.internal: host.lima.internal
rosetta:
enabled: true
binfmt: true
containerd:
system: false
user: false
provision:
- mode: system
script: |
#!/bin/bash
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
- mode: system
script: |
#!/bin/bash
set -eux -o pipefail
command -v docker >/dev/null 2>&1 && exit 0
if [ ! -e /etc/systemd/system/docker.socket.d/override.conf ]; then
mkdir -p /etc/systemd/system/docker.socket.d
# Alternatively we could just add the user to the "docker" group, but that requires restarting the user session
cat <<-EOF >/etc/systemd/system/docker.socket.d/override.conf
[Socket]
SocketUser={{.User}}
EOF
fi
export DEBIAN_FRONTEND=noninteractive
curl -fsSL https://get.docker.com | sh
probes:
- script: |
#!/bin/bash
set -eux -o pipefail
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
echo >&2 "docker is not installed yet"
exit 1
fi
if ! timeout 30s bash -c "until pgrep dockerd; do sleep 3; done"; then
echo >&2 "dockerd is not running"
exit 1
fi
hint: |
See "/var/log/cloud-init-output.log" in the guest
message: |
To run `docker` on the host (assumes docker-cli is installed), run the following commands:
------
docker context create lima-{{.Name}} --docker "host=unix://{{.Dir}}/sock/docker.sock"
docker context use lima-{{.Name}}
docker run hello-world
------
# limactl start ubuntu-2004.yml --tty=false
---
images:
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
- location: "https://cloud-images.ubuntu.com/releases/focal/release-20240513/ubuntu-20.04-server-cloudimg-amd64.img"
arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/releases/focal/release-20240513/ubuntu-20.04-server-cloudimg-arm64.img"
arch: "aarch64"
# Fallback to the latest release image.
# Hint: run `limactl prune` to invalidate the cache
- location: "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img"
arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-arm64.img"
arch: "aarch64"
# https://lima-vm.io/docs/config/
vmType: vz
cpus: 2 # default: 4
memory: 2GiB # default: 4GiB
disk: 30GiB # default: 100GiB
networks:
- lima: shared
interface: en0
mountType: virtiofs
mounts:
- location: "~"
writable: true
- location: "/tmp/lima"
writable: true
provision:
- mode: system
script: |
#!/bin/bash
set -eux -o pipefail
command -v pip >/dev/null 2>&1 && exit 0
export DEBIAN_FRONTEND=noninteractive
sudo apt install -yqq --no-install-recommends \
build-essential \
python3-dev \
python3-pip
- mode: system
script: |
#!/bin/bash
set -eux -o pipefail
command -v ansible >/dev/null 2>&1 && exit 0
export PIP_NO_CACHE_DIR=off
export PIP_DISABLE_PIP_VERSION_CHECK=on
export PIP_NO_WARN_SCRIPT_LOCATION=true
python3 -m pip install ansible ansible-lint
probes:
- script: |
#!/bin/bash
set -eux -o pipefail
export PATH="$HOME/.local/bin:/usr/local/bin:$PATH"
if ! timeout 30s bash -c "until command -v pip >/dev/null 2>&1; do sleep 3; done"; then
echo >&2 "pip is not installed yet"
exit 1
fi
if ! timeout 30s bash -c "until command -v ansible >/dev/null 2>&1; do sleep 3; done"; then
echo >&2 "ansible is not installed yet"
exit 1
fi
hint: |
See "/var/log/cloud-init-output.log" in the guest
message: |
To test ansible's connection from the host, run the following commands:
------
guestip=$(limactl shell ubuntu-2004 ip a show en0 | awk '/inet/ {print $2; exit}' | cut -d/ -f1)
ansible all -i $guestip, -m ping -u lima
------
@pythoninthegrass
Copy link
Author

Moved to a repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment