diff --git a/.gitignore b/.gitignore index e075d9c..b922815 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea/ *.pyc docker-compose.test.yml +venv/ +*.description \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c530c3c..69f419b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ build: - tags artifacts: paths: - - $CI_PROJECT_NAME.tar + - "$CI_PROJECT_NAME.tar" test: stage: test @@ -29,7 +29,7 @@ test: - schedules artifacts: paths: - - $CI_PROJECT_NAME.tar + - "$CI_PROJECT_NAME.tar" publish: stage: publish @@ -38,10 +38,20 @@ publish: - tags artifacts: paths: - - $CI_PROJECT_NAME.tar + - "$CI_PROJECT_NAME.tar" #update_docker_hub_full_description: # stage: publish # script: /bin/bash -e .utilities/update-docker-hub-full-description.sh # only: # - master + +description_templater: + image: python/3.8-alpine + stage: build + script: sh -e .utilities/templates/templater.sh + only: + - tags + artifacts: + paths: + - "*.description" diff --git a/.utilities/templates/requirements.txt b/.utilities/templates/requirements.txt new file mode 100644 index 0000000..082041b --- /dev/null +++ b/.utilities/templates/requirements.txt @@ -0,0 +1,2 @@ +click==7.1.1 +Jinja2==2.11.1 diff --git a/.utilities/templates/seafile_topic_post.template b/.utilities/templates/seafile_topic_post.template new file mode 100644 index 0000000..e235def --- /dev/null +++ b/.utilities/templates/seafile_topic_post.template @@ -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] diff --git a/.utilities/templates/templater.py b/.utilities/templates/templater.py new file mode 100644 index 0000000..6d0af3e --- /dev/null +++ b/.utilities/templates/templater.py @@ -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() diff --git a/.utilities/templates/templater.sh b/.utilities/templates/templater.sh new file mode 100644 index 0000000..f734ca6 --- /dev/null +++ b/.utilities/templates/templater.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +pip install -r .utilities/templates/requirements.txt + +python ./utilities/templates/templater.py $CI_COMMIT_SHA