Skip to content

Commit 08a3c52

Browse files
authored
Merge pull request #3 from f5devcentral/dev
Dev
2 parents 3075eb0 + 4a7db83 commit 08a3c52

28 files changed

+353
-124
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.github/workflows/cloudapp-build.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: CloudApp Build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'dev'
8+
- 'main'
9+
paths:
10+
- cloudapp/**
11+
tags:
12+
- 'v*'
13+
pull_request:
14+
branches:
15+
- 'dev'
16+
paths:
17+
- cloudapp/**
18+
env:
19+
REGISTRY: ghcr.io
20+
IMAGE_NAME: ${{ github.repository }}/cloudapp
21+
CONTEXT: cloudapp
22+
jobs:
23+
docker:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
steps:
29+
-
30+
name: Checkout
31+
uses: actions/checkout@v4
32+
-
33+
name: Docker meta
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38+
tags: |
39+
type=ref,event=branch
40+
type=ref,event=pr
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
44+
-
45+
name: Login to Registry
46+
if: github.event_name != 'pull_request'
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
-
53+
name: Build and push
54+
uses: docker/build-push-action@v5
55+
with:
56+
context: "{{defaultContext}}:${{env.CONTEXT}}"
57+
push: ${{ github.event_name != 'pull_request' }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/lab-build.yml renamed to .github/workflows/labapp-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: lab-build
1+
name: LabApp Build
22

33
on:
44
workflow_dispatch:

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions",
4+
"ms-python.python"
5+
]
6+
}

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Attach to Python Functions",
6+
"type": "debugpy",
7+
"request": "attach",
8+
"connect": {
9+
"host": "localhost",
10+
"port": 9091
11+
},
12+
"preLaunchTask": "func: host start"
13+
}
14+
]
15+
}

.vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"azureFunctions.deploySubpath": "cloudapp/azure_function",
3+
"azureFunctions.scmDoBuildDuringDeployment": true,
4+
"azureFunctions.pythonVenv": ".venv",
5+
"azureFunctions.projectLanguage": "Python",
6+
"azureFunctions.projectRuntime": "~4",
7+
"debug.internalConsoleOptions": "neverOpen",
8+
"azureFunctions.projectSubpath": "cloudapp/azure_function",
9+
"azureFunctions.projectLanguageModel": 2
10+
}

.vscode/tasks.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "func",
6+
"label": "func: host start",
7+
"command": "host start",
8+
"problemMatcher": "$func-python-watch",
9+
"isBackground": true,
10+
"dependsOn": "pip install (functions)",
11+
"options": {
12+
"cwd": "${workspaceFolder}/cloudapp/azure_function"
13+
}
14+
},
15+
{
16+
"label": "pip install (functions)",
17+
"type": "shell",
18+
"osx": {
19+
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
20+
},
21+
"windows": {
22+
"command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
23+
},
24+
"linux": {
25+
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
26+
},
27+
"problemMatcher": [],
28+
"options": {
29+
"cwd": "${workspaceFolder}/cloudapp/azure_function"
30+
}
31+
}
32+
]
33+
}

cloudapp/.dockerignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.git
2+
.gitignore
3+
Dockerfile*
4+
docker-compose*
5+
README.md
6+
LICENSE
7+
SUPPORT.md
8+
.vscode
9+
.github
10+
zappa_settings.json

cloudapp/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.10.14-slim
2+
LABEL org.opencontainers.image.description MCN Practical Cloud App
3+
4+
ENV PYTHONUNBUFFERED=1
5+
WORKDIR /app
6+
COPY app .
7+
RUN pip install --no-cache-dir -r requirements.txt
8+
9+
EXPOSE 5000
10+
ENV FLASK_APP app.py
11+
ENV FLASK_RUN_HOST 0.0.0.0
12+
13+
CMD ["flask", "run"]

cloudapp/app.py

-62
This file was deleted.

cloudapp/app/app.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
MCN Practical Universal Web App
3+
"""
4+
import os
5+
import json
6+
from flask import Flask, jsonify, request, render_template
7+
8+
def create_app():
9+
app = Flask(__name__)
10+
app.config['site'] = os.getenv('SITE', "local")
11+
12+
@app.template_filter('to_pretty_json')
13+
def to_pretty_json(value):
14+
return json.dumps(value, sort_keys=True, indent=4)
15+
16+
@app.route('/raw', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
17+
def echo():
18+
"""
19+
Echo the request headers and data
20+
"""
21+
headers = dict(request.headers)
22+
data = None
23+
if request.method in ['POST', 'PUT', 'PATCH', 'DELETE']:
24+
try:
25+
data = request.get_json() or request.form.to_dict()
26+
except Exception as e:
27+
print(e)
28+
response = {
29+
'request_headers': headers,
30+
'request_env': app.config['site']
31+
}
32+
if data:
33+
response['request_data'] = data
34+
return jsonify(response)
35+
36+
@app.route('/', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
37+
@app.route('/echo', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
38+
def echo_html():
39+
""" Same as /raw, just prettier"""
40+
headers = dict(request.headers)
41+
data = None
42+
if request.method in ['POST', 'PUT', 'PATCH', 'DELETE']:
43+
try:
44+
data = request.get_json()
45+
except Exception:
46+
pass
47+
try:
48+
data = request.form.to_dict()
49+
except Exception:
50+
pass
51+
return render_template('pretty_echo.html', request_env=app.config['site'], request_headers=headers, request_data=data)
52+
53+
return app
54+
55+
app = create_app()
56+
57+
if __name__ == '__main__':
58+
app.run(debug=False)

cloudapp/app/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask ~=3.0.3
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

cloudapp/templates/pretty_echo.html renamed to cloudapp/app/templates/pretty_echo.html

+14-39
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Echo</title>
6+
<title>MCN Practical Cloud App</title>
77
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
88
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/styles/atom-one-dark.min.css">
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
@@ -12,33 +12,39 @@
1212

1313
<style>
1414
.json-output {
15-
background-color: #333; /* Dark grey background */
16-
color: #fff; /* Ensure text color is white */
15+
background-color: #333;
16+
color: #fff;
1717
padding: 1em;
1818
border-radius: 0.5em;
1919
overflow: auto;
2020
}
21-
.json-output pre, .json-output code { /* Ensure all text within pre and code tags inherits white color */
21+
.json-output pre, .json-output code {
2222
color: inherit;
2323
}
24+
pre code.hljs {
25+
overflow-x: hidden;
26+
}
27+
pre code.hljs:hover {
28+
overflow-x: auto;
29+
}
2430
</style>
2531
</head>
2632
<body>
2733
<div class="container">
2834
<div>
2935
<h1 class="mt-5">
30-
<img src="/static/logo.png" alt="" width="auto" height="100"/>
36+
<img src="https://github.com/f5devcentral/f5xc-lab-mcn-practical/blob/main/cloudapp/static/logo.png?raw=true" alt="" width="auto" height="100"/>
3137
MCN Practical Cloud App</h1>
3238
</div>
3339
<div class="card mt-3">
3440
<div class="card-header">Environment</div>
3541
<div class="card-body">
3642
{% if request_env == 'AWS' %}
37-
<img src="/static/aws.png" alt="" width="auto" height="40">
43+
<img src="https://github.com/f5devcentral/f5xc-lab-mcn-practical/blob/main/cloudapp/static/aws.png?raw=true" alt="" width="auto" height="40">
3844
{% elif request_env == 'Azure' %}
39-
<img src="/static/azure.png" alt="" width="auto" height="40">
45+
<img src="https://github.com/f5devcentral/f5xc-lab-mcn-practical/blob/main/cloudapp/static/azure.png?raw=true" alt="" width="auto" height="40">
4046
{% else %}
41-
<img src="/static/flask.png" alt="" width="auto" height="40">
47+
<img src="https://github.com/f5devcentral/f5xc-lab-mcn-practical/blob/main/cloudapp/static/flask.png?raw=true" alt="" width="auto" height="40">
4248
{% endif %}
4349
&nbsp{{ request_env }}
4450
</div>
@@ -55,39 +61,8 @@ <h1 class="mt-5">
5561
<div class="card-body json-output">
5662
<pre><code class="json">{{ request_data | to_pretty_json }}</code></pre>
5763
</div>
58-
<div>
59-
<form action="/pretty_echo" method="POST">
60-
<input type="hidden" name="example" value="data">
61-
<button type="submit" class="btn btn-primary">Send POST Data</button>
62-
</form>
63-
</div>
6464
</div>
6565
{% endif %}
6666
</div>
67-
<script>
68-
document.addEventListener('DOMContentLoaded', (event) => {
69-
hljs.highlightAll();
70-
});
71-
72-
function sendPostRequest() {
73-
fetch('/pretty_echo', {
74-
method: 'POST',
75-
headers: {
76-
'Content-Type': 'application/json',
77-
},
78-
body: JSON.stringify({
79-
exampleField: 'exampleValue'
80-
})
81-
})
82-
.then(response => response.json())
83-
.then(data => {
84-
alert('POST request sent.');
85-
console.log(data);
86-
})
87-
.catch((error) => {
88-
console.error('Error:', error);
89-
});
90-
}
91-
</script>
9267
</body>
9368
</html>

0 commit comments

Comments
 (0)