-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
162 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Docker | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
permissions: | ||
actions: write | ||
contents: read | ||
packages: write | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build: | ||
name: 🐳 Build | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: ⬇️ Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
access_token: ${{ github.token }} | ||
|
||
- name: 🐳 Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: ⚡️ Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: 🔑 Github Registry Auth | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: 👀 Extract metadata | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: 🐳 Build | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
COMMIT_SHA=${{ github.sha }} | ||
BRANCH=${{ github.head_ref || github.ref_name }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new | ||
|
||
- name: 🚚 Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM python:3.10-alpine | ||
|
||
WORKDIR /code | ||
|
||
COPY . /code | ||
|
||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | ||
|
||
|
||
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes
Empty file.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
openpyxl==3.1.2 | ||
pandas==2.2.0 | ||
pillow==10.2.0 | ||
img2pdf==0.5.1 | ||
img2pdf==0.5.1 | ||
fastapi==0.105.0 | ||
uvicorn[standard]==0.25.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from fastapi import FastAPI, Response | ||
from typing import Optional | ||
from os import walk | ||
from fastapi.staticfiles import StaticFiles | ||
from bib import generate_image | ||
|
||
app = FastAPI(title="DLV", docs_url="/swagger", | ||
openapi_url="/swagger-json", redoc_url=None) | ||
|
||
app.mount("/header", StaticFiles(directory="header"), name="header") | ||
app.mount("/footer", StaticFiles(directory="footer"), name="footer") | ||
|
||
|
||
def headers(): | ||
header = [] | ||
for (dirpath, dirnames, filenames) in walk("header"): | ||
filenames = [f for f in filenames if f.endswith( | ||
'.png') or f.endswith('.jpg')] | ||
header.extend(filenames) | ||
break | ||
return header | ||
|
||
|
||
def footers(): | ||
footer = [] | ||
for (dirpath, dirnames, filenames) in walk("footer"): | ||
filenames = [f for f in filenames if f.endswith( | ||
'.png') or f.endswith('.jpg')] | ||
footer.extend(filenames) | ||
break | ||
return footer | ||
|
||
|
||
@app.get("/", responses={ | ||
200: { | ||
"content": {"image/png": {}} | ||
} | ||
}, response_class=Response) | ||
def generate_bib( | ||
text: str, | ||
header: str, | ||
footer: str, | ||
header_offset: Optional[int] = 60, | ||
): | ||
# check if header and footer are valid | ||
if header not in headers(): | ||
return {"error": "Header not found"} | ||
if footer not in footers(): | ||
return {"error": "Footer not found"} | ||
image = generate_image(text, header, footer, | ||
"agency_fb.ttf", header_offset) | ||
return Response(content=image, media_type="image/png", headers={"Content-Disposition": "filename=" + text + ".png"}) | ||
|
||
|
||
@app.get("/headers") | ||
def get_headers(): | ||
return headers() | ||
|
||
|
||
@app.get("/footers") | ||
def get_footers(): | ||
return footers() |