diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..cb0d94e --- /dev/null +++ b/.drone.yml @@ -0,0 +1,41 @@ +kind: pipeline +name: default + +steps: + - name: docker + image: plugins/docker + settings: + registry: registry.d1v3.de + repo: registry.d1v3.de/dnd-spellcard-builder + username: + from_secret: docker_username + password: + from_secret: docker_password + tags: latest + auto_tag: true + - name: dockerroot + image: plugins/docker + settings: + registry: registry.d1v3.de + repo: registry.d1v3.de/dnd-spellcard-builder-root + dockerfile: Dockerfile.root + username: + from_secret: docker_username + password: + from_secret: docker_password + tags: latest + auto_tag: true +--- +kind: secret +name: docker_username +get: + path: kv/data/drone/docker + name: username +--- + +kind: secret +name: docker_password +get: + path: kv/data/drone/docker + name: token + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6fff426 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.8-alpine as base + +FROM base as builder +RUN mkdir /install +WORKDIR /install +COPY requirements.txt /requirements.txt +RUN pip install --install-option="--prefix=/install" -r /requirements.txt + +FROM base +COPY --from=builder /install /usr/local +RUN addgroup -S appgroup && adduser -S appuser -G appgroup + +WORKDIR /home/appuser +USER appuser + +COPY ./ ./ +ENTRYPOINT ["python", "./genspells.py"] diff --git a/Dockerfile.root b/Dockerfile.root new file mode 100644 index 0000000..97493dc --- /dev/null +++ b/Dockerfile.root @@ -0,0 +1,14 @@ +FROM python:3.8-alpine as base + +FROM base as builder +RUN mkdir /install +WORKDIR /install +COPY requirements.txt /requirements.txt +RUN pip install --install-option="--prefix=/install" -r /requirements.txt + +FROM base +COPY --from=builder /install /usr/local +WORKDIR /home/appuser + +COPY ./ ./ +ENTRYPOINT ["python", "./genspells.py"] diff --git a/genspells.py b/genspells.py index de7cfaf..407c750 100644 --- a/genspells.py +++ b/genspells.py @@ -23,7 +23,9 @@ def get_template(name): line_comment_prefix="%#", trim_blocks=True, autoescape=False, - loader=jinja2.FileSystemLoader(os.path.abspath("templates/")), + loader=jinja2.FileSystemLoader( + os.path.abspath(os.path.join(os.path.dirname(__file__), "templates/")) + ), ) template = latex_jinja_env.get_template(f"{name}.tex.jinja") return template @@ -59,9 +61,11 @@ def main(): spells.update(json.load(jf)) if args.characterclass != "All": - spells = dict(filter(lambda x: args.characterclass in x[1]["classes"], spells.items())) + spells = dict( + filter(lambda x: args.characterclass in x[1]["classes"], spells.items()) + ) - spells = dict(sorted(spells.items(), key=spell_sorter(args.sort.split(',')))) + spells = dict(sorted(spells.items(), key=spell_sorter(args.sort.split(",")))) pages = generate_pages(spells, args.twosided) filename = args.output if args.output is not None else args.characterclass write_doc(filename, pages) @@ -75,8 +79,8 @@ def write_doc(filename, pages): def generate_pages(spells, twosided=False): spellpages = [] back = get_template("spellcard_back").render() - for i in range(0, len(spells)+9, 10): - spellpages.append(generate_page(list(spells.items())[i:i+10])) + for i in range(0, len(spells) + 9, 10): + spellpages.append(generate_page(list(spells.items())[i : i + 10])) if twosided: spellpages.append(back) if not twosided: @@ -109,5 +113,6 @@ def latex_format(text): text = re.sub(r"([0-9]+)\sm", r"\1~m", text) return text + if __name__ == "__main__": main()