Skip to content

Packer build qemu

Packer build qemu #139

Workflow file for this run

name: Packer build qemu
on:
workflow_run:
workflows: ["Build and Publish devcontainer image"]
types:
- completed
workflow_dispatch:
inputs:
glueops_codespace_tag:
description: 'Enter the github.com/glueops/codespaces tag to use (e.g. v0.60.0)'
required: false
jobs:
build:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: codespaces
timeout-minutes: 60
steps:
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Debug Print Ref Info
run: |
echo "inputs.glueops_codespace_tag: ${{ inputs.glueops_codespace_tag }}"
echo "event.workflow_run.head_branch: ${{ github.event.workflow_run.head_branch }}"
echo "event.workflow_run.head_sha: ${{ github.event.workflow_run.head_sha }}"
echo "github.ref: ${{ github.ref }}"
echo "event_name: ${{ github.event_name }}"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
ref: ${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_sha }}
- name: Setup packer
uses: hashicorp/setup-packer@c3d53c525d422944e50ee27b840746d6522b08de # v3.2.0
id: setup
with:
version: 1.11.2
- name: Generate image password
run: echo "IMAGE_PASSWORD=$(openssl rand -base64 16)" >> $GITHUB_ENV
- name: Generate cloud-init data
run: |
echo '#cloud-config
chpasswd:
expire: False
users:
- {name: debian, password: '"$IMAGE_PASSWORD"', type: text}
ssh_pwauth: True' > user-data
echo '' > meta-data
- name: Install runner dependencies
run: sudo apt-get update && sudo apt-get install qemu-system genisoimage -y
- name: Run packer init
id: init
run: packer init qemu.pkr.hcl
- name: Run packer build
id: build
run: packer build -var glueops_codespaces_container_tag=${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_branch }} -var image_password=${{ env.IMAGE_PASSWORD }} qemu.pkr.hcl
- id: install-aws-cli
uses: unfor19/install-aws-cli-action@v1
with:
version: 2
verbose: false
arch: amd64
- name: Upload .qcow2 to S3
run: |
aws s3 cp images/${{ github.event.workflow_run.head_branch }}.qcow2 s3://${{ secrets.S3_BUCKET }}/${{ github.event.workflow_run.head_branch }}.qcow2 --acl public-read
env:
AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.S3_BUCKET_REGION }}
- name: Split qcow2 image into 1024M files
run: |
mv images/${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_branch }}.qcow2 .
tar -cvf ${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_branch }}.qcow2.tar ${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_branch }}.qcow2
split -b 1024M ${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_branch }}.qcow2.tar ${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_branch }}.qcow2.tar.part_
- name: Upload *.qcow2.tar.part_* files to GitHub Releases as an Asset
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file: "*.qcow2.tar.part_*"
tag_name: ${{ inputs.glueops_codespace_tag || github.event.workflow_run.head_branch }}