Skip to content

Commit 44189d5

Browse files
authored
Show version (#5)
* updates for showing version * Better UI for front door, details on Swagger, favicon
1 parent 2e31b4c commit 44189d5

7 files changed

Lines changed: 91 additions & 21 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ EXPOSE 8000
2222

2323
# Define environment variable
2424
ENV NAME=World
25+
ENV VERSION=dev
2526

2627
# Run app.py when the container launches
2728
CMD ["fastapi", "run", "app.py"]
2829

29-
#harbor.freshbrewed.science/library/pybsposter:0.2.0
30+
#harbor.freshbrewed.science/library/pybsposter:0.2.1

app.py

Lines changed: 84 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Union
22
from fastapi import FastAPI, HTTPException
33
from fastapi.responses import HTMLResponse
4+
from fastapi.staticfiles import StaticFiles
45
from datetime import datetime
56
from atproto import Client, client_utils
67
from pydantic import BaseModel
@@ -11,6 +12,10 @@
1112

1213
app = FastAPI()
1314

15+
16+
# Mount the `static` directory to serve static files
17+
app.mount("/static", StaticFiles(directory="static"), name="static")
18+
1419
class SocialPost(BaseModel):
1520
username: str
1621
password: str
@@ -59,24 +64,71 @@ def read_root():
5964
print(f"Error: {e}")
6065
uptime_seconds, current_time, logs = "N/A", "N/A", ["Error reading metrics or logs"]
6166

67+
# Get app version from environment variable
68+
app_version = os.environ.get("VERSION", "unknown")
69+
6270
return f"""
63-
<pre>
64-
______ ______ ______ _
65-
| ___ \ | ___ \ | ___ \ | |
66-
| |_/ / _ _ | |_/ / ___ | |_/ / ___ ___ | |_ ___ _ __
67-
| __/ | | | || ___ \/ __|| __/ / _ \ / __|| __| / _ \| '__|
68-
| | | |_| || |_/ /\__ \| | | (_) |\__ \| |_ | __/| |
69-
\_| \__, |\____/ |___/\_| \___/ |___/ \__| \___||_|
70-
__/ |
71-
|___/
72-
</pre>
73-
<br/>
74-
<br/>
75-
<h1>Container Metrics</h1>
76-
<p>Uptime: {uptimeoutput}</p>
77-
<p>Last Updated: {current_time}</p>
78-
<h2>Recent Logs:</h2>
79-
<ul>{''.join(f'<li>{log}</li>' for log in logs)}</ul>
71+
<!DOCTYPE html>
72+
<html lang="en">
73+
<head>
74+
<meta charset="UTF-8">
75+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
76+
<title>PyBsPoster</title>
77+
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
78+
<style>
79+
body {{
80+
font-family: Arial, sans-serif;
81+
background-color: #f4f4f9;
82+
margin: 0;
83+
padding: 0;
84+
display: flex;
85+
justify-content: center;
86+
align-items: center;
87+
height: 100vh;
88+
}}
89+
.container {{
90+
text-align: center;
91+
background: #ffffff;
92+
padding: 2em;
93+
border-radius: 8px;
94+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
95+
}}
96+
.logo {{
97+
max-width: 200px;
98+
}}
99+
.title {{
100+
color: #333;
101+
font-size: 1.2em;
102+
margin: 20px 0;
103+
}}
104+
h1 {{
105+
color: #333;
106+
font-size: 2em;
107+
}}
108+
p {{
109+
color: #555;
110+
font-size: 1.2em;
111+
}}
112+
.version {{
113+
margin-top: 1em;
114+
font-weight: bold;
115+
color: #007BFF;
116+
}}
117+
</style>
118+
</head>
119+
<body>
120+
<div class="container">
121+
<img src="/static/logo3.png" alt="Logo" class="logo">
122+
<h1 class="title">Welcome to PyBSPoster</h1>
123+
<p>The application is running smoothly.</p>
124+
<p>Documentation for this instance can be found:</p>
125+
<div class="title"><a href="/docs">Swagger (OpenAPI)</a><br/><a href="/redoc">Redocs</a><br/></div>
126+
<div class="version">Version: {app_version}</div><br/><br/>
127+
<div>Uptime: {uptimeoutput}</div><br/><br/>
128+
<div>Last Updated: {current_time}</div>
129+
</div>
130+
</body>
131+
</html>
80132
"""
81133

82134

@@ -112,6 +164,18 @@ async def preview_social(post: SocialPost):
112164

113165
@app.post("/post")
114166
async def post_social(post: SocialPost):
167+
"""
168+
Post to BlueSky.
169+
170+
Args:
171+
post (SocialPost): Contains the text, optional link
172+
username and password for your BlueSky account.
173+
174+
NOTE: baseURL is not used for BlueSky, but is included for consistency.
175+
176+
Returns:
177+
Response from Bluesky or status message.
178+
"""
115179
# Debug
116180
# print(f"Received username: {post.username}", flush=True)
117181
# print(f"Received password: {post.password}", flush=True)
@@ -162,8 +226,10 @@ async def post_to_mastodon(post: SocialPost):
162226
post (SocialPost): Contains the text, optional link, and the Mastodon instance URL (baseURL).
163227
the password is the API key for Mastodon.
164228
229+
NOTE: The username is not used for Mastodon, but is included for consistency.
230+
165231
Returns:
166-
dict: Response from Mastodon or status message.
232+
Response from Mastodon or status message.
167233
"""
168234
# Ensure the baseURL is provided for Mastodon posts
169235
if not post.baseURL:

charts/pybsposter/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ apiVersion: v2
22
name: pybsposter
33
description: A Helm chart for deploying the pybsposter application
44
type: application
5-
version: 0.1.3
6-
appVersion: "2.1"
5+
version: 0.1.4
6+
appVersion: "2.2"
77

charts/pybsposter/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ spec:
2020
imagePullPolicy: {{ .Values.image.pullPolicy }}
2121
ports:
2222
- containerPort: {{ .Values.service.targetPort }}
23+
env:
24+
- name: VERSION
25+
value: "{{ .Values.image.tag }}"
2326
resources:
2427
{{- toYaml .Values.resources | nindent 12 }}
2528

static/favicon.ico

15 KB
Binary file not shown.

static/logo.png

976 KB
Loading

static/logo3.png

1020 KB
Loading

0 commit comments

Comments
 (0)