summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2021-11-25 11:53:13 -0500
committerBruce Ashfield <bruce.ashfield@gmail.com>2021-12-13 15:59:11 -0500
commit6fe326b68012b0eae5c951ab21d55b0ccfda84f9 (patch)
tree5cb8e259e11ba99296fcbc8e46d979e6ba101597
parentfc5fdd79e082e69f3e0c145412516314fbf00f0b (diff)
downloadmeta-virtualization-6fe326b68012b0eae5c951ab21d55b0ccfda84f9.tar.gz
demo: add flask and k3s deployment files
To enable demonstrations of application container builds, and deployment to k*s clusters, we introduce a simple recipes-demo/ structure with a sample flask application and deployment yaml. i.e. ensure that "helloworld-flask-deploy" is installed on your image, and then: % kubectl apply -f /etc/flask-app.yaml % kubectl label pods zeddii-pod new-label=yoctorule % kubectl expose pod zeddii-pod --port=9000 --target-port=9000 --type=LoadBalancer --name=my-service Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
-rwxr-xr-xrecipes-demo/helloworld-flask/helloworld-flask/flask-app21
-rw-r--r--recipes-demo/helloworld-flask/helloworld-flask/flask-app-service.yaml32
-rw-r--r--recipes-demo/helloworld-flask/helloworld-flask/flask-app.yaml12
-rw-r--r--recipes-demo/helloworld-flask/helloworld-flask_0.1.bb44
-rw-r--r--recipes-demo/images/app-container.bb10
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
8from flask import Flask
9
10app = Flask(__name__)
11
12@app.route('/yocto/', methods=['GET', 'POST'])
13def welcome():
14 return "Hello from Yocto!"
15
16@app.route('/oe/', methods=['GET', 'POST'])
17def welcometooe():
18 return "Hello from OpenEmbedded!"
19
20if __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 @@
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: @NAME@
5spec:
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---
21apiVersion: v1
22kind: Service
23metadata:
24 name: yocto-flask-service
25spec:
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 @@
1apiVersion: v1
2kind: Pod
3metadata:
4 name: @NAME@
5spec:
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 @@
1DESCRIPTION = "Demo flask application"
2HOMEPAGE = "https://yoctoproject.org"
3LICENSE = "MIT"
4LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
5
6SRC_URI = "file://flask-app \
7 file://flask-app.yaml \
8 file://flask-app-service.yaml"
9
10DEPLOY_TYPE ?= "pod"
11
12NAME ?= "demo"
13APPNAME ?= "yocto-app"
14CONTAINERNAME ?= "yocto-container"
15CONTAINERIMAGE ?= "zeddii/app-container:latest"
16CONTAINERPORT ?= "9000"
17EXTERNALPORT ?= "10000"
18
19do_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
38RDEPENDS:${PN} += "python3-core python3-flask"
39
40PACKAGES:prepend = "${PN}-deploy "
41FILES:${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 @@
1SUMMARY = "Basic Application container image"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
4
5include container-base.bb
6
7OCI_IMAGE_ENTRYPOINT = "/usr/bin/flask-app"
8CONTAINER_SHELL = "busybox"
9
10IMAGE_INSTALL:append = "helloworld-flask"