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

Build and test images #14

Closed
wants to merge 16 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
53 changes: 53 additions & 0 deletions .github/actions/image-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Setup Environment
description: Composite action that sets up the environment for building and testing images

inputs:
lxd-channel:
description: LXD snap channel to install
default: latest/edge
go-version:
description: Go version to install
default: 1.22.x

runs:
using: composite
steps:
- name: Install dependencies
shell: bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace all those by a single top section:

defaults:
  run:
    # Make sure bash is always invoked with `-eo pipefail`
    # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
    shell: bash

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried this one, but composite actions do not support default.run.shell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh bummer. Have you tried putting it in the top composite job?

run: |
sudo apt-get -qq update
sudo apt-get install -y --no-install-recommends \
debootstrap \
qemu-utils \
git \
gpg \
rsync \
squashfs-tools

- name: Setup LXD ${{ inputs.lxd-channel }}
shell: bash
run: |
sudo snap refresh lxd --channel=${{ inputs.lxd-channel }}
sudo lxd waitready --timeout 60
sudo chmod 777 /var/snap/lxd/common/lxd/unix.socket
sudo lxd init --auto
lxc version

- name: Install Go ${{ inputs.go-version }}
uses: actions/setup-go@v5
with:
go-version: "${{ inputs.go-version }}"

- name: Build LXD imagebuilder
shell: bash
run: make

- name: Clone LXD CI repository (for image recipes)
shell: bash
run: git clone https://github.com/musicdin/lxd-ci --branch cp/images2 --depth 1

- name: Print supported driver
shell: bash
run: |
lxc query /1.0 | jq '.environment.driver'
sudo lxc query /1.0 | jq '.environment.driver'
52 changes: 52 additions & 0 deletions .github/actions/image-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test Image
description: Composite action that test built image

inputs:
target:
description: Directory where built image is located
required: true
distro:
description: Image distribution
required: true
release:
description: Image release
required: true
variant:
description: Image variant
required: true
type:
description: Image type [container, vm]
required: true

runs:
using: composite
steps:
- name: Test image
shell: bash
run: |
TYPE=${{ inputs.type }}
TARGET=${{ inputs.target }}
DISTRO=${{ inputs.distro }}
RELEASE=${{ inputs.release }}
VARIANT=${{ inputs.variant }}

set -e

TEST_ID="${DISTRO}-${RELEASE}-${VARIANT} (${TYPE})"
echo "==> TEST: ${TEST_ID}"

VIRT_ENABLED=$(lxc query /1.0 | jq '.environment.driver | contains("qemu")')
if [ ${TYPE} = "vm" ] && [ "${VIRT_ENABLED}" != "true" ]; then
echo "==> SKIP: Virtualization is not supported"
exit 0
fi

./bin/test-image "${TYPE}" "${DISTRO}" "${RELEASE}" "${VARIANT}" "${TARGET}"

if [ "$?" = "0" ]; then
echo "==> PASS: ${TEST_ID}"
exit 0
fi

echo "==> FAIL: ${TEST_ID}"
exit 0
48 changes: 48 additions & 0 deletions .github/actions/image-upload/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Upload Image
description: Composite action for uploading built images

inputs:
name:
description: Final image name
required: true
target:
description: Directory where built image is located
required: true
# types:
# description: Image types
# required: true

runs:
using: composite
steps:
# actions/upload-artifact does not expand env vars.
- name: Expand target path
shell: bash
run: echo "target=${{ inputs.target }}" >> $GITHUB_ENV

- name: Print artifacts
shell: bash
run: ls -lah "${{ env.target }}"

# - name: Make tarball
# id: tarball
# shell: bash
# run: |
# files=$(cd ${{ inputs.target }} && ls *.tar.xz *.qcow2 *.squashfs image.yaml serial 2> /dev/null)
# tar -czvf "${{ inputs.name }}.tar.gz" -C ${{ inputs.target }} ${files}

- name: Publish artifacts
uses: actions/upload-artifact@v4
with:
name: "${{ inputs.name }}"
# path: "${{ inputs.name }}.tar.gz"
path: |
${{ env.target }}/*.qcow2
${{ env.target }}/*.squashfs
${{ env.target }}/*.tar.xz
${{ env.target }}/image.yaml
${{ env.target }}/serial
if-no-files-found: "error"
retention-days: 1
compression-level: 0
overwrite: true
93 changes: 93 additions & 0 deletions .github/workflows/image-alpine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build Alpine Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image

jobs:
alpine:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
release:
- "3.16"
- "3.17"
- "3.18"
- "3.19"
- "edge"
architecture:
- amd64
# - arm64
variant:
- default
- cloud
env:
type: "container"
distro: "${{ github.job }}"
target: "${HOME}/build"

steps:
- uses: actions/checkout@v4

- name: Setup environment
uses: ./.github/actions/image-setup

- name: Determine image types
run: |
ARCH="${{ matrix.architecture }}"
if [ "${ARCH}" = "amd64" ] || [ "${ARCH}" = "arm64" ]; then
echo "type=container,vm" >> $GITHUB_ENV
fi

- name: Build image
run: |
TIMEOUT=1800
YAML="${{ github.workspace }}/lxd-ci/images/${{ env.distro }}.yaml"
ARCH="${{ matrix.architecture }}"
TYPE="${{ env.type }}"

IMAGE_ARCH="${ARCH}"
[ "${ARCH}" = "amd64" ] && IMAGE_ARCH="x86_64"
[ "${ARCH}" = "arm64" ] && IMAGE_ARCH="aarch64"

./bin/build-distro "${YAML}" "${ARCH}" "${TYPE}" "${TIMEOUT}" "${{ env.target }}" \
-o image.architecture="${IMAGE_ARCH}" \
-o image.release=${{ matrix.release }} \
-o image.variant=${{ matrix.variant }}

- name: Print build artifacts
run: ls -lah "${{ env.target }}"

- name: Test container image
uses: ./.github/actions/image-test
if: contains(env.type, 'container')
with:
type: container
target: ${{ env.target }}
distro: ${{ env.distro }}
release: ${{ matrix.release }}
variant: ${{ matrix.variant }}

- name: Test VM image
uses: ./.github/actions/image-test
if: contains(env.type, 'vm')
with:
type: vm
target: ${{ env.target }}
distro: ${{ env.distro }}
release: ${{ matrix.release }}
variant: ${{ matrix.variant }}

- name: Upload image
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
# types: ${{ env.type }}
78 changes: 78 additions & 0 deletions .github/workflows/image-busybox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build BusyBox Images

on:
workflow_dispatch:
workflow_call:
inputs:
publish:
type: boolean
default: false
description: Publish built image

jobs:
busybox:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
release:
- 1.36.1
architecture:
- amd64
# - arm64
variant:
- default
env:
type: "container"
distro: "${{ github.job }}"
target: "${HOME}/build"

steps:
- uses: actions/checkout@v4

- name: Setup environment
uses: ./.github/actions/image-setup

- name: Build image
run: |
TIMEOUT=1800
YAML="${{ github.workspace }}/lxd-ci/images/${{ env.distro }}.yaml"
ARCH="${{ matrix.architecture }}"
TYPE="${{ env.type }}"

./bin/build-distro "${YAML}" "${ARCH}" "${TYPE}" "${TIMEOUT}" "${{ env.target }}" \
-o image.architecture="${IMAGE_ARCH}" \
-o image.release=${{ matrix.release }} \
-o image.variant=${{ matrix.variant }} \
${EXTRA_ARGS}

- name: Print build artifacts
run: ls -lah "${{ env.target }}"

- name: Test container image
uses: ./.github/actions/image-test
if: contains(env.type, 'container')
with:
type: container
target: ${{ env.target }}
distro: ${{ env.distro }}
release: ${{ matrix.release }}
variant: ${{ matrix.variant }}

- name: Test VM image
uses: ./.github/actions/image-test
if: contains(env.type, 'vm')
with:
type: vm
target: ${{ env.target }}
distro: ${{ env.distro }}
release: ${{ matrix.release }}
variant: ${{ matrix.variant }}

- name: Upload image
uses: ./.github/actions/image-upload
if: inputs.publish == true
with:
name: "${{ env.distro }}-${{ matrix.release }}-${{ matrix.architecture }}-${{ matrix.variant }}"
target: ${{ env.target }}
# types: ${{ env.type }}
Loading
Loading