-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
subahua
wants to merge
39
commits into
tech-shrimp:main
Choose a base branch
from
subahua:feature/image-backup-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.