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 node images with cloud build #1746

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
48 changes: 48 additions & 0 deletions .github/workflows/osimages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: E2E node images

on:
pull_request:
branches: [main]
paths-ignore:
- '**/*.md'
- 'docs/**'
- '.gitignore'
- 'hack/*.sh'
- 'LICENSE'
- 'SECURITY_CONTACTS'
- 'OWNERS'

permissions: {}

jobs:
build:
name: Build and upload node images
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: kubernetes-sigs/image-builder
path: image-builder
ref: v0.1.22

- name: Patch image-builder Dockerfile with root user
run: git apply "../osimages/image-builder.patch"
working-directory: "./image-builder"

- name: Build image-builder image with root user
run: make docker-build
working-directory: "./image-builder/images/capi"

- name: Build images
env:
OSIMAGE_BUILDER: gcr.io/scl-image-builder/cluster-node-image-builder-amd64:dev
run: make -C osimages -j2 ACCELERATOR=kvm osimage-flatcar-1.27.2 osimage-flatcar-1.28.2 osimage-ubuntu-2204-1.28.2 osimage-ubuntu-2204-1.27.2

- name: Upload images
run: make -C osimages osimage-upload
72 changes: 72 additions & 0 deletions osimages/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

REPO_ROOT = $(shell git rev-parse --show-toplevel)

ARTIFACTS ?= $(REPO_ROOT)/_artifacts
OSIMAGE_DIR ?= $(ARTIFACTS)/osimages
OSIMAGE_BUILDER ?= registry.k8s.io/scl-image-builder/cluster-node-image-builder-amd64:v0.1.20
STAGING_BUCKET ?= artifacts.k8s-staging-capi-openstack.appspot.com

DISTROS ?= ubuntu-2204 flatcar
KUBERNETES_VERSIONS ?= 1.28.2 1.27.2

# By default, build all distros with all kubernetes versions
all_targets := $(foreach distro,$(DISTROS),$(addprefix osimage-$(distro)-,$(KUBERNETES_VERSIONS)))
all: $(all_targets)

# Set this to 'none' if kvm is not available
ACCELERATOR ?= kvm

ifeq ($(ACCELERATOR),kvm)
privileged=--privileged
else
privileged=
endif

$(OSIMAGE_DIR):
mkdir -p $(OSIMAGE_DIR)

.PHONY: osimage
osimage: DISTRO ?= ubuntu-2204
osimage: KUBERNETES_VERSION ?= v1.28.2
# KUBERNETES_SERIES default to vX.Y from KUBERNETES_VERSION
osimage: KUBERNETES_SERIES ?= $(shell echo $(KUBERNETES_VERSION) | sed 's/\(v[0-9]\+\.[0-9]\+\).[0-9]\+/\1/;tx;q1;:x')
osimage: | $(OSIMAGE_DIR)
docker run --rm $(privileged) \
--network=host \
-v "$(OSIMAGE_DIR):/output" \
-e PACKER_FLAGS=" \
--var 'boot_wait=300s' \
Copy link
Contributor

Choose a reason for hiding this comment

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

@lentzi90 #1746 (comment) you can change the value here.

--var 'accelerator=$(ACCELERATOR)' \
--var 'kubernetes_semver=$(KUBERNETES_VERSION)' \
--var 'kubernetes_series=$(KUBERNETES_SERIES)' \
" \
-e OEM_ID=openstack \
$(OSIMAGE_BUILDER) build-qemu-$(DISTRO)

# Build a specific image, determined by the name of the target
# e.g. osimage-flatcar-1.26.2 -> DISTRO=flatcar, KUBERNETES_VERSION=v1.26.2
osimage-%: DISTRO=$(shell echo $@ | sed 's/osimage-\(.*\)-\([^-]*\)/\1/')
osimage-%: KUBERNETES_VERSION=v$(shell echo $@ | sed 's/osimage-\(.*\)-\([^-]*\)/\2/')
osimage-%: FORCE
$(MAKE) osimage DISTRO=$(DISTRO) KUBERNETES_VERSION=$(KUBERNETES_VERSION)

.PHONY: FORCE
FORCE:

.PHONY: osimage-upload
osimage-upload:
ls $(OSIMAGE_DIR)
gsutil cp $(OSIMAGE_DIR)/* gs://$(STAGING_BUCKET)/test
21 changes: 21 additions & 0 deletions osimages/cloudbuild-osimages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://cloud.google.com/cloud-build/docs/build-config
timeout: 7200s
options:
substitution_option: ALLOW_LOOSE
machineType: 'N1_HIGHCPU_32'
steps:
- name: 'docker'
script: |
apk add --update bash git make
cd ./osimages
make -j2 ACCELERATOR=none \
lentzi90 marked this conversation as resolved.
Show resolved Hide resolved
osimage-flatcar-1.27.2 \
osimage-flatcar-1.28.2 \
osimage-ubuntu-2204-1.28.2 \
osimage-ubuntu-2204-1.27.2
id: 'make'
- name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:latest'
waitFor: ['make']
script: |
cd ./osimages
make osimage-upload
31 changes: 31 additions & 0 deletions osimages/image-builder.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
index 9514c03ae..372b8dfc2 100644
--- a/images/capi/Dockerfile
+++ b/images/capi/Dockerfile
@@ -38,18 +38,15 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ARG ARCH
ARG PASSED_IB_VERSION

-USER imagebuilder
-WORKDIR /home/imagebuilder/
-
-COPY --chown=imagebuilder:imagebuilder ansible ansible/
-COPY --chown=imagebuilder:imagebuilder ansible.cfg ansible.cfg
-COPY --chown=imagebuilder:imagebuilder cloudinit cloudinit/
-COPY --chown=imagebuilder:imagebuilder hack hack/
-COPY --chown=imagebuilder:imagebuilder packer packer/
-COPY --chown=imagebuilder:imagebuilder Makefile Makefile
-COPY --chown=imagebuilder:imagebuilder azure_targets.sh azure_targets.sh
-
-ENV PATH="/home/imagebuilder/.local/bin:${PATH}"
+COPY ansible ansible/
+COPY ansible.cfg ansible.cfg
+COPY cloudinit cloudinit/
+COPY hack hack/
+COPY packer packer/
+COPY Makefile Makefile
+COPY azure_targets.sh azure_targets.sh
+
+ENV PATH="/root/.local/bin:${PATH}"
ENV PACKER_ARGS ''
ENV PACKER_VAR_FILES ''
ENV IB_VERSION "${PASSED_IB_VERSION}"