Commit 35afa59e authored by Nadine Tschirner's avatar Nadine Tschirner
Browse files

initial commit

parents
#Base py alpine - minimal and fastes install version
FROM python:alpine
RUN pip install pyyaml && pip install Flask && pip install Jinja2 && pip install ruamel.yaml
# inside the container create a group and add a user, apline different options then debian/ubuntu
RUN addgroup -g 2000 flaski && \
adduser -H -D -u 2000 -G flaski flaski && \
mkdir /app
COPY app /app
#inside the container the user is change to flaski and work with
USER flaski
WORKDIR /app
#container set command and important the host inside container isn't 127.0.0.1
CMD ["python3", "/app/app.py"]
# docker-flask
from flask import render_template
from jinja2 import Template
from flask import Flask
import yaml
import json
app = Flask(__name__)
@app.route('/')
def in_yml():
with open("host.yml", 'r') as host:
return host.read()
#env = Environment(loader = FileSystemLoader('./templates'), print(template.render(host.yml)))
@app.route('/test01')
def test_jinja01():
tm = Template('Hallo Welt')
output = tm.render()
return output
@app.route('/test01_1')
def test_jinja01_1():
tm = Template('Hallo {{ name }}')
output = tm.render(name='Nadine')
return output
@app.route('/test01_2')
def test_jinja01_2():
name_python='Megisjana'
tm = Template('Hallo {{ name_jinja }}')
output = tm.render(name_jinja=name_python)
return output
@app.route('/test01_3')
def test_jinja01_3():
name_list=['Megisjana', 'Nadine']
tm = Template('Hallo {{ name_jinja }}')
output = tm.render(name_jinja=name_list[1])
return output
@app.route('/test02')
def test_jinja02():
with open("test.html", 'r') as template_jinja:
tm = Template(template_jinja.read())
return tm.render()
@app.route('/test03')
def in_yml03():
with open("host.yml", 'r') as host1:
dict = yaml.safe_load(host1)
return dict
print(dict)
@app.route('/test04')
def in_yml04():
with open("host.yml", 'r') as yaml_in, open("host.json","w") as json_out:
yaml_object = yaml.safe_load(yaml_in)
json.dump(yaml_object, json_out)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
---
network:
- name: "cmos"
ip: "130.73.70.25"
- name: "lifeislife"
ip: "130.73.71.88"
- name: "fun"
ip: "192.168.90.1"
<!DOCTYPE html>
<html lang="en">
<head>Networks</head>
<body>
{%- for networks in network -%}
if {{networks['cmos']}}:
print({networks['130.73.70.25']})
return {{networks['130.73.70.25']}}
{% endfor %}
</body>
</html>
{% set host = "cmos" -%}
<!DOCTYPE html>
<html lang="en">
<head>
Network
</head>
<body>
<p>
{% for networks in network %}
The hostname is {{ ['name'] }}
{% endfor %}
</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>Networks</head>
<body>
{%- for networks in network -%}
if {{networks['cmos']}}:
print({networks['130.73.70.25']})
return {{networks['130.73.70.25']}}
{% endfor %}
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment