diff options
Diffstat (limited to 'recipes-demo')
6 files changed, 201 insertions, 0 deletions
diff --git a/recipes-demo/helloworld-flask/helloworld-flask/flask-app b/recipes-demo/helloworld-flask/helloworld-flask/flask-app new file mode 100755 index 00000000..15ecde93 --- /dev/null +++ b/recipes-demo/helloworld-flask/helloworld-flask/flask-app @@ -0,0 +1,21 @@ +#!/usr/bin/python3 + +# Example flask application for containerization +# +# Copyright (C) 2021 Bruce Ashfield <bruce.ashfield@gmail.com> +# License: MIT (see COPYING.MIT at the root of the repository for terms) + +from flask import Flask + +app = Flask(__name__) + +@app.route('/yocto/', methods=['GET', 'POST']) +def welcome(): + return "Hello from Yocto!" + +@app.route('/oe/', methods=['GET', 'POST']) +def welcometooe(): + return "Hello from OpenEmbedded!" + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=9000) diff --git a/recipes-demo/helloworld-flask/helloworld-flask/flask-app-service.yaml b/recipes-demo/helloworld-flask/helloworld-flask/flask-app-service.yaml new file mode 100644 index 00000000..f2c8bbe2 --- /dev/null +++ b/recipes-demo/helloworld-flask/helloworld-flask/flask-app-service.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: @NAME@ +spec: + selector: + matchLabels: + app: @APPNAME@ + replicas: 1 + template: + metadata: + labels: + app: @APPNAME@ + spec: + containers: + - name: @CONTAINERNAME@ + image: @CONTAINERIMAGE@ + ports: + - containerPort: @CONTAINERPORT@ +--- +apiVersion: v1 +kind: Service +metadata: + name: yocto-flask-service +spec: + ports: + - port: @EXTERNALPORT@ + targetPort: @CONTAINERPORT@ + name: http + selector: + app: @APPNAME@ + diff --git a/recipes-demo/helloworld-flask/helloworld-flask/flask-app.yaml b/recipes-demo/helloworld-flask/helloworld-flask/flask-app.yaml new file mode 100644 index 00000000..85c0362e --- /dev/null +++ b/recipes-demo/helloworld-flask/helloworld-flask/flask-app.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Pod +metadata: + name: @NAME@ +spec: + containers: + - name: @CONTAINERNAME@ + image: @CONTAINERIMAGE@ + ports: + - containerPort: @CONTAINERPORT@ + + diff --git a/recipes-demo/helloworld-flask/helloworld-flask_0.1.bb b/recipes-demo/helloworld-flask/helloworld-flask_0.1.bb new file mode 100644 index 00000000..3f5507b3 --- /dev/null +++ b/recipes-demo/helloworld-flask/helloworld-flask_0.1.bb @@ -0,0 +1,44 @@ +DESCRIPTION = "Demo flask application" +HOMEPAGE = "https://yoctoproject.org" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" + +SRC_URI = "file://flask-app \ + file://flask-app.yaml \ + file://flask-app-service.yaml" + +DEPLOY_TYPE ?= "pod" + +NAME ?= "demo" +APPNAME ?= "yocto-app" +CONTAINERNAME ?= "yocto-container" +CONTAINERIMAGE ?= "zeddii/app-container:latest" +CONTAINERPORT ?= "9000" +EXTERNALPORT ?= "10000" + +do_install() { + + for tgt in flask-app.yaml flask-app-service.yaml; do + sed -i 's%\@NAME\@%${NAME}%g' ${UNPACKDIR}/$tgt + sed -i 's%\@APPNAME\@%${APPNAME}%g' ${UNPACKDIR}/$tgt + sed -i 's%\@CONTAINERNAME\@%${CONTAINERNAME}%g' ${UNPACKDIR}/$tgt + sed -i 's%\@CONTAINERIMAGE\@%${CONTAINERIMAGE}%g' ${UNPACKDIR}/$tgt + sed -i 's%\@CONTAINERPORT\@%${CONTAINERPORT}%g' ${UNPACKDIR}/$tgt + sed -i 's%\@EXTERNALPORT\@%${EXTERNALPORT}%g' ${UNPACKDIR}/$tgt + done + + install -d ${D}${bindir}/ + install -m 755 ${UNPACKDIR}/flask-app ${D}${bindir}/ + + install -d ${D}${sysconfdir}/deploy + install -m 644 ${UNPACKDIR}/flask-app.yaml ${D}${sysconfdir}/ + install -m 644 ${UNPACKDIR}/flask-app-service.yaml ${D}${sysconfdir}/ +} + +RDEPENDS:${PN} += "python3-core python3-flask" + +PACKAGES:prepend = "${PN}-deploy " +FILES:${PN}-deploy = "${sysconfdir}/*" + +# this rdepends should be conditional on a debug PACKAGECONFIG +# RDEPENDS:${PN} += "busybox" diff --git a/recipes-demo/images/app-container-curl.bb b/recipes-demo/images/app-container-curl.bb new file mode 100644 index 00000000..51451300 --- /dev/null +++ b/recipes-demo/images/app-container-curl.bb @@ -0,0 +1,46 @@ +SUMMARY = "Curl Application container image" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" + +IMAGE_FSTYPES = "container oci" +inherit image +inherit image-oci + +IMAGE_FEATURES = "" +IMAGE_LINGUAS = "" +NO_RECOMMENDATIONS = "1" + +IMAGE_INSTALL = " \ + base-files \ + base-passwd \ + netbase \ + ${CONTAINER_SHELL} \ +" + +# If the following is configured in local.conf (or the distro): +# PACKAGE_EXTRA_ARCHS:append = " container-dummy-provides" +# +# it has been explicitly # indicated that we don't want or need a shell, so we'll +# add the dummy provides. +# +# This is required, since there are postinstall scripts in base-files and base-passwd +# that reference /bin/sh and we'll get a rootfs error if there's no shell or no dummy +# provider. +CONTAINER_SHELL ?= "${@bb.utils.contains('PACKAGE_EXTRA_ARCHS', 'container-dummy-provides', 'container-dummy-provides', 'busybox', d)}" + +# Allow build with or without a specific kernel +IMAGE_CONTAINER_NO_DUMMY = "1" + +# Workaround /var/volatile for now +ROOTFS_POSTPROCESS_COMMAND += "rootfs_fixup_var_volatile ; " +rootfs_fixup_var_volatile () { + install -m 1777 -d ${IMAGE_ROOTFS}/${localstatedir}/volatile/tmp + install -m 755 -d ${IMAGE_ROOTFS}/${localstatedir}/volatile/log +} + +OCI_IMAGE_ENTRYPOINT = "curl" +OCI_IMAGE_TAG = "easy" +OCI_IMAGE_ENTRYPOINT_ARGS = "http://localhost:80" +CONTAINER_SHELL = "busybox" + +IMAGE_INSTALL:append = "curl" diff --git a/recipes-demo/images/app-container.bb b/recipes-demo/images/app-container.bb new file mode 100644 index 00000000..22d2ab9f --- /dev/null +++ b/recipes-demo/images/app-container.bb @@ -0,0 +1,46 @@ +SUMMARY = "Basic Application container image" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" + +#include container-base.bb + +OCI_IMAGE_ENTRYPOINT = "/usr/bin/flask-app" +CONTAINER_SHELL = "busybox" + +IMAGE_INSTALL:append = "helloworld-flask" + +IMAGE_FSTYPES = "container oci" +inherit image +inherit image-oci + +IMAGE_FEATURES = "" +IMAGE_LINGUAS = "" +NO_RECOMMENDATIONS = "1" + +IMAGE_INSTALL = " \ + base-files \ + base-passwd \ + netbase \ + ${CONTAINER_SHELL} \ +" + +# If the following is configured in local.conf (or the distro): +# PACKAGE_EXTRA_ARCHS:append = " container-dummy-provides" +# +# it has been explicitly # indicated that we don't want or need a shell, so we'll +# add the dummy provides. +# +# This is required, since there are postinstall scripts in base-files and base-passwd +# that reference /bin/sh and we'll get a rootfs error if there's no shell or no dummy +# provider. +CONTAINER_SHELL ?= "${@bb.utils.contains('PACKAGE_EXTRA_ARCHS', 'container-dummy-provides', 'container-dummy-provides', 'busybox', d)}" + +# Allow build with or without a specific kernel +IMAGE_CONTAINER_NO_DUMMY = "1" + +# Workaround /var/volatile for now +ROOTFS_POSTPROCESS_COMMAND += "rootfs_fixup_var_volatile ; " +rootfs_fixup_var_volatile () { + install -m 1777 -d ${IMAGE_ROOTFS}/${localstatedir}/volatile/tmp + install -m 755 -d ${IMAGE_ROOTFS}/${localstatedir}/volatile/log +} |