Swift package manager is based on the new gitee image acceleration scheme (acceleration service for Chinese users)

Swift package manager is based on the new gitee image acceleration scheme (acceleration service for Chinese users)
I have studied image acceleration for a long time and have written many related technical articles.
[1] Some experience on swift package manager acceleration
[2] About using swift package manager acceleration scheme 2.0 in China
[3] Swift package manager acceleration (mirroring)
This article is extended on the basis of [3], and should be regarded as the last article in the mirror series. Who knows? I don't know whether the recent mirror service is interesting or how long it can serve the community.
@Mattt write image service proposal has been delayed and may be released together with WWDC in 2022.
Although the article [3] mentioned how to configure the image, the image of gitee is very miscellaneous and may not be very consistent with the version of GitHub, so it can't be used basically. I was wondering why I couldn't do a mirror service? Would it be better.

First attempt

The first time I thought about it, I was going to write a command line and make it distributed. When everyone is using it, if the central warehouse does not exist, the local production will be promoted to gitee, and others can use the produced image.
Considering that making an image requires an agent to download the code of GitHub locally and everyone uses it, what should we do? The plan was abandoned.

Second attempt

In order to unify everyone's image making, I wrote a set of services through vapor. However, the server needs to start the agent and push all branches and all tags, which is very troublesome.
I tried this plan and gave it up.

Third attempt

Through packet capture analysis, gitee automatically imports the interface of GitHub library, and makes images through the interface. However, due to the problem of session permission, it is not a good way, and it was quickly abandoned.

Fourth attempt

When I was helpless, I suddenly searched for information and saw that GitHub action was used to make images. This gave me hope. Soon I had the opportunity to GitHub action and completed the development of the first version.
There was no server at that time. At that time, I used personal MAC + ngrok to open services. Later, I met Huawei cloud for 40 yuan a year, so I bought it for one year.
However, there are many problems in the operation of the server. I have created many GitHub actions, resulting in subsequent additions. All of them will go again at the same time. When thousands of GitHub actions are synchronized, each new GitHub action will be started thousands of times, which is completely impossible.
Finally, I would like to thank the author of @OHeroJ irds for his suggestions for improvement.
Distinguish different GitHub actions through branches to prevent more and more runs
Batch production by grabbing the library with swiftpackageindex Star > 1000
The solution I take later is to use vapor's queue to perform the mirroring task
Create image successfully, delete YML, create other YML start tasks, and ensure that the YML file is within 1 (try)
If more than 1000 updates are requested and the time is less than 1 week, remake the image and keep the library up-to-date
When the image making library with the same name already exists, check that the package with the same name already exists Whether the base64 content of swift is the same. If it is different, create other organizations to make images
Climb to all warehouses of swiftpackageindex and import more than 4000 (currently importing)
Finally, the fourth attempt was correct.

Use mirror

Install MINT

brew install mint

Setting environment

export PATH=$PATH:$HOME/. mint/bin

Installing spmmc

mint install josercc/ SwiftPackageManagerMirrorCommand@main  -f

1 add image to project

spmmc add  https://github.com/vapor/vapor.git

2 initialize or update the image to the project

spmmc init


For swiftpackagemanagermirrorcommand, this command is also written based on swiftpackagemanager. In order to solve his acceleration, I prepare his dependency to create a configuration file separately into gitee.
I'm also going to use fluent to write a foreground and background service respectively. The foreground displays all the image libraries and the image libraries waiting. Do some image management services in the background. I also want to add login function later. By the way, learn about the authorization of vapor and count the number of users of image.

1 Like