diff --git a/bin/run-jupyter-notebook b/bin/exec-odoo-jupyter similarity index 100% rename from bin/run-jupyter-notebook rename to bin/exec-odoo-jupyter diff --git a/bin/github-set-default-branch b/bin/set-github-repo-default-branch similarity index 100% rename from bin/github-set-default-branch rename to bin/set-github-repo-default-branch diff --git a/bin/update-docker-hub-readme b/bin/update-docker-hub-readme new file mode 100755 index 00000000..ca89d120 --- /dev/null +++ b/bin/update-docker-hub-readme @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +"""Update Docker Hub repository README content from local markdown files.""" + +import base64 +import json +import os +import sys + +import requests + +DOCKER_HUB_API = "https://hub.docker.com/v2" + +REPOSITORIES = [ + ("images/odoo/README.md", "mintsystem", "odoo"), + ("images/odoo-cli/README.md", "mintsystem", "odoo-cli"), + ("images/odoo-mailgate/README.md", "mintsystem", "odoo-mailgate"), + ("images/odoo-upgrade/README.md", "mintsystem", "odoo-upgrade"), +] + + +def get_docker_credentials(): + """Extract Docker Hub credentials from docker config.json.""" + docker_config_dir = os.environ.get("DOCKER_CONFIG", os.path.expanduser("~/.docker")) + docker_config_path = os.path.join(docker_config_dir, "config.json") + + if not os.path.exists(docker_config_path): + print(f"Docker config not found: {docker_config_path}") + return None, None + + with open(docker_config_path) as f: + config = json.load(f) + + auths = config.get("auths", {}) + + for key in ("https://index.docker.io/v1/", "https://index.docker.io/v1/access-token"): + if key in auths and "auth" in auths[key]: + decoded = base64.b64decode(auths[key]["auth"]).decode("utf-8") + if ":" in decoded: + username, password = decoded.split(":", 1) + return username, password + + return None, None + + +def login_docker_hub(username, password): + """Authenticate with Docker Hub and return JWT token.""" + response = requests.post( + f"{DOCKER_HUB_API}/users/login/", + json={"username": username, "password": password}, + timeout=30, + ) + response.raise_for_status() + return response.json()["token"] + + +def update_repository(token, namespace, repo, description): + """Update the full_description field of a Docker Hub repository.""" + response = requests.patch( + f"{DOCKER_HUB_API}/repositories/{namespace}/{repo}/", + headers={"Authorization": f"JWT {token}", "Content-Type": "application/json"}, + json={"full_description": description}, + timeout=30, + ) + response.raise_for_status() + return response + + +def main(): + username, password = get_docker_credentials() + if not username: + print("Could not find Docker Hub credentials.") + print("Run 'task login-docker ' first.") + sys.exit(1) + + print(f"Authenticating with Docker Hub as '{username}'...") + token = login_docker_hub(username, password) + print("Authentication successful.") + + for readme_path, namespace, repo in REPOSITORIES: + if not os.path.exists(readme_path): + print(f"Skipping {namespace}/{repo}: {readme_path} not found.") + continue + + with open(readme_path) as f: + content = f.read() + + print(f"Updating {namespace}/{repo}...") + update_repository(token, namespace, repo, content) + print(f"Updated {namespace}/{repo} successfully.") + + print("Done.") + + +if __name__ == "__main__": + main() diff --git a/prompts/27_check-version-for-list-of-modules.md b/prompts/27_check-version-for-list-of-modules.md index fc8b6644..1e6d44a9 100644 --- a/prompts/27_check-version-for-list-of-modules.md +++ b/prompts/27_check-version-for-list-of-modules.md @@ -26,12 +26,12 @@ First I want you to update the `bin/update-modules-doc` script. It should also p The file looks like this: ```csv -forge, organisation, repo, module, versions -github.com, Mint-System, odoo-apps-account-financial-reporting, account_financial_report_contra_accounts, 14.0,15.0;16.0 +forge,organisation,repo,module,versions +github.com,Mint-System,odoo-apps-account-financial-reporting,account_financial_report_contra_accounts,14.0;15.0;16.0 ... ``` -Note that command `task update-modules-doc` that is executing this script will take a long time. For every Odoo version all submodules are checked out synced: +Note that command `task update-modules-doc` that is executing this script will take a long time. For every Odoo version all submodules are checked out and synced: ```python @@ -47,7 +47,7 @@ submodules = read_gitmodules(".gitmodules") Do not execute the script. I will do it myself. -Then I would like to have a command `check-module-versions` that takes a list as input: +Then I would like to have a command `check-module-version ` that takes a list as input: ``` account_financial_report @@ -78,10 +78,12 @@ web_responsive And then looks up every module in `modules.csv` and returns a table with available versions: -``` -| name | versions | -|-----------------------|------------| -| account_reconcile_oca | 14.0, 16.0 | +```bash +cat list.txt | task check-module-version 18.0 +| name | version | +|--------------------------|---------| +| account_financial_report | 18.0 | +| account_reconcile_oca | 17.0 | ... ``` diff --git a/prompts/30_create-command-to-update-docker-hub-readme.md b/prompts/30_create-command-to-update-docker-hub-readme.md index 0597e5d9..fb81e1fd 100644 --- a/prompts/30_create-command-to-update-docker-hub-readme.md +++ b/prompts/30_create-command-to-update-docker-hub-readme.md @@ -1,7 +1,7 @@ --- title: "Create command to update Docker Hub readme" -state: draft -model: +state: completed +model: infomaniak/moonshotai/Kimi-K2.6 input_tokens: --- @@ -32,6 +32,12 @@ It uses the credentials created with `login-docker` to make the post. ## Worklog -@Clanker Add a summary here once the task has been completed. +- Created `bin/update-docker-hub-readme` Python script that reads Docker Hub credentials from `~/.docker/config.json` (or `$DOCKER_CONFIG/config.json`), authenticates with the Docker Hub API, and updates the `full_description` for each repository. +- Added `update-docker-hub-readme` function to the `task` file. +- Added the command to the `task` help table under the Docker section. +- Verified the script syntax and tested the command successfully against Docker Hub. +- Removed `python` prefix from the `update-docker-hub-readme` function call in the `task` file; the script now runs directly via its shebang. +- Renamed `bin/github-set-default-branch` to `bin/set-github-repo-default-branch`. +- Renamed `bin/run-jupyter-notebook` to `bin/exec-odoo-jupyter` and updated the function name and help table entry in the `task` file. @Clanker Set frontmatter state to completed and update info about model and token usage. diff --git a/task b/task index d3ba3aa7..c31823a3 100755 --- a/task +++ b/task @@ -50,6 +50,7 @@ help-table() { rows+=("build-odoo-cli|[output]|Build Odoo CLI Docker image.") rows+=("login-docker|[user][token]|Setup Docker Hub login credentials.") rows+=("login-podman|[user][token]|Login into registry with podman.") + rows+=("update-docker-hub-readme||Update Docker Hub repository READMEs from image folders.") rows+=("container-ps||List container processes.") rows+=("remove|[name]|Remove containers and volumes.") rows+=("test-image-script|[folder]|Test scripts of target Docker image folder.") @@ -186,7 +187,7 @@ help-table() { rows+=("===JUPYTER===| | ") rows+=("init-odoo-jupyter|[path]|Init jypyter lab directory.") rows+=("start-odoo-jupyter|[path][db]|Start juypter lab in directory.") - rows+=("run-jupyter-notebook|[path][db]|Run juypter notebook with papermill.") + rows+=("exec-odoo-jupyter|[path][db]|Run juypter notebook with papermill.") for row in "${rows[@]}"; do IFS='|' read -r cmd opt desc <<< "$row" @@ -911,6 +912,10 @@ login-podman() { podman login --username "$CONTAINER_REGISTRY_USERNAME" --password "$CONTAINER_REGISTRY_PASSWORD" docker.io } +update-docker-hub-readme() { + bin/update-docker-hub-readme +} + test-odoo-version-regex() { # If ODOO_VERSION=19.0 then @@ -1359,7 +1364,7 @@ start-odoo-jupyter() { ./bin/start-odoo-jupyter "$1" "$database" "$token" } -run-jupyter-notebook() { +exec-odoo-jupyter() { if [[ -z "$1" ]]; then echo '$1/path is empty.' exit @@ -1369,7 +1374,7 @@ run-jupyter-notebook() { database="$DB_NAME" fi - ./bin/run-jupyter-notebook "$1" "$database" + ./bin/exec-odoo-jupyter "$1" "$database" } exec() {