Skip to content

Commit 17dcd89

Browse files
committed
feat: add kvm
1 parent d006e3d commit 17dcd89

File tree

3 files changed

+73
-8
lines changed

3 files changed

+73
-8
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Packer build qemu
2+
3+
on:
4+
push:
5+
branches:
6+
- "feat/add-kvm-acceleration"
7+
8+
jobs:
9+
build:
10+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
11+
runs-on: codespaces
12+
steps:
13+
- name: Enable KVM group perms
14+
run: |
15+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
16+
sudo udevadm control --reload-rules
17+
sudo udevadm trigger --name-match=kvm
18+
19+
- name: Debug Print Ref Info
20+
run: |
21+
echo "inputs.glueops_codespace_tag: ${{ inputs.glueops_codespace_tag }}"
22+
echo "event.workflow_run.head_branch: ${{ github.event.workflow_run.head_branch }}"
23+
echo "event.workflow_run.head_sha: ${{ github.event.workflow_run.head_sha }}"
24+
echo "github.ref: ${{ github.ref }}"
25+
echo "event_name: ${{ github.event_name }}"
26+
27+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
28+
with:
29+
fetch-depth: 0
30+
ref: ${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_sha }}
31+
32+
- name: Setup packer
33+
uses: hashicorp/setup-packer@1aa358be5cf73883762b302a3a03abd66e75b232 # v3.1.0
34+
id: setup
35+
with:
36+
version: 1.11.2
37+
38+
- name: Generate image password
39+
run: echo "IMAGE_PASSWORD=$(openssl rand -base64 16)" >> $GITHUB_ENV
40+
41+
- name: Generate cloud-init data
42+
run: |
43+
echo '#cloud-config
44+
chpasswd:
45+
expire: False
46+
users:
47+
- {name: debian, password: '"$IMAGE_PASSWORD"', type: text}
48+
ssh_pwauth: True' > user-data
49+
echo '' > meta-data
50+
51+
- name: Install qemu
52+
run: sudo apt-get update && sudo apt-get install qemu-system -y
53+
54+
- name: Run packer init
55+
id: init
56+
run: packer init qemu.pkr.hcl
57+
58+
- name: Run packer build
59+
id: build
60+
run: packer build -var glueops_codespaces_container_tag=v0.98.0 -var image_password=${{ env.IMAGE_PASSWORD }} qemu.pkr.hcl

.github/workflows/packer-qemu.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ jobs:
1616
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1717
runs-on: codespaces
1818
steps:
19+
- name: Enable KVM group perms
20+
run: |
21+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
22+
sudo udevadm control --reload-rules
23+
sudo udevadm trigger --name-match=kvm
24+
1925
- name: Debug Print Ref Info
2026
run: |
2127
echo "inputs.glueops_codespace_tag: ${{ inputs.glueops_codespace_tag }}"
@@ -38,19 +44,16 @@ jobs:
3844
- name: Generate image password
3945
run: echo "IMAGE_PASSWORD=$(openssl rand -base64 16)" >> $GITHUB_ENV
4046

41-
- name: Generate cloud-init iso
47+
- name: Generate cloud-init data
4248
run: |
43-
sudo apt install genisoimage
4449
echo '#cloud-config
4550
chpasswd:
4651
expire: False
4752
users:
4853
- {name: debian, password: '"$IMAGE_PASSWORD"', type: text}
4954
ssh_pwauth: True' > user-data
50-
echo 'instance-id: iid-local01
51-
local-hostname: localhost' > meta-data
52-
genisoimage -output ci-data.iso -volid cidata -joliet -rock user-data meta-data
53-
55+
echo '' > meta-data
56+
5457
- name: Install qemu
5558
run: sudo apt-get update && sudo apt-get install qemu-system -y
5659

qemu.pkr.hcl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ variable "image_password" {
77
}
88

99
source "qemu" "qemu-amd64" {
10+
accelerator = "kvm"
1011
iso_url = "https://cloud.debian.org/images/cloud/bookworm/daily/latest/debian-12-generic-amd64-daily.qcow2"
1112
iso_checksum = "file:https://cloud.debian.org/images/cloud/bookworm/daily/latest/SHA512SUMS"
1213
disk_image = true
@@ -21,10 +22,11 @@ source "qemu" "qemu-amd64" {
2122
ssh_wait_timeout = "5m"
2223
vnc_port_min = 5901
2324
vnc_port_max = 5901
25+
cd_files = ["user-data", "meta-data"]
26+
cd_label = "cidata"
2427
qemuargs = [
2528
["-m", "4096M"],
26-
["-smp", "2"],
27-
["-cdrom", "ci-data.iso"]
29+
["-smp", "2"]
2830
]
2931
}
3032

0 commit comments

Comments
 (0)