Add a templater for both Docker Hub and Seafile's forum project description

This commit is contained in:
flow.gunso
2020-03-10 22:34:43 +01:00
parent 878887361a
commit 6b52b102c8
6 changed files with 112 additions and 3 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
.idea/ .idea/
*.pyc *.pyc
docker-compose.test.yml docker-compose.test.yml
venv/
*.description

View File

@@ -19,7 +19,7 @@ build:
- tags - tags
artifacts: artifacts:
paths: paths:
- $CI_PROJECT_NAME.tar - "$CI_PROJECT_NAME.tar"
test: test:
stage: test stage: test
@@ -29,7 +29,7 @@ test:
- schedules - schedules
artifacts: artifacts:
paths: paths:
- $CI_PROJECT_NAME.tar - "$CI_PROJECT_NAME.tar"
publish: publish:
stage: publish stage: publish
@@ -38,10 +38,20 @@ publish:
- tags - tags
artifacts: artifacts:
paths: paths:
- $CI_PROJECT_NAME.tar - "$CI_PROJECT_NAME.tar"
#update_docker_hub_full_description: #update_docker_hub_full_description:
# stage: publish # stage: publish
# script: /bin/bash -e .utilities/update-docker-hub-full-description.sh # script: /bin/bash -e .utilities/update-docker-hub-full-description.sh
# only: # only:
# - master # - master
description_templater:
image: python/3.8-alpine
stage: build
script: sh -e .utilities/templates/templater.sh
only:
- tags
artifacts:
paths:
- "*.description"

View File

@@ -0,0 +1,2 @@
click==7.1.1
Jinja2==2.11.1

View File

@@ -0,0 +1,27 @@
Hello everyone,
I wanted to use files from my Seafile server within Docker containers.
I started looking for existing image featuring a Seafile client on Docker Hub. There are some, but with issues such as non-existant/vague documentation or improper tagging.
I don't know if it's something that people are looking for, but I made one. It's available at flowgunso/seafile-client in Docker Hub.
Example usage with docker-compose and for the docker cli are provided. Essentially, it runs `seaf-cli sync`, but you have to pass to the container your Seafile server URL, your credentials and the library ID you want to sync with. Then you can share the path `/library` as a volume to your containers for your own usages.
Feedback is welcome so I can keep improving it.
# Quick informations
**[flowgunso/seafile-client](https://hub.docker.com/r/flowgunso/seafile-client)** on Docker Hub, latest stable version: **2.1.1**
Contribute and report issues on [Gitlab](https://gitlab.com/flwgns-docker/seafile-client/).
## Features
* Synchronize a single Seafile library, available at the path `/library/'.
* Password protected librairies are supported.
* Two factor authentication is supported.
* Upload and download speeds are configurable.
* SSL certificates are skippable.
# Change log
[details]
{{ changelog }}
[/details]

View File

@@ -0,0 +1,63 @@
#!/usr/bin/env python3
import re
from jinja2 import Template
import click
README_FILENAME = "README.md"
CHANGELOG_FILENAME = "CHANGELOG.md"
SEAFILE_TOPIC_POST_TEMPLATE_FILENAME = ".utilities/templates/seafile_topic_post.template"
DOCKER_HUB_DESCRIPTION_FILENAME = "docker_hub.description"
SEAFILE_FORUM_TOPIC_POST_DESCRIPTION_FILENAME = "seafile_forum_topic_post.description"
def translate_issues_references_into_urls(string):
return re.sub(
r' #([0-9]+)',
r' [issue#\1](https://gitlab.com/flwgns-docker/seafile-client/-/issues/\1)',
string)
def translate_markdown_links_of_repository_files_into_urls(string, ref):
return re.sub(
r'(\[.+\])\((?!.+:\/\/)(?!mailto:.+)(.+)\)',
r'\1(https://gitlab.com/flwgns-docker/seafile-client/-/blob/{}/\2)'
.format(ref),
string)
@click.command()
@click.argument('ref', type=click.STRING)
def templater(ref):
"""CLI entrypoint the templater."""
if len(ref) != 40:
raise Exception("Commit reference must be 40 characters long (i.e. not the short ref)")
# Extract text from the README.md, CHANGELOG.md and the Seafile forum topic post template files.
with open(README_FILENAME, mode="rt") as fo:
readme_text = fo.read()
with open(CHANGELOG_FILENAME, mode="rt") as fo:
changelog_text = fo.read()
with open(SEAFILE_TOPIC_POST_TEMPLATE_FILENAME, mode="rt") as fo:
seafile_topic_post_template_text = fo.read()
# Generate the Docker Hub description by:
# - translating Markdown links of repository files to reachable URLs
docker_hub_description = translate_markdown_links_of_repository_files_into_urls(readme_text, ref)
with open(DOCKER_HUB_DESCRIPTION_FILENAME, mode="wt") as fo:
fo.write(docker_hub_description)
# Generate the Seafile forum topic post description by:
# - translating issues reference into reachable URLs
# - templating the previous into the existing post
seafile_topic_post_template = Template(seafile_topic_post_template_text)
changlog_reachable_issue_urls = translate_issues_references_into_urls(changelog_text)
seafile_topic_post_description = seafile_topic_post_template.render(changelog=changlog_reachable_issue_urls)
with open(SEAFILE_FORUM_TOPIC_POST_DESCRIPTION_FILENAME, mode="wt") as fo:
fo.write(seafile_topic_post_description)
if __name__ == "__main__":
templater()

View File

@@ -0,0 +1,5 @@
#!/bin/sh
pip install -r .utilities/templates/requirements.txt
python ./utilities/templates/templater.py $CI_COMMIT_SHA