diff --git a/apps-code/community-apps/Makefile.config b/apps-code/community-apps/Makefile.config index 5f4c8d9..a7b9e16 100644 --- a/apps-code/community-apps/Makefile.config +++ b/apps-code/community-apps/Makefile.config @@ -7,7 +7,7 @@ VERBOSE := 1 PACKER_LOG := 0 PACKER_HEADLESS := true -SERVICES := service_Lithops service_UERANSIM capone131 +SERVICES := service_Lithops service_UERANSIM capone131 service_customLithops .DEFAULT_GOAL := help diff --git a/apps-code/community-apps/appliances/customLithops/appliance.sh b/apps-code/community-apps/appliances/customLithops/appliance.sh new file mode 100644 index 0000000..dbe154c --- /dev/null +++ b/apps-code/community-apps/appliances/customLithops/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/apps-code/community-apps/packer/service_customLithops/82-configure-context.sh b/apps-code/community-apps/packer/service_customLithops/82-configure-context.sh new file mode 100644 index 0000000..2278ea9 --- /dev/null +++ b/apps-code/community-apps/packer/service_customLithops/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/apps-code/community-apps/packer/service_customLithops/customLithops.pkr.hcl b/apps-code/community-apps/packer/service_customLithops/customLithops.pkr.hcl new file mode 100644 index 0000000..65f701f --- /dev/null +++ b/apps-code/community-apps/packer/service_customLithops/customLithops.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" "customLithops" { + 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.customLithops"] + + # 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/customLithops/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/apps-code/community-apps/packer/service_customLithops/gen_context b/apps-code/community-apps/packer/service_customLithops/gen_context new file mode 100755 index 0000000..2203524 --- /dev/null +++ b/apps-code/community-apps/packer/service_customLithops/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<