Skip to content

Commit

Permalink
Build supported images using Packer
Browse files Browse the repository at this point in the history
  • Loading branch information
xorel committed Nov 6, 2023
1 parent c791865 commit c8d4a5b
Show file tree
Hide file tree
Showing 178 changed files with 10,062 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
build/
export/
Makefile.local
version
packer/*/*-cloud-init.iso
packer/*/*-userdata
context-windows/out/
context-windows/*.msi
context-windows/rhsrvany.exe
Expand Down
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# load variables and makefile config
include Makefile.config

# load possible overrides or non-free definitions
-include Makefile.local

# all, aliases
all: $(patsubst %, packer-%, $(DISTROS)) $(patsubst %, packer-%, $(SERVICES))
distros: $(patsubst %, packer-%, $(DISTROS))
services: $(patsubst %, packer-%, $(SERVICES))

# allow individual distribution targets (e.g., "make debian11")
$(DISTROS): %: packer-% ;
$(SERVICES): %: packer-% ;

packer-%: context-linux ${DIR_EXPORT}/%.qcow2
@${INFO} "Packer ${*} done"

# run packer build for given distro or service
${DIR_EXPORT}/%.qcow2:
$(eval DISTRO_NAME := $(shell echo ${*} | sed 's/[0-9].*//'))
$(eval DISTRO_VER := $(shell echo ${*} | sed 's/[a-z]*//'))
packer/build.sh ${DISTRO_NAME} ${DISTRO_VER} ${@}

# context packages
context-linux: $(patsubst %, context-linux/out/%, $(LINUX_CONTEXT_PACKAGES))
@${INFO} "Generate context-linux done"

context-linux/out/%:
cd context-linux; ./generate-all.sh

clean:
-rm -rf ${DIR_EXPORT}/*

help:
@echo 'Available distros:'
@echo "$(shell echo "${DISTROS}" | fmt -w 65 | tr '\n' '\1' )" \
| tr '\1' '\n' | sed 's/^/ /'
@echo 'Available services:'
@echo ' $(SERVICES)'
@echo
@echo 'Usage examples:'
@echo ' make all -- build all distros and services'
@echo ' make distros -- build all distros'
@echo ' make services -- build all services'
@echo
@echo ' make <distro> -- build just one distro'
@echo ' make context-linux -- build context linux packages'
@echo ' make context-windows -- TODO'

version:
@echo $(VERSION)-$(RELEASE) > version
59 changes: 59 additions & 0 deletions Makefile.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# context version definition
VERSION := 6.6.1
RELEASE := 1

# log
VERBOSE := 1
PACKER_LOG := 0
PACKER_HEADLESS := true

DISTROS := alma8 alma9 \
alpine316 alpine317 \
alt9 alt10 \
amazon2 \
centos7 centos8stream \
debian10 debian11 debian12 \
devuan3 devuan4\
fedora37 fedora38 \
freebsd12 freebsd13 \
ol8 ol9 \
opensuse15 \
rocky8 rocky9 \
ubuntu2004 ubuntu2004min ubuntu2204 ubuntu2204min

SERVICES := service_OneKE service_wordpress

.DEFAULT_GOAL := help

# default directories
DIR_BUILD := build
DIR_EXPORT := export

# create them if not present
$(shell mkdir -p ${DIR_BUILD} ${DIR_EXPORT})

# don't delete exported
.SECONDARY: $(patsubst %, $(DIR_EXPORT)/%.qcow2, $(DISTROS)) $(patsubst %, $(DIR_EXPORT)/%.qcow2, $(SERVICES))

.PHONY: context-linux help

# this needs to match context-linux/generate-all.sh products
LINUX_CONTEXT_PACKAGES := one-context_${VERSION}-${RELEASE}.deb \
one-context-${VERSION}-${RELEASE}.el6.noarch.rpm \
one-context-${VERSION}-${RELEASE}.el7.noarch.rpm \
one-context-${VERSION}-${RELEASE}.el8.noarch.rpm \
one-context-${VERSION}-${RELEASE}.el9.noarch.rpm \
one-context-${VERSION}-${RELEASE}.suse.noarch.rpm \
one-context-${VERSION}_${RELEASE}.txz \
one-context-${VERSION}-alt${RELEASE}.noarch.rpm \
one-context-${VERSION}-r${RELEASE}.apk \
one-context-linux-${VERSION}-${RELEASE}.iso

LINUX_CONTEXT_PACKAGES_FULL := $(patsubst %, context-linux/out/%, $(LINUX_CONTEXT_PACKAGES))


# logging func
INFO=sh -c 'if [ $(VERBOSE) = 1 ]; then echo [INFO] $$1; fi' INFO

# export all variables
export
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# one-apps
Toolchain to build OpenNebula appliances

Requirements:
- make
- Packer
- Qemu Packer Plugin
- cloud-utils
- guestfs-tools
- qemu-img
11 changes: 11 additions & 0 deletions appliances/OneKE/appliance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

service_bootstrap() { ruby -- "${BASH_SOURCE%.*}/appliance.rb" bootstrap; }

service_cleanup() { ruby -- "${BASH_SOURCE%.*}/appliance.rb" cleanup; }

service_configure() { ruby -- "${BASH_SOURCE%.*}/appliance.rb" configure; }

service_install() { ruby -- "${BASH_SOURCE%.*}/appliance.rb" install; }

return
30 changes: 30 additions & 0 deletions appliances/OneKE/appliance/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
AllCops:
Exclude:
- '*_spec.rb'

Lint/MissingCopEnableDirective:
Enabled: false

Layout/FirstArrayElementIndentation:
Enabled: false

Layout/FirstHashElementIndentation:
Enabled: false

Layout/HashAlignment:
Enabled: false

Layout/HeredocIndentation:
Enabled: false

Layout/IndentationWidth:
Enabled: false

Layout/MultilineMethodCallIndentation:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/MethodLength:
Enabled: false
81 changes: 81 additions & 0 deletions appliances/OneKE/appliance/appliance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

require_relative 'config.rb'
require_relative 'helpers.rb'

require_relative 'vnf.rb'
require_relative 'kubernetes.rb'

require_relative 'multus.rb'
require_relative 'calico.rb'
require_relative 'canal.rb'
require_relative 'cilium.rb'

require_relative 'metallb.rb'
require_relative 'traefik.rb'
require_relative 'longhorn.rb'
require_relative 'cleaner.rb'

if caller.empty?
case ARGV[0].to_sym
when :install
install_packages PACKAGES

with_policy_rc_d_disabled do
install_kubernetes
end

install_metallb
install_traefik
install_longhorn
install_cleaner

# NOTE: Longhorn images are pulled separately.
pull_addon_images if ONE_SERVICE_AIRGAPPED

msg :info, 'Installation completed successfully'

when :configure
prepare_dedicated_storage unless ONEAPP_STORAGE_DEVICE.nil?

configure_vnf

if ONE_SERVICE_AIRGAPPED
include_images 'rke2-images-core'
include_images 'rke2-images-multus' if ONEAPP_K8S_MULTUS_ENABLED
include_images 'rke2-images-cilium' if ONEAPP_K8S_CNI_PLUGIN == 'cilium'

include_images 'one-longhorn' if ONEAPP_K8S_LONGHORN_ENABLED
include_images 'one-metallb' if ONEAPP_K8S_METALLB_ENABLED
include_images 'one-traefik' if ONEAPP_K8S_TRAEFIK_ENABLED
include_images 'one-cleaner'
end

node = configure_kubernetes(
configure_cni: ->{
configure_multus if ONEAPP_K8S_MULTUS_ENABLED
configure_calico if ONEAPP_K8S_CNI_PLUGIN == 'calico'
configure_canal if ONEAPP_K8S_CNI_PLUGIN == 'canal'
configure_cilium if ONEAPP_K8S_CNI_PLUGIN == 'cilium'
},
configure_addons: ->{
configure_metallb if ONEAPP_K8S_METALLB_ENABLED

include_manifests 'one-longhorn' if ONEAPP_K8S_LONGHORN_ENABLED
include_manifests 'one-metallb' if ONEAPP_K8S_METALLB_ENABLED
include_manifests 'one-traefik' if ONEAPP_K8S_TRAEFIK_ENABLED
include_manifests 'one-cleaner'
}
)

if node[:join_worker]
vnf_ingress_setup_https_backend
vnf_ingress_setup_http_backend
end

msg :info, 'Configuration completed successfully'

when :bootstrap
puts 'bootstrap_success'
end
end
33 changes: 33 additions & 0 deletions appliances/OneKE/appliance/calico.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'base64'
require 'yaml'

require_relative 'config.rb'
require_relative 'helpers.rb'

def configure_calico(manifest_dir = K8S_MANIFEST_DIR)
msg :info, 'Configure Calico'

if ONEAPP_K8S_CNI_CONFIG.nil?
msg :info, 'Create Calico CRD config from user-provided ranges'

documents = YAML.load_stream <<~MANIFEST
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: rke2-calico
namespace: kube-system
spec:
valuesContent: |-
MANIFEST
else
msg :info, 'Use Calico user-provided config'
documents = YAML.load_stream Base64.decode64 ONEAPP_K8S_CNI_CONFIG
end

msg :info, 'Generate Calico config manifest'
manifest = YAML.dump_stream *documents
file "#{manifest_dir}/rke2-calico-config.yaml", manifest, overwrite: true
end
33 changes: 33 additions & 0 deletions appliances/OneKE/appliance/canal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'base64'
require 'yaml'

require_relative 'config.rb'
require_relative 'helpers.rb'

def configure_canal(manifest_dir = K8S_MANIFEST_DIR)
msg :info, 'Configure Canal'

if ONEAPP_K8S_CNI_CONFIG.nil?
msg :info, 'Create Canal CRD config from user-provided ranges'

documents = YAML.load_stream <<~MANIFEST
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: rke2-canal
namespace: kube-system
spec:
valuesContent: |-
MANIFEST
else
msg :info, 'Use Canal user-provided config'
documents = YAML.load_stream Base64.decode64 ONEAPP_K8S_CNI_CONFIG
end

msg :info, 'Generate Canal config manifest'
manifest = YAML.dump_stream *documents
file "#{manifest_dir}/rke2-canal-config.yaml", manifest, overwrite: true
end
71 changes: 71 additions & 0 deletions appliances/OneKE/appliance/cilium.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

require 'base64'
require 'uri'
require 'yaml'

require_relative 'config.rb'
require_relative 'helpers.rb'

def configure_cilium(manifest_dir = K8S_MANIFEST_DIR, endpoint = K8S_CONTROL_PLANE_EP)
msg :info, 'Configure Cilium'

ep = URI.parse "https://#{endpoint}"

if ONEAPP_K8S_CNI_CONFIG.nil?
msg :info, 'Create Cilium CRD config from user-provided ranges'

documents = YAML.load_stream <<~MANIFEST
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: rke2-cilium
namespace: kube-system
spec:
valuesContent: |-
kubeProxyReplacement: strict
k8sServiceHost: "#{ep.host}"
k8sServicePort: #{ep.port}
cni:
chainingMode: "none"
exclusive: false
bgpControlPlane:
enabled: true
---
apiVersion: cilium.io/v2alpha1
kind: CiliumLoadBalancerIPPool
metadata:
name: default
namespace: kube-system
spec:
cidrs: {}
MANIFEST

unless ONEAPP_K8S_CILIUM_RANGES.empty?
ip_address_pool = documents.find do |doc|
doc['kind'] == 'CiliumLoadBalancerIPPool' && doc.dig('metadata', 'name') == 'default'
end
ip_address_pool['spec']['cidrs'] = extract_cilium_ranges.map do |item|
{ 'cidr' => item.join('/') }
end
end
else
msg :info, 'Use Cilium user-provided config'
documents = YAML.load_stream Base64.decode64 ONEAPP_K8S_CNI_CONFIG
end

msg :info, 'Generate Cilium config manifest'
manifest = YAML.dump_stream *documents
file "#{manifest_dir}/rke2-cilium-config.yaml", manifest, overwrite: true
end

def extract_cilium_ranges(ranges = ONEAPP_K8S_CILIUM_RANGES)
ranges.compact
.map(&:strip)
.reject(&:empty?)
.map { |item| item.split('/').map(&:strip) }
.reject { |item| item.length > 2 }
.reject { |item| item.map(&:empty?).any? }
.reject { |item| !(ipv4?(item.first) && integer?(item.last)) }
end
Loading

0 comments on commit c8d4a5b

Please sign in to comment.