mirror of
git://git.yoctoproject.org/meta-virtualization.git
synced 2025-07-05 05:15:25 +02:00
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>
This commit is contained in:
parent
fc5fdd79e0
commit
6fe326b680
21
recipes-demo/helloworld-flask/helloworld-flask/flask-app
Executable file
21
recipes-demo/helloworld-flask/helloworld-flask/flask-app
Executable file
|
@ -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)
|
|
@ -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@
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: @NAME@
|
||||
spec:
|
||||
containers:
|
||||
- name: @CONTAINERNAME@
|
||||
image: @CONTAINERIMAGE@
|
||||
ports:
|
||||
- containerPort: @CONTAINERPORT@
|
||||
|
||||
|
44
recipes-demo/helloworld-flask/helloworld-flask_0.1.bb
Normal file
44
recipes-demo/helloworld-flask/helloworld-flask_0.1.bb
Normal file
|
@ -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' ${WORKDIR}/$tgt
|
||||
sed -i 's%\@APPNAME\@%${APPNAME}%g' ${WORKDIR}/$tgt
|
||||
sed -i 's%\@CONTAINERNAME\@%${CONTAINERNAME}%g' ${WORKDIR}/$tgt
|
||||
sed -i 's%\@CONTAINERIMAGE\@%${CONTAINERIMAGE}%g' ${WORKDIR}/$tgt
|
||||
sed -i 's%\@CONTAINERPORT\@%${CONTAINERPORT}%g' ${WORKDIR}/$tgt
|
||||
sed -i 's%\@EXTERNALPORT\@%${EXTERNALPORT}%g' ${WORKDIR}/$tgt
|
||||
done
|
||||
|
||||
install -d ${D}${bindir}/
|
||||
install -m 755 ${WORKDIR}/flask-app ${D}${bindir}/
|
||||
|
||||
install -d ${D}${sysconfdir}/deploy
|
||||
install -m 644 ${WORKDIR}/flask-app.yaml ${D}${sysconfdir}/
|
||||
install -m 644 ${WORKDIR}/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"
|
10
recipes-demo/images/app-container.bb
Normal file
10
recipes-demo/images/app-container.bb
Normal file
|
@ -0,0 +1,10 @@
|
|||
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"
|
Loading…
Reference in New Issue
Block a user