Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test-amd64-image flow #79

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/test-amd64-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: test-amd64-image

concurrency:
group: amd64-lean-image-build-${{ github.head_ref }}
cancel-in-progress: true

on:
workflow_dispatch:
push:
branches: ["dev", "v1.10"]
paths:
- "home.admin/cl.install.sh"
pull_request:
branches: ["dev", "v1.10"]
paths:
- "home.admin/cl.install.sh"
jobs:
prepare-image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set values
id: set_values
run: |
echo "BUILD_DATE=$(date +"%Y-%m-%d")" >> $GITHUB_ENV
echo "BUILD_VERSION=$(git describe --always --tags)" >> $GITHUB_ENV
if [ -z "$GITHUB_HEAD_REF" ]; then
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
else
echo "BRANCH_NAME=${GITHUB_HEAD_REF}" >> $GITHUB_ENV
fi
if [[ "${{github.event_name}}" == "pull_request" ]]; then
echo "::set-output name=github_user::${{github.event.pull_request.head.repo.owner.login}}"
else
echo "::set-output name=github_user::$(echo ${{github.repository}} | cut -d'/' -f1)"
fi

- name: Display values
run: |
echo "BUILD_DATE: ${{env.BUILD_DATE}}"
echo "BUILD_VERSION: ${{env.BUILD_VERSION}}"
echo "BRANCH_NAME: ${{env.BRANCH_NAME}}"
echo "GITHUB_USER: ${{steps.set_values.outputs.github_user}}"

- name: Get Last Successful Workflow Run ID
id: get-run-id
run: |
RUN_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/rootzoll/raspiblitz/actions/workflows/amd64-lean-image.yml/runs?branch=dev&status=success" \
| jq -r '.workflow_runs[0].id')
echo "::set-output name=run_id::$RUN_ID"

- name: Get Artifact Download URL
id: get-artifact-url
run: |
ARTIFACT_URL=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/rootzoll/raspiblitz/actions/runs/${{ steps.get-run-id.outputs.run_id }}/artifacts" \
| jq -r '.artifacts[0].archive_download_url')
echo "::set-output name=url::$ARTIFACT_URL"

- name: Download Artifact
run: |
curl -L -o artifact.zip -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ steps.get-artifact-url.outputs.url }}

- name: Decompress Image
run: |
gzip -d raspiblitz-amd64-debian-lean.qcow2.gz

- name: Extract Checksum
id: checksum
run: |
CHECKSUM=$(cat raspiblitz-amd64-debian-lean.qcow2.sha256 | awk '{print $1}')
echo "::set-output name=value::$CHECKSUM"

- name: Run the build script
run: |
echo "Using the variables: --image_link ${{github.workspace}}/raspiblitz-amd64-debian-lean.qcow2 --image_checksum ${{steps.checksum.outputs.value}} --github_user ${{steps.set_values.outputs.github_user}} --branch ${{env.BRANCH_NAME}} --github_user ${{steps.set_values.outputs.github_user}} --branch ${{env.BRANCH_NAME}}
cd ci/amd64
bash packer.build.amd64-debian.sh --image_link ${{github.workspace}}/raspiblitz-amd64-debian-lean.qcow2 --image_checksum ${{steps.checksum.outputs.value}} --github_user ${{steps.set_values.outputs.github_user}} --branch ${{env.BRANCH_NAME}} --github_user ${{steps.set_values.outputs.github_user}} --branch ${{env.BRANCH_NAME}}
8 changes: 4 additions & 4 deletions ci/amd64/debian/build.amd64-debian.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ variable "boot" { default = "uefi" }
variable "preseed_file" { default = "preseed.cfg" }
variable "hostname" { default = "raspiblitz-amd64" }

variable "iso_name" { default = "debian-12.2.0-amd64-netinst.iso" }
variable "iso_checksum" { default = "23ab444503069d9ef681e3028016250289a33cc7bab079259b73100daee0af66" }
variable "image_link" { default = "https://cdimage.debian.org/cdimage/release/current/amd64/iso-cd/debian-12.2.0-amd64-netinst.iso" }
variable "image_checksum" { default = "23ab444503069d9ef681e3028016250289a33cc7bab079259b73100daee0af66" }

variable "disk_size" { default = "30000" }
variable "memory" { default = "4096" }
Expand Down Expand Up @@ -64,8 +64,8 @@ source "qemu" "debian" {
cpus = var.cpus
disk_size = var.disk_size
http_directory = "./http"
iso_checksum = var.iso_checksum
iso_url = "https://cdimage.debian.org/cdimage/release/current/amd64/iso-cd/${var.iso_name}"
iso_checksum = var.image_checksum
iso_url = var.image_link
memory = var.memory
output_directory = "../builds/${local.name_template}-qemu"
shutdown_command = "echo 'raspiblitz' | sudo /sbin/shutdown -hP now"
Expand Down
9 changes: 9 additions & 0 deletions ci/amd64/debian/scripts/test.raspiblitz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh -eux

echo '# Check out the branch of the PR (passed down as an env variable)'
/home/admin/config.scripts/blitz.github.sh ${branch} ${github_user}

echo '# Test the installs'

echo 'cl.install.sh on'
/home/admin/config.scripts/cl.install.sh on
78 changes: 78 additions & 0 deletions ci/amd64/debian/test.amd64-debian.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
packer {
required_version = ">= 1.7.0, < 2.0.0"

required_plugins {
qemu = {
source = "github.com/hashicorp/qemu"
version = ">= 1.0.0, < 2.0.0"
}
}
}

variable "pack" { default = "lean" }
variable "github_user" { default = "raspiblitz" }
variable "branch" { default = "dev" }
variable "desktop" { default = "none" }

variable "boot" { default = "uefi" }
variable "preseed_file" { default = "preseed.cfg" }
variable "hostname" { default = "raspiblitz-amd64" }

variable "disk_size" { default = "30000" }
variable "memory" { default = "4096" }
variable "cpus" { default = "4" }

locals {
name_template = "${var.hostname}-debian-${var.pack}"
}

source "qemu" "debian" {

disk_image = true
#TODO
image_path = "path/to/your/raspiblitz-amd64-debian-lean.qcow2"

cpus = var.cpus
disk_size = var.disk_size

iso_checksum = var.image_checksum
iso_url = var.image_link
memory = var.memory

ssh_password = "raspiblitz"
ssh_port = 22
ssh_timeout = "10000s"
ssh_username = "admin"

format = "qcow2"
vm_name = "${local.name_template}.qcow2"
headless = false

vnc_bind_address = "127.0.0.1"
vnc_port_max = 5900
vnc_port_min = 5900
qemuargs = [
["-m", var.memory],
["-display", "none"]
]
}

build {
description = "Can't use variables here yet!"
sources = ["source.qemu.debian"]

provisioner "shell" {
environment_vars = [
"HOME_DIR=/home/admin",
"github_user=${var.github_user}",
"branch=${var.branch}",
]

execute_command = "echo 'raspiblitz' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'"
expect_disconnect = true
scripts = [
"./../_common/env.sh",
"./scripts/test.raspiblitz.sh",
]
}
}
33 changes: 33 additions & 0 deletions ci/amd64/packer.test.amd64-debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash -e

sudo apt-get update

# install packer
if ! packer version 2>/dev/null; then
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository -y "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update
echo -e "\nInstalling packer..."
sudo apt-get install -y packer
else
echo "# Packer is installed"
fi

# install qemu
echo "# Install qemu ..."
sudo apt-get update
sudo apt-get install -y qemu-system

# set vars
echo "# Setting the variables: $*"
source ../set_variables.sh
set_variables "$@"

# Build the image
echo "# Build the image ..."
cd debian
packer init -upgrade .
command="PACKER_LOG=1 packer build ${vars} -only=qemu packer.build.amd64-debian.hcl"
echo "# Running: $command"
if [ ${#vars} -eq 0 ];then exit 1;fi
PACKER_LOG=1 packer build ${vars} -only=qemu.debian test.amd64-debian.pkr.hcl || exit 1
Loading