Add test branch

pull/1/head
Julius 2020-11-27 18:43:47 +01:00
parent f3c84c7186
commit e8c8e651bc
Signed by: j00lz
GPG Key ID: 09102CB8DF00D3CD
9 changed files with 162 additions and 366 deletions

View File

@ -16,4 +16,17 @@ steps:
from_secret: REGISTRY_PASSWORD
registry: harbor.voidcorp.nl
repo: library/galerie
tags: latest
tags: latest
- name: kaniko
image: ghcr.io/finitum/drone-kaniko:0.7.0
when:
branch: [test]
settings:
cache: true
username:
from_secret: REGISTRY_USER
password:
from_secret: REGISTRY_PASSWORD
registry: harbor.voidcorp.nl
repo: library/galerie
tags: test

226
.gitignore vendored
View File

@ -1,226 +1,2 @@
# Created by https://www.gitignore.io/api/python,pycharm+all
# Edit at https://www.gitignore.io/?templates=python,pycharm+all
### PyCharm+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### PyCharm+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
.idea/
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
*.iml
modules.xml
.idea/misc.xml
*.ipr
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
.vscode/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
### Python Patch ###
.venv/
# End of https://www.gitignore.io/api/python,pycharm+all
# Created by https://www.gitignore.io/api/visualstudiocode
# Edit at https://www.gitignore.io/?templates=visualstudiocode
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
# End of https://www.gitignore.io/api/visualstudiocode
.pw
venv*/

View File

@ -1,4 +1,4 @@
FROM python:3.8-alpine
FROM python:3.8-alpine as build
WORKDIR /app
@ -6,13 +6,14 @@ COPY Pipfile* /app/
RUN pip install pipenv && pipenv install --system
COPY . /app
COPY app.py /app/app.py
COPY templates/ /app/templates
COPY data/ /app/data
RUN python ./app.py
RUN date +%d-%m-%Y > /app/date
FROM nginx:1.19-alpine
WORKDIR /app
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 8000
CMD ["gunicorn", "-w 1", "-b 0.0.0.0", "app:app"]
COPY --from=build /app/dist/ /usr/share/nginx/html/

View File

@ -6,9 +6,8 @@ verify_ssl = true
[dev-packages]
[packages]
flask = "*"
markdown2 = "*"
gunicorn = "*"
jinja2 = "*"
[requires]
python_version = "3"

44
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "9ecf6795e5fa6da82ef3858427f44b9ea7a966714a8da293c0bb16584c7e8a54"
"sha256": "1e15c77e0335394662f026bdcdeb19c891f9075651a00d0c890152608725a758"
},
"pipfile-spec": 6,
"requires": {
@ -16,44 +16,12 @@
]
},
"default": {
"click": {
"hashes": [
"sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
"sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==7.1.2"
},
"flask": {
"hashes": [
"sha256:4efa1ae2d7c9865af48986de8aeb8504bf32c7f3d6fdc9353d34b21f4b127060",
"sha256:8a4fdd8936eba2512e9c85df320a37e694c93945b33ef33c89946a340a238557"
],
"index": "pypi",
"version": "==1.1.2"
},
"gunicorn": {
"hashes": [
"sha256:1904bb2b8a43658807108d59c3f3d56c2b6121a701161de0ddf9ad140073c626",
"sha256:cd4a810dd51bf497552cf3f863b575dabd73d6ad6a91075b65936b151cbf4f9c"
],
"index": "pypi",
"version": "==20.0.4"
},
"itsdangerous": {
"hashes": [
"sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19",
"sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==1.1.0"
},
"jinja2": {
"hashes": [
"sha256:89aab215427ef59c34ad58735269eb58b1a5808103067f7bb9d5836c651b3bb0",
"sha256:f0a4641d3cf955324a89c04f3d94663aa4d638abe8f733ecd3582848e1c37035"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"index": "pypi",
"version": "==2.11.2"
},
"markdown2": {
@ -102,14 +70,6 @@
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==1.1.1"
},
"werkzeug": {
"hashes": [
"sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43",
"sha256:6c80b1e5ad3665290ea39320b91e1be1e0d5f60652b964a3070216de83d2e47c"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==1.0.1"
}
},
"develop": {}

190
app.py
View File

@ -1,110 +1,136 @@
# -*- coding: UTF-8 -*-
from datetime import datetime
from os.path import exists, splitext
import os
from datetime import date
from flask import Flask, render_template, Markup, redirect, send_file, send_from_directory
from markdown2 import markdown
app = Flask(__name__, static_url_path="", static_folder="static")
import shutil
from jinja2 import Environment, FileSystemLoader
env = Environment(
loader=FileSystemLoader("./templates")
)
def render(filename):
return markdown(
"".join(open("data/" + filename, encoding="UTF-8").readlines()),
use_file_vars=True,
extras=["use-file-vars", "tables"])
file_exts = [".html", ".md", ".txt", ".pdf", ""]
update = open("date", encoding="UTF-8").readline()
tijden = Markup(
markdown("".join(open("data/tijden.md", encoding="UTF-8").readlines()),
use_file_vars=True,
extras=["use-file-vars", "tables"]))
nieuws = Markup(
markdown("".join(open("data/nieuws.md", encoding="UTF-8").readlines()),
use_file_vars=True,
extras=["use-file-vars", "tables"]))
renders = dict()
update = date.today()
tijden = render("tijden.md")
nieuws = render("nieuws.md")
@app.context_processor
def inject_now():
return {'now': datetime.utcnow().year,
inject_now = {'now': date.today().year,
'tijden': tijden,
'nieuws': nieuws,
'update': update}
def render(filename):
return Markup(markdown(
"".join(open("data/" + filename, encoding="UTF-8").readlines()),
use_file_vars=True,
extras=["use-file-vars", "tables"]))
# if filename in renders:
# return renders[filename]
# else:
# ren = ""
# renders[filename] = ren
# return ren
@app.route('/')
def index():
return render_template("index.html", content=render("content.md"))
# @app.route('/')
# def index():
# return render_template("index.html", content=render("content.md"))
@app.route("/<string:url>")
def site(url: str):
# error handling
if url.startswith("hoofdexpo") or url.startswith("fotos"):
return redirect("/schilderijen", 301)
if url.startswith("boek&foto"):
return redirect("/boekenmeer", 301)
if url.endswith(".html"):
return redirect(url.rstrip(".html"), 301)
# @app.route("/<string:url>")
# def site(url: str):
# # error handling
# if url.startswith("hoofdexpo") or url.startswith("fotos"):
# return redirect("/schilderijen", 301)
# if url.startswith("boek&foto"):
# return redirect("/boekenmeer", 301)
# if url.endswith(".html"):
# return redirect(url.rstrip(".html"), 301)
if url.endswith(".ico"):
return send_from_directory("static", url)
# if url.endswith(".ico"):
# return send_from_directory("static", url)
# actual code
if url == "content":
return redirect("/", 301)
if exists("data/" + url.lstrip("/") + ".md"):
filename = url.lstrip("/") + ".md"
else:
filename = "404.md"
# # actual code
# if url == "content":
# return redirect("/", 301)
# if exists("data/" + url.lstrip("/") + ".md"):
# filename = url.lstrip("/") + ".md"
# else:
# filename = "404.md"
return render_template("index.html",
content=render(filename))
# return render_template("index.html",
# content=render(filename))
@app.route("/archief/<string:url>")
def archief(url: str):
if url == "content":
return redirect("/")
filename = ""
ex = ""
url, _ = splitext(url)
print(url)
for ext in file_exts:
print("data/archief/" + url + ext)
if exists("data/archief/" + url + ext):
filename = "data/archief/" + url + ext
ex = ext
break
if filename == "":
filename = "data/404.md"
ex = ".md"
if ex == ".html":
return Markup("".join(open("data/archief/" + url + ".html", encoding="utf-8").readlines()))
elif ex == ".md":
return render_template("index.html",
content=Markup(markdown("".join(open(filename, encoding="UTF-8").readlines()),
use_file_vars=True,
extras=["use-file-vars"])))
elif ex == ".txt":
return render_template("index.html", content="".join(open(filename, encoding="UTF-8").readlines()))
elif ex == ".pdf":
return send_file("data/archief/" + url + ".pdf", mimetype="application/pdf")
else:
return render_template("index.html", content="".join(open(filename, encoding="UTF-8").readlines()))
# @app.route("/archief/<string:url>")
# def archief(url: str):
# if url == "content":
# return redirect("/")
# filename = ""
# ex = ""
# url, _ = splitext(url)
# print(url)
# for ext in file_exts:
# print("data/archief/" + url + ext)
# if exists("data/archief/" + url + ext):
# filename = "data/archief/" + url + ext
# ex = ext
# break
# if filename == "":
# filename = "data/404.md"
# ex = ".md"
# if ex == ".html":
# return Markup("".join(open("data/archief/" + url + ".html", encoding="utf-8").readlines()))
# elif ex == ".md":
# return render_template("index.html",
# content=Markup(markdown("".join(open(filename, encoding="UTF-8").readlines()),
# use_file_vars=True,
# extras=["use-file-vars"])))
# elif ex == ".txt":
# return render_template("index.html", content="".join(open(filename, encoding="UTF-8").readlines()))
# elif ex == ".pdf":
# return send_file("data/archief/" + url + ".pdf", mimetype="application/pdf")
# else:
# return render_template("index.html", content="".join(open(filename, encoding="UTF-8").readlines()))
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5667)
# app.run(host="0.0.0.0", port=5667)
t = env.get_template("index.html")
if exists("./dist"):
shutil.rmtree("./dist")
os.makedirs("./dist")
for d in os.listdir("./data/"):
d = d.replace(".md", "")
if d == "content":
f = open(f"./dist/index.html", "w", encoding="utf-8")
r = t.render(content=render(f"{d}.md"), request={'path': f"/"}, **inject_now)
f.write(r)
f.close()
else:
f = open(f"./dist/{d}.html", "w", encoding="utf-8")
r = t.render( content=render(f"{d}.md"), request={'path': f"/{d}"}, **inject_now)
f.write(r)
f.close()
os.makedirs("./dist/archief")
for d in os.listdir("./data/archief"):
name,ext = splitext(d)
if ext in [".html", ".pdf"]:
shutil.copyfile(f"./data/archief/{d}", f"./dist/archief/{d}")
elif ext == ".txt":
d = d.replace(".txt", "")
# print(d)
r = t.render( content=render(f"archief/{d}.txt"), request={'url': f"/{d}"}, **inject_now)
f = open(f"./dist/archief/{d}.html", "w", encoding="utf-8")
f.write(r)
f.close()
elif ext == ".md":
d = d.replace(".md", "")
# print(d)
r = t.render( content=render(f"archief/{d}.md"), request={'url': f"/{d}"}, **inject_now)
f = open(f"./dist/archief/{d}.html", "w", encoding="utf-8")
f.write(r)
f.close()

View File

@ -1,7 +0,0 @@
{
"default": "content.md",
"list": {
},
"comment": "USE UTC!!!!!! instead of CE(S)T"
}

28
nginx.conf Normal file
View File

@ -0,0 +1,28 @@
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
try_files $uri.html $uri $uri/index.html
index index.html index.htm;
}
# location /archief/ {
# root /usr/share/nginx/html/archief;
# try_files $uri.html $uri $uri/
# index index.html index.htm;
# }
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root /usr/share/nginx/html;
# }
}

BIN
req.txt

Binary file not shown.