Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ EXPOSE 8000

# Define environment variable
ENV NAME=World
ENV VERSION=dev

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

#harbor.freshbrewed.science/library/pybsposter:0.2.0
#harbor.freshbrewed.science/library/pybsposter:0.2.1
102 changes: 84 additions & 18 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Union
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from datetime import datetime
from atproto import Client, client_utils
from pydantic import BaseModel
Expand All @@ -11,6 +12,10 @@

app = FastAPI()


# Mount the `static` directory to serve static files
app.mount("/static", StaticFiles(directory="static"), name="static")

class SocialPost(BaseModel):
username: str
password: str
Expand Down Expand Up @@ -59,24 +64,71 @@ def read_root():
print(f"Error: {e}")
uptime_seconds, current_time, logs = "N/A", "N/A", ["Error reading metrics or logs"]

# Get app version from environment variable
app_version = os.environ.get("VERSION", "unknown")

return f"""
<pre>
______ ______ ______ _
| ___ \ | ___ \ | ___ \ | |
| |_/ / _ _ | |_/ / ___ | |_/ / ___ ___ | |_ ___ _ __
| __/ | | | || ___ \/ __|| __/ / _ \ / __|| __| / _ \| '__|
| | | |_| || |_/ /\__ \| | | (_) |\__ \| |_ | __/| |
\_| \__, |\____/ |___/\_| \___/ |___/ \__| \___||_|
__/ |
|___/
</pre>
<br/>
<br/>
<h1>Container Metrics</h1>
<p>Uptime: {uptimeoutput}</p>
<p>Last Updated: {current_time}</p>
<h2>Recent Logs:</h2>
<ul>{''.join(f'<li>{log}</li>' for log in logs)}</ul>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PyBsPoster</title>
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
<style>
body {{
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}}
.container {{
text-align: center;
background: #ffffff;
padding: 2em;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}}
.logo {{
max-width: 200px;
}}
.title {{
color: #333;
font-size: 1.2em;
margin: 20px 0;
}}
h1 {{
color: #333;
font-size: 2em;
}}
p {{
color: #555;
font-size: 1.2em;
}}
.version {{
margin-top: 1em;
font-weight: bold;
color: #007BFF;
}}
</style>
</head>
<body>
<div class="container">
<img src="/static/logo3.png" alt="Logo" class="logo">
<h1 class="title">Welcome to PyBSPoster</h1>
<p>The application is running smoothly.</p>
<p>Documentation for this instance can be found:</p>
<div class="title"><a href="/docs">Swagger (OpenAPI)</a><br/><a href="/redoc">Redocs</a><br/></div>
<div class="version">Version: {app_version}</div><br/><br/>
<div>Uptime: {uptimeoutput}</div><br/><br/>
<div>Last Updated: {current_time}</div>
</div>
</body>
</html>
"""


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

@app.post("/post")
async def post_social(post: SocialPost):
"""
Post to BlueSky.

Args:
post (SocialPost): Contains the text, optional link
username and password for your BlueSky account.

NOTE: baseURL is not used for BlueSky, but is included for consistency.

Returns:
Response from Bluesky or status message.
"""
# Debug
# print(f"Received username: {post.username}", flush=True)
# print(f"Received password: {post.password}", flush=True)
Expand Down Expand Up @@ -162,8 +226,10 @@ async def post_to_mastodon(post: SocialPost):
post (SocialPost): Contains the text, optional link, and the Mastodon instance URL (baseURL).
the password is the API key for Mastodon.

NOTE: The username is not used for Mastodon, but is included for consistency.

Returns:
dict: Response from Mastodon or status message.
Response from Mastodon or status message.
"""
# Ensure the baseURL is provided for Mastodon posts
if not post.baseURL:
Expand Down
4 changes: 2 additions & 2 deletions charts/pybsposter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ apiVersion: v2
name: pybsposter
description: A Helm chart for deploying the pybsposter application
type: application
version: 0.1.3
appVersion: "2.1"
version: 0.1.4
appVersion: "2.2"

3 changes: 3 additions & 0 deletions charts/pybsposter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.targetPort }}
env:
- name: VERSION
value: "{{ .Values.image.tag }}"
resources:
{{- toYaml .Values.resources | nindent 12 }}

Binary file added static/favicon.ico
Binary file not shown.
Binary file added static/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/logo3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.