Skip to content

Commit 3c38a5b

Browse files
ci: add orbstack
fix cloud-init.ubuntu.yml race conditions
1 parent 556066d commit 3c38a5b

3 files changed

Lines changed: 116 additions & 23 deletions

File tree

cloud-init/cloud-init.ubuntu.yml

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ timezone: "America/Chicago"
88
hostname: ubuntu
99

1010
package_update: true # default: true
11-
package_upgrade: false # default: false # TODO: set to true
11+
package_upgrade: true # default: false
1212
# https://github.com/number5/cloud-init/blob/main/doc/examples/cloud-config-apt.txt#L21
13-
apt_get_command: ["apt-get", "--option=Dpkg::Options::=--force-confold", "--option=Dpkg::options::=--force-unsafe-io", "--assume-yes", "--quiet", "--no-install-recommends"]
13+
apt_get_command: [
14+
"env",
15+
"DEBIAN_FRONTEND=noninteractive",
16+
"apt-get",
17+
"--option=Dpkg::Options::=--force-confold",
18+
"--option=Dpkg::options::=--force-unsafe-io",
19+
"--assume-yes",
20+
"--quiet",
21+
"--no-install-recommends"
22+
]
1423

1524
apt:
1625
sources:
17-
deadsnakes.list:
18-
source: deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu $RELEASE main
26+
deadsnakes:
27+
source: deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu $RELEASE main
1928
keyid: F23C5A6CF475977595C89F51BA6932366A755776
20-
docker.list:
29+
docker:
2130
source: deb https://download.docker.com/linux/ubuntu $RELEASE stable
2231
keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
2332

@@ -64,14 +73,14 @@ runcmd:
6473
- systemctl enable --now qemu-guest-agent.service
6574
- systemctl enable --now docker
6675
- systemctl enable --now redis-server
67-
- runuser -l ubuntu -c "wget -O - https://github.com/pythoninthegrass.keys | sudo tee -a ~/.ssh/authorized_keys"
68-
- runuser -l ubuntu -c "ssh-keyscan github.com >> ~/.ssh/known_hosts"
69-
- runuser -l ubuntu -c "mkdir -p /home/ubuntu/git"
70-
- runuser -l ubuntu -c "sudo chmod -R 0777 /home/ubuntu/git"
71-
- runuser -l ubuntu -c "sudo chown -R ubuntu:ubuntu /home/ubuntu/git"
72-
- runuser -l ansible -c "sudo touch /var/log/ansible.log"
73-
- runuser -l ansible -c "sudo chown ansible:ansible /var/log/ansible.log"
74-
- runuser -l ansible -c "sudo chmod 0777 /var/log/ansible.log"
76+
- wget -O - https://github.com/pythoninthegrass.keys | sudo tee -a /home/ubuntu/.ssh/authorized_keys
77+
- ssh-keyscan github.com >> /home/ubuntu/.ssh/known_hosts
78+
- mkdir -p /home/ubuntu/git
79+
- chmod -R 0777 /home/ubuntu/git
80+
- chown -R ubuntu:ubuntu /home/ubuntu/git
81+
- touch /var/log/ansible.log
82+
- chown ansible:ansible /var/log/ansible.log
83+
- chmod 0777 /var/log/ansible.log
7584
# * smoke test
7685
# - ansible all -m ping -i /etc/ansible/hosts
7786

@@ -86,6 +95,7 @@ write_files:
8695
owner: ubuntu:ubuntu
8796
permissions: '0644'
8897
append: false
98+
defer: true
8999
content: |
90100
# Verify that shell is interactive
91101
if [[ $- != *i* ]]; then return; fi
@@ -133,11 +143,13 @@ write_files:
133143
134144
- path: /home/ubuntu/.bash_profile
135145
owner: ubuntu:ubuntu
146+
defer: true
136147
content: |
137148
[[ -s ~/.bashrc ]] && source ~/.bashrc
138149
139150
- path: /home/ubuntu/.gitignore
140151
owner: ubuntu:ubuntu
152+
defer: true
141153
content: |
142154
.env
143155
.gitattributes
@@ -150,6 +162,7 @@ write_files:
150162
151163
- path: /home/ubuntu/.gitconfig
152164
owner: ubuntu:ubuntu
165+
defer: true
153166
content: |
154167
[core]
155168
excludesfile = /home/ubuntu/.gitignore
@@ -163,6 +176,7 @@ write_files:
163176
164177
- path: /etc/ansible/hosts
165178
owner: ansible:ansible
179+
defer: true
166180
content: |
167181
[all]
168182
localhost ansible_connection=local
@@ -225,16 +239,16 @@ write_files:
225239
}
226240
227241
# TODO: QA
228-
ansible:
229-
ansible_config: |
230-
[defaults]
231-
log_path = /var/log/ansible.log
232-
fact_caching = memory
233-
install_method: distro
234-
package_name: ansible
235-
pull:
236-
url: "https://github.com/pythoninthegrass/multipass_poc.git"
237-
playbook_name: "tasks/git.yml"
242+
# ansible:
243+
# ansible_config: |
244+
# [defaults]
245+
# log_path = /var/log/ansible.log
246+
# fact_caching = memory
247+
# install_method: distro
248+
# package_name: ansible
249+
# pull:
250+
# url: "https://github.com/pythoninthegrass/multipass_poc.git"
251+
# playbook_name: "tasks/git.yml"
238252

239253
bootcmd:
240254
- printf "[Resolve]\nDNS=1.1.1.1" > /etc/systemd/resolved.conf

taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ vars:
1414
includes:
1515
docker:
1616
taskfile: ./taskfiles/docker.yml
17+
orbstack:
18+
taskfile: ./taskfiles/orbstack.yml
19+
aliases: ["orb"]
1720
poetry:
1821
taskfile: ./taskfiles/poetry.yml
1922
redis:

taskfiles/orbstack.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: "3.0"
2+
3+
set: ['e', 'u', 'pipefail']
4+
shopt: ['globstar']
5+
6+
env:
7+
ARCH: "amd64"
8+
USERNAME: "ubuntu"
9+
CLOUD_CONFIG: "{{.ROOT_DIR}}/cloud-init/cloud-init.ubuntu.yml"
10+
OS_NAME: "ubuntu"
11+
OS_VERSION: "jammy"
12+
VM_NAME: "ubuntu-amd64"
13+
14+
vars:
15+
16+
tasks:
17+
create:
18+
desc: "Create an orbstack VM"
19+
cmds:
20+
- |
21+
orb create \
22+
-a "{{.ARCH}}" \
23+
-u "{{.USERNAME}}" \
24+
-c "{{.CLOUD_CONFIG}}" \
25+
"{{.OS_NAME}}:{{.OS_VERSION}}" \
26+
"{{.VM_NAME}}"
27+
run: once
28+
silent: true
29+
ignore_error: true
30+
status:
31+
- orb list 2>/dev/null | grep -q "{{.VM_NAME}}"
32+
33+
start:
34+
desc: "Start an orbstack VM"
35+
cmds:
36+
- orb start "{{.VM_NAME}}"
37+
run: once
38+
silent: true
39+
preconditions:
40+
- sh: >
41+
orb list 2>/dev/null
42+
| grep -q '^{{.VM_NAME}}\s'
43+
msg: "VM doesn't exist"
44+
- sh: >
45+
orb list 2>/dev/null
46+
| awk '$1=="{{.VM_NAME}}" && $2=="running" {exit 1}'
47+
msg: "VM is already running"
48+
49+
stop:
50+
desc: "Stop an orbstack VM"
51+
cmds:
52+
- orb stop "{{.VM_NAME}}"
53+
run: once
54+
silent: true
55+
preconditions:
56+
- sh: >
57+
orb list 2>/dev/null
58+
| grep -q '^{{.VM_NAME}}\s'
59+
msg: "VM doesn't exist"
60+
- sh: >
61+
orb list 2>/dev/null
62+
| awk '$1=="{{.VM_NAME}}" && $2=="stopped" {exit 1}'
63+
msg: "VM is already stopped"
64+
65+
delete:
66+
desc: "Delete an orbstack VM"
67+
cmds:
68+
- orb delete "{{.VM_NAME}}" -f
69+
run: once
70+
silent: true
71+
ignore_error: true
72+
preconditions:
73+
- sh: >
74+
orb list 2>/dev/null
75+
| grep -q '^{{.VM_NAME}}\s'
76+
msg: "VM doesn't exist"

0 commit comments

Comments
 (0)