Add container build
This commit is contained in:
parent
73a318d816
commit
d1a7356088
5 changed files with 82 additions and 9 deletions
8
.dockerignore
Normal file
8
.dockerignore
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.env
|
||||
venv
|
||||
src/posts
|
||||
src/images
|
||||
site
|
||||
__pycache__
|
||||
src/cache
|
||||
src/.doit.db
|
||||
28
Containerfile
Normal file
28
Containerfile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
FROM python:alpine AS base
|
||||
WORKDIR /app
|
||||
|
||||
FROM base as deps
|
||||
WORKDIR /app
|
||||
COPY ./requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
FROM deps as scripts
|
||||
WORKDIR /app
|
||||
COPY ./backup.py .
|
||||
COPY ./entrypoint.sh .
|
||||
|
||||
FROM scripts as app
|
||||
WORKDIR /app
|
||||
COPY ./src ./src
|
||||
|
||||
FROM app AS env
|
||||
WORKDIR /app
|
||||
ENV TBS_TS="1999-09-09 09:09"
|
||||
ENV TBS_CONSUMER_KEY replace_me
|
||||
ENV TBS_CONSUMER_SECRET replace_me
|
||||
ENV TBS_OAUTH_TOKEN replace_me
|
||||
ENV TBS_OAUTH_SECRET replace_me
|
||||
ENV TBS_BLOG_NAME replace_me
|
||||
|
||||
FROM env AS final
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
38
Containerfile.www
Normal file
38
Containerfile.www
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
FROM python:alpine AS base
|
||||
WORKDIR /app
|
||||
|
||||
FROM base as deps
|
||||
WORKDIR /app
|
||||
COPY ./requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
FROM deps as scripts
|
||||
WORKDIR /app
|
||||
COPY ./backup.py .
|
||||
|
||||
FROM scripts as app
|
||||
WORKDIR /app
|
||||
COPY ./src ./src
|
||||
|
||||
FROM app AS env
|
||||
WORKDIR /app
|
||||
ARG CONSUMER_KEY
|
||||
ARG CONSUMER_SECRET
|
||||
ARG OAUTH_TOKEN
|
||||
ARG OAUTH_SECRET
|
||||
ARG BLOG_NAME
|
||||
ENV TBS_TS="1999-09-09 09:09"
|
||||
ENV TBS_CONSUMER_KEY "$CONSUMER_KEY"
|
||||
ENV TBS_CONSUMER_SECRET "$CONSUMER_SECRET"
|
||||
ENV TBS_OAUTH_TOKEN "$OAUTH_TOKEN"
|
||||
ENV TBS_OAUTH_SECRET "$OAUTH_SECRET"
|
||||
ENV TBS_BLOG_NAME "$BLOG_NAME"
|
||||
|
||||
FROM env AS final
|
||||
RUN mkdir /app/site /app/src/posts
|
||||
RUN python backup.py $TBS_BLOG_NAME
|
||||
RUN (cd src && nikola build)
|
||||
|
||||
FROM docker.io/nginx:alpine AS www
|
||||
COPY --from=final /app/site /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
14
backup.py
14
backup.py
|
|
@ -1,7 +1,6 @@
|
|||
import pytumblr
|
||||
import sys
|
||||
import os
|
||||
from time import sleep
|
||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
|
|
@ -35,7 +34,6 @@ for envkey in [
|
|||
exit(1)
|
||||
tokens.append(ek)
|
||||
|
||||
# https://github.com/tumblr/pytumblr?tab=readme-ov-file
|
||||
client = pytumblr.TumblrRestClient(*tokens)
|
||||
|
||||
|
||||
|
|
@ -72,10 +70,10 @@ def prerender(data):
|
|||
f.write(contents)
|
||||
|
||||
|
||||
try:
|
||||
blog = sys.argv[1]
|
||||
except IndexError:
|
||||
print("missing blogname argument, exiting")
|
||||
blog = os.environ.get("TBS_BLOG_NAME")
|
||||
|
||||
if not blog:
|
||||
print("missing TBS_BLOG_NAME variable, exiting")
|
||||
exit(2)
|
||||
|
||||
L = 50
|
||||
|
|
@ -83,7 +81,7 @@ params = {"limit": L, "offset": 0}
|
|||
info = client.blog_info(blog)
|
||||
total = info["blog"]["total_posts"]
|
||||
P = total // L + 1
|
||||
TS = os.environ.get("TBS_TS", str(datetime.now()))
|
||||
TS = os.environ.get("TBS_LAST_SYNC", str(datetime.now()))
|
||||
TS = int(datetime.timestamp(datetime.fromisoformat(TS)))
|
||||
|
||||
for i in range(P):
|
||||
|
|
@ -103,7 +101,5 @@ for i in range(P):
|
|||
prerender(post)
|
||||
case other:
|
||||
print("->", post["type"], post.keys())
|
||||
progress_bar(i, P, prefix="Downloading:", suffix="", length=30)
|
||||
if len(posts["posts"]) < L:
|
||||
break
|
||||
sleep(0.5)
|
||||
|
|
|
|||
3
entrypoint.sh
Executable file
3
entrypoint.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
python backup.py
|
||||
(cd src && nikola build)
|
||||
Loading…
Add table
Reference in a new issue