diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3209fbe --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +community-apps/build +community-apps/export +community-apps/version +community-apps/Makefile.local diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..72d7971 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "one-apps"] + path = one-apps + url = https://github.com/OpenNebula/one-apps.git diff --git a/appliances/service/695ab19e-23dc-11ef-a2b8-59beec9fdf86.yaml b/appliances/service/695ab19e-23dc-11ef-a2b8-59beec9fdf86.yaml index e8ac7b3..50ae103 100644 --- a/appliances/service/695ab19e-23dc-11ef-a2b8-59beec9fdf86.yaml +++ b/appliances/service/695ab19e-23dc-11ef-a2b8-59beec9fdf86.yaml @@ -5,7 +5,7 @@ publisher: OpenNebula Systems description: |- Appliance with preinstalled [Lithops](https://lithops-cloud.github.io/docs/) and Docker for k8s backend. - See the dedicated [documentation](https://github.com/OpenNebula/one-apps/wiki/lithops_quick). + See the dedicated [documentation](https://github.com/OpenNebula/marketplace-community/wiki/lithops_quick). short_description: Appliance with preinstalled Lithops for KVM hosts tags: - lithops diff --git a/community-apps/Makefile b/community-apps/Makefile new file mode 100644 index 0000000..29bfaf5 --- /dev/null +++ b/community-apps/Makefile @@ -0,0 +1,38 @@ +# load variables and makefile config +include Makefile.config + +# load possible overrides or non-free definitions +-include Makefile.local + +# services +services: $(patsubst %, packer-%, $(SERVICES)) + +# allow individual services targets (e.g., "make service_Lithops") +$(SERVICES): %: packer-% ; + +# aliases + dependency +packer-%: ${DIR_EXPORT}/%.qcow2 + @${INFO} "Packer ${*} done" + +# run packer build for given distro or service +${DIR_EXPORT}/%.qcow2: $(patsubst %, ${DIR_ONEAPPS}/context-linux/out/%, $(LINUX_CONTEXT_PACKAGES)) + $(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}" ${@} + +clean: + -rm -rf ${DIR_EXPORT}/* + +help: + @echo 'Usage examples:' + @echo ' make -- build just one service' + @echo + @echo ' make services -- build all services' + @echo ' make services -j 4 -- build all services in 4 parallel tasks' + @echo + @echo 'Available services:' + @echo ' $(SERVICES)' + @echo + +version: + @echo $(VERSION)-$(RELEASE) > version diff --git a/community-apps/Makefile.config b/community-apps/Makefile.config new file mode 100644 index 0000000..f292226 --- /dev/null +++ b/community-apps/Makefile.config @@ -0,0 +1,27 @@ +# context version definition +VERSION := 6.10.0 +RELEASE := 1 + +# log +VERBOSE := 1 +PACKER_LOG := 0 +PACKER_HEADLESS := true + +SERVICES := service_Lithops + +.DEFAULT_GOAL := help + +# default directories +DIR_ONEAPPS := ../one-apps +DIR_BUILD := build +DIR_EXPORT := export +$(shell mkdir -p ${DIR_BUILD} ${DIR_EXPORT}) + +# don't delete exported +.SECONDARY: $(patsubst %, $(DIR_EXPORT)/%.qcow2, $(SERVICES)) + +# logging func +INFO=sh -c 'if [ $(VERBOSE) = 1 ]; then echo [INFO] $$1; fi' INFO + +# export all variables +export diff --git a/community-apps/appliances/Lithops/appliance.sh b/community-apps/appliances/Lithops/appliance.sh new file mode 100644 index 0000000..dbe154c --- /dev/null +++ b/community-apps/appliances/Lithops/appliance.sh @@ -0,0 +1,254 @@ +# ---------------------------------------------------------------------------- # +# Copyright 2024, OpenNebula Project, OpenNebula Systems # +# # +# 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. # +# ---------------------------------------------------------------------------- # +set -o errexit -o pipefail + + +# List of contextualization parameters +ONE_SERVICE_PARAMS=( + 'ONEAPP_LITHOPS_BACKEND' 'configure' 'Lithops compute backend' 'O|text' + 'ONEAPP_LITHOPS_STORAGE' 'configure' 'Lithops storage backend' 'O|text' + 'ONEAPP_MINIO_ENDPOINT' 'configure' 'Lithops storage backend MinIO endpoint URL' 'O|text' + 'ONEAPP_MINIO_ACCESS_KEY_ID' 'configure' 'Lithops storage backend MinIO account user access key' 'O|text' + 'ONEAPP_MINIO_SECRET_ACCESS_KEY' 'configure' 'Lithops storage backend MinIO account user secret access key' 'O|text' + 'ONEAPP_MINIO_BUCKET' 'configure' 'Lithops storage backend MinIO existing bucket' 'O|text' + 'ONEAPP_MINIO_ENDPOINT_CERT' 'configure' 'Lithops storage backend MinIO endpoint certificate' 'O|text64' +) + + +### Appliance metadata ############################################### + +# Appliance metadata +ONE_SERVICE_NAME='Service Lithops - KVM' +ONE_SERVICE_VERSION='3.4.0' #latest +ONE_SERVICE_BUILD=$(date +%s) +ONE_SERVICE_SHORT_DESCRIPTION='Appliance with preinstalled Lithops for KVM hosts' +ONE_SERVICE_DESCRIPTION=$(cat <> ${local_ca_folder}/ca.crt + update-ca-certificates + fi + + return 0 +} + +service_bootstrap() +{ + update_lithops_config + return 0 +} + +############################################################################### +############################################################################### +############################################################################### + +# +# functions +# + +install_deps() +{ + msg info "Run apt-get update" + apt-get update + + msg info "Install required packages for Lithops" + if ! apt-get install -y "${1}" ; then + msg error "Package(s) installation failed: ${1}" + exit 1 + fi + + msg info "Install pip dependencies" + if ! pip install "${2}" ; then + msg error "Python pip dependencies installation failed" + exit 1 + fi +} + +install_docker() +{ + msg info "Add Docker official GPG key" + install -m 0755 -d /etc/apt/keyrings + + curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc + + chmod a+r /etc/apt/keyrings/docker.asc + + msg info "Add Docker repository to apt sources" + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + apt update + + msg info "Install Docker Engine" + if ! apt-get install -y docker-ce=$DOCKER_VERSION docker-ce-cli=$DOCKER_VERSION containerd.io docker-buildx-plugin docker-compose-plugin ; then + msg error "Docker installation failed" + exit 1 + fi +} + +install_lithops() +{ + msg info "Install Lithops from pip" + if ! pip install lithops==${LITHOPS_VERSION} ; then + msg error "Error installing Lithops" + exit 1 + fi + + msg info "Create /etc/lithops folder" + mkdir /etc/lithops +} + +create_lithops_config() +{ + msg info "Create default config file" + cat > /etc/lithops/config <&2 +set -eux -o pipefail + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "PasswordAuthentication no" } +/^[#\s]*PasswordAuthentication\s/ { $0 = update; found = 1 } +{ print } +ENDFILE { if (!found) print update } +EOF + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "PermitRootLogin without-password" } +/^[#\s]*PermitRootLogin\s/ { $0 = update; found = 1 } +{ print } +ENDFILE { if (!found) print update } +EOF + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "UseDNS no" } +/^[#\s]*UseDNS\s/ { $0 = update; found = 1 } +{ print } +ENDFILE { if (!found) print update } +EOF + +sync diff --git a/community-apps/packer/service_Lithops/82-configure-context.sh b/community-apps/packer/service_Lithops/82-configure-context.sh new file mode 100644 index 0000000..2278ea9 --- /dev/null +++ b/community-apps/packer/service_Lithops/82-configure-context.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Configure and enable service context. + +exec 1>&2 +set -eux -o pipefail + +mv /etc/one-appliance/net-90-service-appliance /etc/one-context.d/ +mv /etc/one-appliance/net-99-report-ready /etc/one-context.d/ + +chown root:root /etc/one-context.d/* +chmod u=rwx,go=rx /etc/one-context.d/* + +sync diff --git a/community-apps/packer/service_Lithops/Lithops.pkr.hcl b/community-apps/packer/service_Lithops/Lithops.pkr.hcl new file mode 100644 index 0000000..1c04e51 --- /dev/null +++ b/community-apps/packer/service_Lithops/Lithops.pkr.hcl @@ -0,0 +1,107 @@ +source "null" "null" { communicator = "none" } + +build { + sources = ["source.null.null"] + + provisioner "shell-local" { + inline = [ + "mkdir -p ${var.input_dir}/context", + "${var.input_dir}/gen_context > ${var.input_dir}/context/context.sh", + "mkisofs -o ${var.input_dir}/${var.appliance_name}-context.iso -V CONTEXT -J -R ${var.input_dir}/context", + ] + } +} + +# Build VM image +source "qemu" "Lithops" { + cpus = 2 + memory = 2048 + accelerator = "kvm" + + iso_url = "../one-apps/export/ubuntu2204.qcow2" + iso_checksum = "none" + + headless = var.headless + + disk_image = true + disk_cache = "unsafe" + disk_interface = "virtio" + net_device = "virtio-net" + format = "qcow2" + disk_compression = false + disk_size = "5000" + + output_directory = var.output_dir + + qemuargs = [ + ["-cpu", "host"], + ["-cdrom", "${var.input_dir}/${var.appliance_name}-context.iso"], + ["-serial", "stdio"], + # MAC addr needs to mach ETH0_MAC from context iso + ["-netdev", "user,id=net0,hostfwd=tcp::{{ .SSHHostPort }}-:22"], + ["-device", "virtio-net-pci,netdev=net0,mac=00:11:22:33:44:55"] + ] + ssh_username = "root" + ssh_password = "opennebula" + ssh_timeout = "900s" + shutdown_command = "poweroff" + vm_name = "${var.appliance_name}" +} + +build { + sources = ["source.qemu.Lithops"] + + # revert insecure ssh options done by context start_script + provisioner "shell" { + scripts = ["${var.input_dir}/81-configure-ssh.sh"] + } + + provisioner "shell" { + inline_shebang = "/bin/bash -e" + inline = [ + "install -o 0 -g 0 -m u=rwx,g=rx,o= -d /etc/one-appliance/{,service.d/,lib/}", + "install -o 0 -g 0 -m u=rwx,g=rx,o=rx -d /opt/one-appliance/{,bin/}", + ] + } + + provisioner "file" { + sources = [ + "../one-apps/appliances/scripts/net-90-service-appliance", + "../one-apps/appliances/scripts/net-99-report-ready", + ] + destination = "/etc/one-appliance/" + } + provisioner "file" { + sources = [ + "../one-apps/appliances/lib/common.sh", + "../one-apps/appliances/lib/functions.sh", + ] + destination = "/etc/one-appliance/lib/" + } + provisioner "file" { + source = "../one-apps/appliances/service.sh" + destination = "/etc/one-appliance/service" + } + provisioner "file" { + sources = ["appliances/Lithops/appliance.sh"] + destination = "/etc/one-appliance/service.d/" + } + + provisioner "shell" { + scripts = ["${var.input_dir}/82-configure-context.sh"] + } + + provisioner "shell" { + inline_shebang = "/bin/bash -e" + inline = ["/etc/one-appliance/service install && sync"] + } + + post-processor "shell-local" { + execute_command = ["bash", "-c", "{{.Vars}} {{.Script}}"] + environment_vars = [ + "OUTPUT_DIR=${var.output_dir}", + "APPLIANCE_NAME=${var.appliance_name}", + ] + scripts = ["../one-apps/packer/postprocess.sh"] + } +} diff --git a/community-apps/packer/service_Lithops/gen_context b/community-apps/packer/service_Lithops/gen_context new file mode 100755 index 0000000..d995acd --- /dev/null +++ b/community-apps/packer/service_Lithops/gen_context @@ -0,0 +1,33 @@ +#!/bin/bash +set -eux -o pipefail + +SCRIPT=$(cat <<'MAINEND' +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "PasswordAuthentication yes" } +/^[#\s]*PasswordAuthentication\s/ { $0 = update; found = 1 } +{ print } +ENDFILE { if (!found) print update } +EOF + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "PermitRootLogin yes" } +/^[#\s]*PermitRootLogin\s/ { $0 = update; found = 1 } +{ print } +ENDFILE { if (!found) print update } +EOF + +systemctl reload sshd + +echo "nameserver 1.1.1.1" > /etc/resolv.conf +MAINEND +) + +cat<