Skip to content

Feature/image backup script #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

subahua
Copy link

@subahua subahua commented Jun 17, 2025

No description provided.

subahua and others added 9 commits August 28, 2024 01:07
…onality

Key updates include:

1.  **Image Information Retrieval:**
    *   `get_tags_data`: Asynchronously retrieves the latest n tags for a specified image from the Docker Hub API (`/v2/repositories/.../tags/`).
    *   `parse_dockerhub_url`: Parses Docker Hub page URLs to extract namespace and repository names.

2.  **Docker Operation Encapsulation:**
    *   `pull_image`: Executes `docker pull`.
    *   `tag_image`: Executes `docker tag` to mark the image for the target private repository.
    *   `docker_login`: Executes `docker login`, using credentials obtained from environment variables to log in to the target repository.
    *   `push_image`: Executes `docker push`.

3.  **Backup Recording:**
    *   `is_image_backed_up`: Checks if the image is already in the record file.
    *   `record_backup`: Writes the successfully backed-up image version to the record file.

4.  **Main Logic (`main` function):**
    *   Loads the target repository URL, namespace, and authentication credentials via environment variables.
    *   Configures the number of tags to retrieve, the record file path, and the list of image URLs to process via command-line arguments.
    *   Coordinates the entire flow: login -> get tags -> (check record -> pull -> tag -> push -> update record).
    *   Uses `aiohttp` for asynchronous API requests.

5.  **Logging and Error Handling:**
    *   Comprehensive use of the `logging` module instead of `print` to provide structured log output.
    *   Error capturing and handling for Docker command execution, API requests, and file operations.

6.  **Documentation:**
    *   Updated `README.md` with detailed instructions on script configuration (environment variables, command-line arguments), dependency installation, and execution methods.

This script can now automatically pull multiple versions of specified images from Docker Hub based on your configuration, push them to a configured private repository (such as Tencent Cloud or Alibaba Cloud), and locally record backed-up images to avoid redundant operations.
I've added a new GitHub Actions Workflow (`.github/workflows/daily_image_backup.yml`) that will automatically run the `main.py` script every day.

Key features:
- Scheduled to run daily at 02:00 UTC.
- You can also trigger it manually.
- The target repository URL, namespace, and authentication details are securely configured using GitHub Actions Secrets.
- The Workflow steps include checking out the code, setting up the Python environment, installing dependencies, and running the `main.py` script.

I've also updated the `README.md` file with instructions on how to configure and use this new Workflow, including the required GitHub Secrets.
…nese

Translate the usage instructions for the `main.py` command-line script and the `daily_image_backup.yml` GitHub Actions workflow into Chinese to improve readability for Chinese users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant