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

Implementation of Harbor-based Docker Registry Appliance for OpenNebula Marketplace #80

Closed
wants to merge 22 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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
build/
export/
Makefile.local
version
packer/*/*-cloud-init.iso
packer/*/*-context.iso
packer/*/context/
context-windows/out/
context-windows/*.msi
context-windows/rhsrvany.exe
Expand Down
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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) $(SERVICES): %: packer-% ;

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

packer-service_vnf: packer-alpine318 ${DIR_EXPORT}/service_vnf.qcow2
@${INFO} "Packer service_vnf done"

packer-service_wordpress: packer-alma8 ${DIR_EXPORT}/service_wordpress.qcow2
@${INFO} "Packer service_wordpress done"

packer-service_OneKE: packer-ubuntu2204 ${DIR_EXPORT}/service_OneKE.qcow2
@${INFO} "Packer service_OneKE 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/^.[^0-9]*\(.*\)/\1/'))
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

context-windows: $(patsubst %, context-windows/out/%, $(WINDOWS_CONTEXT_PACKAGES))
@${INFO} "Generate context-windows done"

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

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

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

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

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

DISTROS := alma8 alma9 \
alpine316 alpine317 alpine318\
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_vnf service_wordpress service_OneKE

.DEFAULT_GOAL := help

# default directories
DIR_BUILD := build
DIR_EXPORT := export
$(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 context-windows 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))

# this needs to match context-windows/generate-all.sh products
WINDOWS_CONTEXT_PACKAGES := one-context-${VERSION}.msi \
one-context-${VERSION}.iso

WINDOWS_CONTEXT_PACKAGES_FULL := $(patsubst %, context-windows/out/%, $(WINDOWS_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
Loading
Loading