Skip to content

Commit 248fc44

Browse files
authored
Merge pull request #213 from crazy-max/switch-to-lima
docker(install): switch to lima
2 parents 5bc270d + c1ecc4b commit 248fc44

5 files changed

Lines changed: 166 additions & 220 deletions

File tree

__tests__/docker/install.test.itg.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ describe('install', () => {
2929
jest.resetModules();
3030
process.env = {
3131
...originalEnv,
32-
SIGN_QEMU_BINARY: '1',
33-
COLIMA_START_ARGS: '--cpu 4 --memory 8 --disk 32'
32+
LIMA_START_ARGS: '--cpus 4 --memory 8'
3433
};
3534
});
3635
afterEach(() => {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"async-retry": "^1.3.3",
5858
"csv-parse": "^5.5.2",
5959
"handlebars": "^4.7.8",
60-
"js-yaml": "^4.1.0",
6160
"jwt-decode": "^4.0.0",
6261
"semver": "^7.5.4",
6362
"tmp": "^0.2.1"

src/docker/assets.ts

Lines changed: 116 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export const dockerServiceLogsPs1 = (): string => {
2525
return get('docker-service-logs.ps1', dockerServiceLogsPs1Data);
2626
};
2727

28-
export const colimaYaml = (): string => {
29-
return get('colima.yaml', colimaYamlData);
28+
export const limaYaml = (): string => {
29+
return get('lima.yaml', limaYamlData);
3030
};
3131

3232
const get = (filename: string, data: string, mode?: string): string => {
@@ -128,174 +128,122 @@ Get-WinEvent -ea SilentlyContinue \`
128128
ForEach-Object {"$($_.TimeCreated.ToUniversalTime().ToString("o")) [$($_.LevelDisplayName)] $($_.Message)"}
129129
`;
130130

131-
export const colimaYamlData = `
132-
# Number of CPUs to be allocated to the virtual machine.
133-
# Default: 2
134-
cpu: 2
135-
136-
# Size of the disk in GiB to be allocated to the virtual machine.
137-
# NOTE: changing this has no effect after the virtual machine has been created.
138-
# Default: 60
139-
disk: 60
140-
141-
# Size of the memory in GiB to be allocated to the virtual machine.
142-
# Default: 2
143-
memory: 2
144-
145-
# Architecture of the virtual machine (x86_64, aarch64, host).
146-
# Default: host
147-
arch: host
148-
149-
# Container runtime to be used (docker, containerd).
150-
# Default: docker
151-
runtime: docker
152-
153-
# Kubernetes configuration for the virtual machine.
154-
kubernetes:
155-
enabled: false
156-
157-
# Auto-activate on the Host for client access.
158-
# Setting to true does the following on startup
159-
# - sets as active Docker context (for Docker runtime).
160-
# - sets as active Kubernetes context (if Kubernetes is enabled).
161-
# Default: true
162-
autoActivate: false
163-
164-
# Network configurations for the virtual machine.
165-
network:
166-
# Assign reachable IP address to the virtual machine.
167-
# NOTE: this is currently macOS only and ignored on Linux.
168-
# Default: false
169-
address: false
170-
171-
# Custom DNS resolvers for the virtual machine.
172-
#
173-
# EXAMPLE
174-
# dns: [8.8.8.8, 1.1.1.1]
175-
#
176-
# Default: []
177-
dns: []
178-
179-
# DNS hostnames to resolve to custom targets using the internal resolver.
180-
# This setting has no effect if a custom DNS resolver list is supplied above.
181-
# It does not configure the /etc/hosts files of any machine or container.
182-
# The value can be an IP address or another host.
183-
#
184-
# EXAMPLE
185-
# dnsHosts:
186-
# example.com: 1.2.3.4
187-
dnsHosts:
188-
host.docker.internal: host.lima.internal
189-
190-
# Forward the host's SSH agent to the virtual machine.
191-
# Default: false
192-
forwardAgent: false
193-
194-
# Docker daemon configuration that maps directly to daemon.json.
195-
# https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file.
196-
# NOTE: some settings may affect Colima's ability to start docker. e.g. \`hosts\`.
197-
#
198-
# EXAMPLE - disable buildkit
199-
# docker:
200-
# features:
201-
# buildkit: false
202-
#
203-
# EXAMPLE - add insecure registries
204-
# docker:
205-
# insecure-registries:
206-
# - myregistry.com:5000
207-
# - host.docker.internal:5000
208-
#
209-
# Colima default behaviour: buildkit enabled
210-
# Default: {}
211-
{{daemonConfig}}
212-
213-
# Virtual Machine type (qemu, vz)
214-
# NOTE: this is macOS 13 only. For Linux and macOS <13.0, qemu is always used.
215-
#
216-
# vz is macOS virtualization framework and requires macOS 13
217-
#
218-
# Default: qemu
131+
export const limaYamlData = `
132+
# VM type: "qemu" or "vz" (on macOS 13 and later).
133+
# The vmType can be specified only on creating the instance.
134+
# The vmType of existing instances cannot be changed.
135+
# Builtin default: "qemu"
219136
vmType: qemu
220137
221-
# Volume mount driver for the virtual machine (virtiofs, 9p, sshfs).
222-
#
223-
# virtiofs is limited to macOS and vmType \`vz\`. It is the fastest of the options.
224-
#
225-
# 9p is the recommended and the most stable option for vmType \`qemu\`.
226-
#
227-
# sshfs is faster than 9p but the least reliable of the options (when there are lots
228-
# of concurrent reads or writes).
229-
#
230-
# Default: virtiofs (for vz), sshfs (for qemu)
231-
mountType: 9p
232-
233-
# The CPU type for the virtual machine (requires vmType \`qemu\`).
234-
# Options available for host emulation can be checked with: \`qemu-system-$(arch) -cpu help\`.
235-
# Instructions are also supported by appending to the cpu type e.g. "qemu64,+ssse3".
236-
# Default: host
237-
cpuType: host
238-
239-
# Custom provision scripts for the virtual machine.
240-
# Provisioning scripts are executed on startup and therefore needs to be idempotent.
241-
#
242-
# EXAMPLE - script exected as root
243-
# provision:
244-
# - mode: system
245-
# script: apk add htop vim
246-
#
247-
# EXAMPLE - script exected as user
248-
# provision:
249-
# - mode: user
250-
# script: |
251-
# [ -f ~/.provision ] && exit 0;
252-
# echo provisioning as $USER...
253-
# touch ~/.provision
254-
#
255-
# Default: []
138+
# OS: "Linux".
139+
# Builtin default: "Linux"
140+
os: null
141+
142+
# Arch: "default", "x86_64", "aarch64".
143+
# Builtin default: "default" (corresponds to the host architecture)
144+
arch: null
145+
146+
images:
147+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20231026/ubuntu-22.04-server-cloudimg-amd64.img"
148+
arch: "x86_64"
149+
digest: "sha256:054db2d88c454bb0ad8dfd8883955e3946b57d2b0bf0d023f3ade3c93cdd14e5"
150+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20231026/ubuntu-22.04-server-cloudimg-arm64.img"
151+
arch: "aarch64"
152+
digest: "sha256:eafa7742ce5ff109222ea313d31ea366d587b4e89b900b11d8285ae775dfe8c3"
153+
154+
# CPUs
155+
# Builtin default: min(4, host CPU cores)
156+
cpus: null
157+
158+
# Memory size
159+
# Builtin default: min("4GiB", half of host memory)
160+
memory: null
161+
162+
# Disk size
163+
# Builtin default: "100GiB"
164+
disk: 60GiB
165+
166+
# Expose host directories to the guest, the mount point might be accessible from all UIDs in the guest
167+
# Builtin default: null (Mount nothing)
168+
# This file: Mount the home as read-only, /tmp/lima as writable
169+
mounts:
170+
- location: "~"
171+
- location: "/tmp/lima"
172+
writable: true
173+
174+
# Mount type for above mounts, such as "reverse-sshfs" (from sshocker), "9p" (EXPERIMENTAL, from QEMU’s virtio-9p-pci, aka virtfs),
175+
# or "virtiofs" (EXPERIMENTAL, needs \`vmType: vz\`)
176+
# Builtin default: "reverse-sshfs" (for QEMU), "virtiofs" (for vz)
177+
mountType: null
178+
179+
containerd:
180+
system: false
181+
user: false
182+
256183
provision:
257-
- mode: system
258-
script: |
259-
wget -qO- "https://download.docker.com/linux/static/{{dockerBinChannel}}/{{dockerBinArch}}/docker-{{dockerBinVersion}}.tgz" | tar xvz --strip 1 -C /usr/bin/
260-
261-
# Modify ~/.ssh/config automatically to include a SSH config for the virtual machine.
262-
# SSH config will still be generated in ~/.colima/ssh_config regardless.
263-
# Default: true
264-
sshConfig: false
265-
266-
# Configure volume mounts for the virtual machine.
267-
# Colima mounts user's home directory by default to provide a familiar
268-
# user experience.
269-
#
270-
# EXAMPLE
271-
# mounts:
272-
# - location: ~/secrets
273-
# writable: false
274-
# - location: ~/projects
275-
# writable: true
276-
#
277-
# Colima default behaviour: $HOME and /tmp/colima are mounted as writable.
278-
# Default: []
279-
mounts: []
280-
281-
# Environment variables for the virtual machine.
282-
#
283-
# EXAMPLE
284-
# env:
285-
# KEY: value
286-
# ANOTHER_KEY: another value
287-
#
288-
# Default: {}
289-
env: {}
290-
`;
184+
- mode: system
185+
# This script defines the host.docker.internal hostname when hostResolver is disabled.
186+
# It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts.
187+
# Names defined in /etc/hosts inside the VM are not resolved inside containers when
188+
# using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later).
189+
script: |
190+
#!/bin/sh
191+
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
192+
- mode: system
193+
script: |
194+
#!/bin/sh
195+
apt-get install -f -y iptables
196+
- mode: system
197+
script: |
198+
#!/bin/bash
199+
set -eux -o pipefail
200+
command -v docker >/dev/null 2>&1 && exit 0
201+
if [ ! -e /etc/systemd/system/docker.socket.d/override.conf ]; then
202+
mkdir -p /etc/systemd/system/docker.socket.d
203+
# Alternatively we could just add the user to the "docker" group, but that requires restarting the user session
204+
cat <<-EOF >/etc/systemd/system/docker.socket.d/override.conf
205+
[Socket]
206+
SocketUser=\${LIMA_CIDATA_USER}
207+
EOF
208+
fi
209+
if [ ! -e /etc/docker/daemon.json ]; then
210+
mkdir -p /etc/docker
211+
cat <<-EOF >/etc/docker/daemon.json
212+
{{stringify daemonConfig}}
213+
EOF
214+
fi
215+
export DEBIAN_FRONTEND=noninteractive
216+
curl -fsSL https://get.docker.com | sh -s -- --channel {{dockerBinChannel}} --version {{dockerBinVersion}}
217+
218+
probes:
219+
- script: |
220+
#!/bin/bash
221+
set -eux -o pipefail
222+
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
223+
echo >&2 "docker is not installed yet"
224+
exit 1
225+
fi
226+
if ! timeout 30s bash -c "until pgrep dockerd; do sleep 3; done"; then
227+
echo >&2 "dockerd is not running"
228+
exit 1
229+
fi
230+
hint: See "/var/log/cloud-init-output.log". in the guest
231+
232+
hostResolver:
233+
# hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also
234+
# resolve inside containers, and not just inside the VM itself.
235+
hosts:
236+
host.docker.internal: host.lima.internal
291237
292-
export const qemuEntitlements = `
293-
<?xml version="1.0" encoding="UTF-8"?>
294-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
295-
<plist version="1.0">
296-
<dict>
297-
<key>com.apple.security.hypervisor</key>
298-
<true/>
299-
</dict>
300-
</plist>
238+
portForwards:
239+
- guestSocket: "/var/run/docker.sock"
240+
hostSocket: "{{dockerSock}}"
241+
242+
audio:
243+
# EXPERIMENTAL
244+
# QEMU audiodev, e.g., "none", "coreaudio", "pa", "alsa", "oss".
245+
# VZ driver, use "vz" as device name
246+
# Choosing "none" will mute the audio output, and not play any sound.
247+
# Builtin default: ""
248+
device: none
301249
`;

0 commit comments

Comments
 (0)