Skip to content

Commit

Permalink
WIP kernel workflow call
Browse files Browse the repository at this point in the history
Signed-off-by: Misha Sakhnov <[email protected]>
  • Loading branch information
mikhail-sakhnov committed Oct 29, 2024
1 parent b36b974 commit 1e446e5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 57 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,16 @@ jobs:
with:
tag: ${{ inputs.kernel-image || inputs.tag }}
return-image-for-tag: ${{ inputs.kernel-image }}
arch: ${{ matrix.arch }}
strategy:
matrix:
arch: [ 'amd64', 'arm64' ]
secrets: inherit

build:
# nb: use format(..) to catch both inputs.skip = true AND inputs.skip = 'true'.
if: ${{ format('{0}', inputs.skip) != 'true' }}
needs: [ tags ]
needs: [ tags , vm-kernel ]
env:
GO_BASE_IMG: ${{ format('localhost:5000/neondatabase/autoscaling-go-base-{0}:dev', matrix.arch) }}
permissions:
Expand Down
82 changes: 26 additions & 56 deletions .github/workflows/vm-kernel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ on:
type: boolean
required: false
default: false
arch:
description: 'Architecture to build the kernel for'
type: string
required: false
default: 'amd64'
outputs:
# image:
# description: 'vm-kernel Docker image'
# value: ${{ jobs.setup-build-vm-kernel-image.outputs.image || jobs.build-vm-kernel-image.outputs.image }}
image_amd64:
description: 'vm-kernel Docker image for amd64'
value: ${{ jobs.setup-build-vm-kernel-image.outputs.image || jobs.build-vm-kernel-image.outputs.image_amd64 }}
image_arm64:
description: 'vm-kernel Docker image for arm64'
value: ${{ jobs.setup-build-vm-kernel-image.outputs.image || jobs.build-vm-kernel-image.outputs.image_arm64 }}
image:
description: 'vm-kernel Docker image'
value: ${{ jobs.setup-build-vm-kernel-image.outputs.image || jobs.build-vm-kernel-image.outputs.image }}
image_placeholder:
description: 'vm-kernel Docker image placeholder'
value: ${{ jobs.build-vm-kernel-image.outputs.image }}

env:
VM_KERNEL_IMAGE: "neondatabase/vm-kernel"
VM_KERNEL_IMAGE: ${{format('neondatabase/vm-kernel-{0}', inputs.arch)}}
VM_KERNEL_IMAGE_PLACEHOLDER: 'neondatabase/vm-kernel-{0}'

defaults:
run:
Expand Down Expand Up @@ -133,14 +136,12 @@ jobs:
docker push ${VM_KERNEL_IMAGE}:${NEW_TAG}
build-vm-kernel-image:
# TODO: fix setup-build-vm-kernel-image to support multiarch
needs: setup-build-vm-kernel-image
if: needs.setup-build-vm-kernel-image.outputs.image == ''
outputs:
# image for backward compatibility
# image: ${{ steps.get-tags-amd64.outputs.canonical }}@${{ steps.build-linux-kernel-amd64.outputs.digest }}
image_amd64: ${{ steps.get-tags-amd64.outputs.canonical }}@${{ steps.build-linux-kernel-amd64.outputs.digest }}
image_arm64: ${{ steps.get-tags-arm64.outputs.canonical }}@${{ steps.build-linux-kernel-arm64.outputs.digest }}
image: ${{ steps.get-tags.outputs.canonical }}@${{ steps.build-linux-kernel.outputs.digest }}
placeholder: ${{ steps.get-tags.outputs.canonical_placeholder }}@${{ steps.build-linux-kernel.outputs.digest }}

runs-on: [ self-hosted, gen3, large ]
steps:
Expand Down Expand Up @@ -172,8 +173,8 @@ jobs:
echo VM_KERNEL_VERSION=$kernel_version >> $GITHUB_OUTPUT
- name: get docker tags amd64
id: get-tags-amd64
- name: get docker tags
id: get-tags
env:
KERNEL_VERSION_TAG: ${{ inputs.tag || steps.get-kernel-version.outputs.VM_KERNEL_VERSION }}
CACHE_TAG: ${{ needs.setup-build-vm-kernel-image.outputs.kernel-cache-tag }}
Expand All @@ -188,57 +189,26 @@ jobs:
# `docker/build-push-action@v6` returns all ${TAGS} in metadata ("image.name" field), so it can't be used a image name right away.
# Choose one of them as a "canonical" tag and use it to construct the job output (along with a digest provided by `docker/build-push-action@v6`).
echo "canonical=${VM_KERNEL_IMAGE}:${GITHUB_RUN_ID}" >> $GITHUB_OUTPUT
echo "canonical_placeholder=${VM_KERNEL_IMAGE_PLACEHOLDER}:${GITHUB_RUN_ID}" >> $GITHUB_OUTPUT
- name: get docker tags arm64
id: get-tags-arm64
env:
KERNEL_VERSION_TAG: ${{ inputs.tag || steps.get-kernel-version.outputs.VM_KERNEL_VERSION }}
CACHE_TAG: ${{ needs.setup-build-vm-kernel-image.outputs.kernel-cache-tag }}
run: |
# A comma-separated list of tags
TAGS="${VM_KERNEL_IMAGE}-arm64:${KERNEL_VERSION_TAG}"
TAGS="${VM_KERNEL_IMAGE}-arm64:${CACHE_TAG},${TAGS}"
TAGS="${VM_KERNEL_IMAGE}-arm64:${GITHUB_RUN_ID},${TAGS}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
# `docker/build-push-action@v6` returns all ${TAGS} in metadata ("image.name" field), so it can't be used a image name right away.
# Choose one of them as a "canonical" tag and use it to construct the job output (along with a digest provided by `docker/build-push-action@v6`).
echo "canonical=${VM_KERNEL_IMAGE}-arm64:${GITHUB_RUN_ID}" >> $GITHUB_OUTPUT
- name: build linux kernel amd64
id: build-linux-kernel-amd64
- name: build linux kernel
id: build-linux-kernel
uses: docker/build-push-action@v6
with:
build-args: KERNEL_VERSION=${{ steps.get-kernel-version.outputs.VM_KERNEL_VERSION }}
context: neonvm-kernel
platforms: linux/amd64
# neonvm-kernel/Dockerfile.kernel-builder has different targets for different architectures
# so we need to specify the target explicitly
target: kernel_amd64
target: ${{format('kernel_{0}', inputs.arch)}}
# Push kernel image only for scheduled builds or if workflow_dispatch/workflow_call input is true
push: true
pull: true
file: neonvm-kernel/Dockerfile.kernel-builder
cache-from: type=registry,ref=cache.neon.build/vm-kernel:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/vm-kernel:cache,mode=max' || '' }}
tags: ${{ steps.get-tags-amd64.outputs.tags }}
cache-from: ${{format('type=registry,ref=cache.neon.build/vm-kernel-{0}:cache', inputs.arch)}}
cache-to: ${{ github.ref_name == 'main' && format('type=registry,ref=cache.neon.build/vm-kernel-{0}:cache,mode=max', inputs.arch) || '' }}
tags: ${{ steps.get-tags.outputs.tags }}

- name: build linux kernel arm64
id: build-linux-kernel-arm64
uses: docker/build-push-action@v6
with:
build-args: KERNEL_VERSION=${{ steps.get-kernel-version.outputs.VM_KERNEL_VERSION }}
context: neonvm-kernel
# kernel is built using crosscompilation, so it doesn't matter what runner arch we have
platforms: linux/amd64
# neonvm-kernel/Dockerfile.kernel-builder has different targets for different architectures
# so we need to specify the target explicitly
target: kernel_arm64
# Push kernel image only for scheduled builds or if workflow_dispatch/workflow_call input is true
push: true
pull: true
file: neonvm-kernel/Dockerfile.kernel-builder
cache-from: type=registry,ref=cache.neon.build/vm-kernel:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/vm-kernel:cache,mode=max' || '' }}
tags: ${{ steps.get-tags-arm64.outputs.tags }}

- run: git diff neonvm-kernel

0 comments on commit 1e446e5

Please sign in to comment.