diff options
5 files changed, 119 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 @@ | |||
| 1 | #!/usr/bin/python3 | ||
| 2 | |||
| 3 | # Example flask application for containerization | ||
| 4 | # | ||
| 5 | # Copyright (C) 2021 Bruce Ashfield <bruce.ashfield@gmail.com> | ||
| 6 | # License: MIT (see COPYING.MIT at the root of the repository for terms) | ||
| 7 | |||
| 8 | from flask import Flask | ||
| 9 | |||
| 10 | app = Flask(__name__) | ||
| 11 | |||
| 12 | @app.route('/yocto/', methods=['GET', 'POST']) | ||
| 13 | def welcome(): | ||
| 14 | return "Hello from Yocto!" | ||
| 15 | |||
| 16 | @app.route('/oe/', methods=['GET', 'POST']) | ||
| 17 | def welcometooe(): | ||
| 18 | return "Hello from OpenEmbedded!" | ||
| 19 | |||
| 20 | if __name__ == '__main__': | ||
| 21 | 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 @@ | |||
| 1 | apiVersion: apps/v1 | ||
| 2 | kind: Deployment | ||
| 3 | metadata: | ||
| 4 | name: @NAME@ | ||
| 5 | spec: | ||
| 6 | selector: | ||
| 7 | matchLabels: | ||
| 8 | app: @APPNAME@ | ||
| 9 | replicas: 1 | ||
| 10 | template: | ||
| 11 | metadata: | ||
| 12 | labels: | ||
| 13 | app: @APPNAME@ | ||
| 14 | spec: | ||
| 15 | containers: | ||
| 16 | - name: @CONTAINERNAME@ | ||
| 17 | image: @CONTAINERIMAGE@ | ||
| 18 | ports: | ||
| 19 | - containerPort: @CONTAINERPORT@ | ||
| 20 | --- | ||
| 21 | apiVersion: v1 | ||
| 22 | kind: Service | ||
| 23 | metadata: | ||
| 24 | name: yocto-flask-service | ||
| 25 | spec: | ||
| 26 | ports: | ||
| 27 | - port: @EXTERNALPORT@ | ||
| 28 | targetPort: @CONTAINERPORT@ | ||
| 29 | name: http | ||
| 30 | selector: | ||
| 31 | app: @APPNAME@ | ||
| 32 | |||
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 @@ | |||
| 1 | apiVersion: v1 | ||
| 2 | kind: Pod | ||
| 3 | metadata: | ||
| 4 | name: @NAME@ | ||
| 5 | spec: | ||
| 6 | containers: | ||
| 7 | - name: @CONTAINERNAME@ | ||
| 8 | image: @CONTAINERIMAGE@ | ||
| 9 | ports: | ||
| 10 | - containerPort: @CONTAINERPORT@ | ||
| 11 | |||
| 12 | |||
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..896e45fd --- /dev/null +++ b/recipes-demo/helloworld-flask/helloworld-flask_0.1.bb | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | DESCRIPTION = "Demo flask application" | ||
| 2 | HOMEPAGE = "https://yoctoproject.org" | ||
| 3 | LICENSE = "MIT" | ||
| 4 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 5 | |||
| 6 | SRC_URI = "file://flask-app \ | ||
| 7 | file://flask-app.yaml \ | ||
| 8 | file://flask-app-service.yaml" | ||
| 9 | |||
| 10 | DEPLOY_TYPE ?= "pod" | ||
| 11 | |||
| 12 | NAME ?= "demo" | ||
| 13 | APPNAME ?= "yocto-app" | ||
| 14 | CONTAINERNAME ?= "yocto-container" | ||
| 15 | CONTAINERIMAGE ?= "zeddii/app-container:latest" | ||
| 16 | CONTAINERPORT ?= "9000" | ||
| 17 | EXTERNALPORT ?= "10000" | ||
| 18 | |||
| 19 | do_install() { | ||
| 20 | |||
| 21 | for tgt in flask-app.yaml flask-app-service.yaml; do | ||
| 22 | sed -i 's%\@NAME\@%${NAME}%g' ${WORKDIR}/$tgt | ||
| 23 | sed -i 's%\@APPNAME\@%${APPNAME}%g' ${WORKDIR}/$tgt | ||
| 24 | sed -i 's%\@CONTAINERNAME\@%${CONTAINERNAME}%g' ${WORKDIR}/$tgt | ||
| 25 | sed -i 's%\@CONTAINERIMAGE\@%${CONTAINERIMAGE}%g' ${WORKDIR}/$tgt | ||
| 26 | sed -i 's%\@CONTAINERPORT\@%${CONTAINERPORT}%g' ${WORKDIR}/$tgt | ||
| 27 | sed -i 's%\@EXTERNALPORT\@%${EXTERNALPORT}%g' ${WORKDIR}/$tgt | ||
| 28 | done | ||
| 29 | |||
| 30 | install -d ${D}${bindir}/ | ||
| 31 | install -m 755 ${WORKDIR}/flask-app ${D}${bindir}/ | ||
| 32 | |||
| 33 | install -d ${D}${sysconfdir}/deploy | ||
| 34 | install -m 644 ${WORKDIR}/flask-app.yaml ${D}${sysconfdir}/ | ||
| 35 | install -m 644 ${WORKDIR}/flask-app-service.yaml ${D}${sysconfdir}/ | ||
| 36 | } | ||
| 37 | |||
| 38 | RDEPENDS:${PN} += "python3-core python3-flask" | ||
| 39 | |||
| 40 | PACKAGES:prepend = "${PN}-deploy " | ||
| 41 | FILES:${PN}-deploy = "${sysconfdir}/*" | ||
| 42 | |||
| 43 | # this rdepends should be conditional on a debug PACKAGECONFIG | ||
| 44 | # RDEPENDS:${PN} += "busybox" | ||
diff --git a/recipes-demo/images/app-container.bb b/recipes-demo/images/app-container.bb new file mode 100644 index 00000000..c8798cf0 --- /dev/null +++ b/recipes-demo/images/app-container.bb | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | SUMMARY = "Basic Application container image" | ||
| 2 | LICENSE = "MIT" | ||
| 3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 4 | |||
| 5 | include container-base.bb | ||
| 6 | |||
| 7 | OCI_IMAGE_ENTRYPOINT = "/usr/bin/flask-app" | ||
| 8 | CONTAINER_SHELL = "busybox" | ||
| 9 | |||
| 10 | IMAGE_INSTALL:append = "helloworld-flask" | ||
