Skip to content

Commit 2a45e5a

Browse files
committed
add lima templates
Signed-off-by: pco <pasquale.convertini@ibm.com>
1 parent e523663 commit 2a45e5a

File tree

6 files changed

+246
-16
lines changed

6 files changed

+246
-16
lines changed

.env

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ export LANG="en_US.UTF-8"
55
export LANGUAGE="en_US.UTF-8"
66
export LC_ALL="en_US.UTF-8"
77

8-
# Ansible
9-
export ANSIBLE_HOST_KEY_CHECKING=false
10-
if [ -d "${HOME}/.asdf/shims/python3" ]; then
11-
export ANSIBLE_PYTHON_INTERPRETER="${HOME}/.asdf/shims/python3"
12-
fi
13-
export LOCAL_ANSIBLE_HOST="host.docker.internal"
14-
158
# For React-Native on iOS
169
export NO_FLIPPER=1
1710

@@ -43,17 +36,15 @@ if [ -f "${HOME}/.cargo/env" ]; then
4336
source "${HOME}/.cargo/env"
4437
fi
4538

46-
### PATH for Travis
47-
if [ -f "${HOME}/.travis/travis.sh" ]; then
48-
source "${HOME}/.travis/travis.sh"
49-
fi
50-
5139
# Path for Go
5240
if [ -d "${HOME}/go" ]; then
5341
export GOPATH="${HOME}/go"
5442
export PATH="${PATH}:$GOPATH/bin"
5543
fi
5644

45+
# Add .local/bin to PATH
46+
export PATH="${PATH}:${HOME}/.local/bin"
47+
5748
# Path for brew
5849
if (command -v brew >/dev/null 2>&1); then
5950
eval "$(brew shellenv)"
@@ -66,8 +57,12 @@ elif [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then
6657
fi
6758

6859
# Path for asdf
69-
if [ -d "${HOME}/.asdf/shims" ]; then
70-
export PATH="${HOME}/.asdf/shims:${PATH}"
60+
export PATH="${HOME}/.asdf/shims:${PATH}"
61+
62+
# Ansible
63+
export ANSIBLE_HOST_KEY_CHECKING=false
64+
if [ -f "${HOME}/.asdf/shims/python3" ]; then
65+
export ANSIBLE_PYTHON_INTERPRETER="${HOME}/.asdf/shims/python3"
7166
fi
7267

7368
# set var to tell the env has been sourced

.functions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ ollama-unload() {
293293
curl -s -X POST -H "Content-Type: application/json" -d "$payload" "$url"
294294
}
295295

296+
# Open an x509 certificate
296297
opencert() {
297298
if [[ -z "$1" ]]; then
298299
echo "Usage: opencert <path-to-cert>"

.lima/templates/fedora.yaml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
minimumLimaVersion: 1.1.0
2+
3+
# VM settings
4+
cpus: 4
5+
memory: "16GiB"
6+
disk: "100GiB"
7+
8+
# Templates to use as base
9+
base:
10+
- template://_images/fedora-41
11+
12+
# Writable mounts override
13+
mounts:
14+
- location: "~"
15+
writable: true
16+
17+
# Disable containerd
18+
containerd:
19+
system: false
20+
user: false
21+
22+
# Provision scripts to setup the VM
23+
provision:
24+
# System-level setup (runs as root)
25+
- mode: system
26+
script: |
27+
#!/bin/bash
28+
set -eux -o pipefail
29+
30+
# Check if already provisioned
31+
test -e /etc/lima-fedora-system-provision && exit 0
32+
33+
# Update system packages
34+
# dnf -y update
35+
36+
# Install development tools
37+
dnf -y install \
38+
runc \
39+
vim \
40+
make \
41+
gcc \
42+
gcc-c++ \
43+
curl \
44+
wget \
45+
git \
46+
tar \
47+
gzip \
48+
unzip \
49+
which \
50+
htop \
51+
tree \
52+
jq \
53+
nc \
54+
bind-utils \
55+
tmux \
56+
python3 \
57+
python3-pip \
58+
stow \
59+
openssl
60+
61+
# Install Docker
62+
curl -fsSL https://get.docker.com | sh
63+
systemctl enable --now docker
64+
65+
# Install Podman
66+
dnf -y install podman
67+
68+
# Configure runc as default runtime
69+
mkdir -p /etc/containers
70+
printf '%s\n' \
71+
'[engine]' \
72+
'runtime = "runc"' \
73+
'' \
74+
'[engine.runtimes]' \
75+
'runc = ["/usr/bin/runc"]' \
76+
'crun = ["/usr/bin/crun"]' \
77+
> /etc/containers/containers.conf
78+
79+
# Mark provisioning as complete
80+
touch /etc/lima-fedora-system-provision
81+
# User-level setup (runs as normal user)
82+
- mode: user
83+
script: |
84+
#!/bin/bash
85+
set -eux -o pipefail
86+
87+
# Check if already provisioned
88+
test -e /etc/lima-fedora-user-provision && exit 0
89+
90+
# Copy runtime config to user directory
91+
mkdir -p ~/.config/containers
92+
cp /etc/containers/containers.conf ~/.config/containers/
93+
94+
# Give user possibility to run docker as root (requires relogin)
95+
sudo usermod -aG docker "$USER"
96+
97+
# Create rootless docker socket and use it by default
98+
dockerd-rootless-setuptool.sh install
99+
docker context use rootless
100+
101+
# Enable podman socket for remote connections
102+
systemctl --user enable --now podman.socket
103+
104+
# Install dotfiles
105+
git clone https://github.com/pasquale95/dotfiles.git ~/dotfiles
106+
~/dotfiles/install.sh --deps --force
107+
108+
# Mark provisioning as complete
109+
sudo touch /etc/lima-fedora-user-provision
110+
111+
# Health probes
112+
probes:
113+
- script: |
114+
#!/bin/bash
115+
set -eux -o pipefail
116+
if ! timeout 30s bash -c "until command -v podman >/dev/null 2>&1; do sleep 3; done"; then
117+
echo >&2 "podman is not installed yet"
118+
exit 1
119+
fi
120+
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
121+
echo >&2 "docker is not installed yet"
122+
exit 1
123+
fi
124+
hint: See "/var/log/cloud-init-output.log" in the guest
125+
126+
# Startup message
127+
message: |
128+
======================================================================
129+
fedora VM ready!
130+
To connect, run:
131+
------
132+
limactl shell fedora
133+
------
134+
Note:
135+
- The home directory is mounted as WRITABLE. You can read/write
136+
files directly from your macOS filesystem.
137+
- docker is enabled as rootless. To use rootful docker, restart the
138+
machine and run "docker context use default".
139+
======================================================================

.lima/templates/podman.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
minimumLimaVersion: 1.1.0
2+
3+
cpus: 4
4+
memory: "16GiB"
5+
disk: "100GiB"
6+
7+
base:
8+
- template://_images/fedora-41
9+
- template://_default/mounts
10+
11+
containerd:
12+
system: false
13+
user: false
14+
15+
provision:
16+
- mode: system
17+
script: |
18+
#!/bin/bash
19+
set -eux -o pipefail
20+
command -v podman >/dev/null 2>&1 && test -e /etc/lima-podman && exit 0
21+
22+
# Install podman AND runc
23+
dnf -y install --best podman runc podman-docker && touch /etc/lima-podman
24+
25+
# Configure runc as default runtime
26+
mkdir -p /etc/containers
27+
printf '%s\n' \
28+
'[engine]' \
29+
'runtime = "runc"' \
30+
'' \
31+
'[engine.runtimes]' \
32+
'runc = ["/usr/bin/runc"]' \
33+
'crun = ["/usr/bin/crun"]' \
34+
> /etc/containers/containers.conf
35+
36+
- mode: user
37+
script: |
38+
#!/bin/bash
39+
set -eux -o pipefail
40+
41+
# Copy runtime config to user directory
42+
mkdir -p ~/.config/containers
43+
cp /etc/containers/containers.conf ~/.config/containers/
44+
45+
# Your existing service enable
46+
systemctl --user enable --now podman.socket
47+
48+
probes:
49+
- script: |
50+
#!/bin/bash
51+
set -eux -o pipefail
52+
if ! timeout 30s bash -c "until command -v podman >/dev/null 2>&1; do sleep 3; done"; then
53+
echo >&2 "podman is not installed yet"
54+
exit 1
55+
fi
56+
hint: See "/var/log/cloud-init-output.log" in the guest
57+
58+
portForwards:
59+
- guestSocket: "/run/user/{{.UID}}/podman/podman.sock"
60+
hostSocket: "{{.Dir}}/sock/podman.sock"
61+
62+
message: |
63+
======================================================================
64+
podman VM ready!
65+
66+
To run `podman` on the host (assumes podman-remote is installed), run the following commands:
67+
------
68+
podman system connection add {{.Name}} "unix://{{.Dir}}/sock/podman.sock"
69+
podman system connection default {{.Name}}
70+
podman{{if eq .HostOS "linux"}} --remote{{end}} run quay.io/podman/hello
71+
------
72+
======================================================================

install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ if [[ INSTALL_DEPS -eq 1 ]]; then
5252
"${DOTFILES_REPO_DIR}/brew.sh"
5353
fi
5454

55+
# install missing dependency
56+
if (! command -v stow >/dev/null 2>&1); then
57+
echo "stow is not installed. Installing it..."
58+
brew install stow
59+
fi
60+
5561
if [[ INSTALL_FORCE -eq 1 ]]; then
5662
# move all conflicting files under ~/.dot-backup
5763
mkdir -p "${DOTFILES_REPO_DIR}/backup"

uninstall.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
# abort on error
4+
set -e
5+
6+
DOTFILES_REPO_DIR="${DOTFILES_REPO_DIR:-${HOME}/dotfiles}"
7+
38
echo "🕒 Uninstalling dotfiles..."
49

510
# install missing dependency
@@ -9,7 +14,19 @@ if (! command -v stow >/dev/null 2>&1); then
914
fi
1015

1116
# install dotfiles
12-
source ./.functions
17+
# shellcheck disable=SC1091
18+
source "${DOTFILES_REPO_DIR}/.functions"
1319
dot-uninstall
1420

15-
echo "✅ Dotfiles successfully installed!"
21+
# Restore backup files if present
22+
if [[ -d "${DOTFILES_REPO_DIR}/backup" ]]; then
23+
echo "🔄 Restoring backup files..."
24+
25+
while IFS= read -r -d '' file; do
26+
basefile=$(basename "${file}")
27+
mv -f "${file}" "${HOME}/${basefile}"
28+
echo "💾 Restored ${basefile} to ${HOME}"
29+
done < <(find "${DOTFILES_REPO_DIR}/backup" -maxdepth 1 -type f -print0)
30+
fi
31+
32+
echo "✅ Dotfiles successfully uninstalled!"

0 commit comments

Comments
 (0)