Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git
.github
.gitlab
.pytest_cache
.mypy_cache
__pycache__/
*.pyc
.venv
hub-mirror/.venv
hub-mirror/__pycache__/
hub-mirror/tests/
hub-mirror-cache/
30 changes: 30 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
stages:
- build

variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_BUILDKIT: "1"
IMAGE_NAME: "$CI_REGISTRY_IMAGE"

build-image:
stage: build
image: docker:25.0.3
services:
- name: docker:25.0.3-dind
script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
- docker build -t "$IMAGE_NAME:$CI_COMMIT_SHA" .
- docker push "$IMAGE_NAME:$CI_COMMIT_SHA"
- |
if [ -n "$CI_COMMIT_TAG" ]; then
docker tag "$IMAGE_NAME:$CI_COMMIT_SHA" "$IMAGE_NAME:$CI_COMMIT_TAG"
docker push "$IMAGE_NAME:$CI_COMMIT_TAG"
fi
- |
if [ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]; then
docker tag "$IMAGE_NAME:$CI_COMMIT_SHA" "$IMAGE_NAME:latest"
docker push "$IMAGE_NAME:latest"
fi
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

WORKDIR /app

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git \
git-lfs \
openssh-client \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

RUN python -m pip install --no-cache-dir --upgrade pip uv

COPY hub-mirror /app/hub-mirror
RUN uv sync --project /app/hub-mirror --frozen

ENV PATH="/app/hub-mirror/.venv/bin:$PATH"

CMD ["hubmirror"]
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,42 @@ steps:

有疑问、想法、问题、建议,可以通过[![Gitter](https://badges.gitter.im/hub-mirror-action/community.svg)](https://gitter.im/hub-mirror-action/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)找到我们。

## GitLab CI/CD Component

该仓库提供 GitLab CI/CD component:`hub-mirror`(见 `templates/hub-mirror.yml`)。

### GitLab.com 示例
```yaml
include:
- component: $CI_SERVER_FQDN/your-group/hub-mirror-action/hub-mirror@2.0.0
inputs:
image: $CI_REGISTRY/your-group/hub-mirror-action:latest
src: "github/kunpengcompute"
dst: "gitee/kunpengcompute"
dst-key: $GITEE_PRIVATE_KEY
dst-token: $GITEE_TOKEN
account-type: "org"
```

组件必须托管在与你的 pipeline 相同的 GitLab 实例中,因此请先将本仓库镜像到 gitlab.com 再引用。

### 自托管 GitLab
请先将本仓库镜像到你的 GitLab 实例,然后使用 `$CI_SERVER_FQDN/<group>/<project>/hub-mirror@<version>` 引用,并在 inputs 中设置 `image` 指向该仓库构建的镜像(见下方 Docker 镜像说明)。

若源或目的端是自托管 GitLab,请在 inputs 中设置 `src-endpoint`/`dst-endpoint`。

## Docker 镜像(GitLab Container Registry)

仓库提供 `Dockerfile` 与 `.gitlab-ci.yml`,在 GitLab CI 中自动构建并推送镜像到当前项目的 Container Registry。

镜像地址为:`$CI_REGISTRY_IMAGE:<tag>`,示例:`registry.gitlab.com/<group>/<project>:latest`
推送规则:
- 默认分支会推送 `latest`
- Git tag 会推送同名 tag
- 每次构建都会推送 `CI_COMMIT_SHA` tag

在 GitLab component 的 inputs 中,将 `image` 指向该镜像即可。

## 谁在使用?
超过[100+](https://github.com/search?p=2&q=hub-mirror-action+%22account_type%22+%22org%22&type=Code)组织,[4000+](https://github.com/search?l=YAML&q=%22hub-mirror-action%22&type=Code)使用者正在使用,[50+](https://github.com/search?l=Markdown&q=%22hub-mirror-action%22&type=code)来自使用者的使用教程:

Expand Down
36 changes: 36 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,42 @@ Here is a workflow to mirror the kunpengcompute org repos from Github to Gitee,

Please refer to [scenarios](https://github.com/Yikun/hub-mirror-action/blob/master/README_en.md#scenarios) for more examples.

## GitLab CI/CD Component

This repository ships a GitLab CI/CD component named `hub-mirror` (see `templates/hub-mirror.yml`).

### GitLab.com example
```yaml
include:
- component: $CI_SERVER_FQDN/your-group/hub-mirror-action/hub-mirror@2.0.0
inputs:
image: $CI_REGISTRY/your-group/hub-mirror-action:latest
src: "github/kunpengcompute"
dst: "gitee/kunpengcompute"
dst-key: $GITEE_PRIVATE_KEY
dst-token: $GITEE_TOKEN
account-type: "org"
```

Components must be hosted on the same GitLab instance as your pipeline, so mirror this repository to GitLab.com before using the include.

### Self-managed GitLab
Mirror this repository into your GitLab instance, then include it via `$CI_SERVER_FQDN/<group>/<project>/hub-mirror@<version>`, and set `image` to the container built from that repository (see the Docker Image section below).

If the source or destination is a self-managed GitLab, set `src-endpoint`/`dst-endpoint` in inputs.

## Docker Image (GitLab Container Registry)

This repository includes a `Dockerfile` and `.gitlab-ci.yml` to build and push an image to the project's Container Registry in GitLab CI.

Image address: `$CI_REGISTRY_IMAGE:<tag>` (example: `registry.gitlab.com/<group>/<project>:latest`)
Tagging rules:
- Default branch pushes `latest`
- Git tags push the same tag name
- Every build pushes a `CI_COMMIT_SHA` tag

Use that image in the GitLab component input `image`.

## Who are using?
More than [100+](https://github.com/search?p=2&q=hub-mirror-action+%22account_type%22+%22org%22&type=Code) organizations,[4000+](https://github.com/search?l=YAML&q=%22hub-mirror-action%22&type=Code) users are using, [50+](https://github.com/search?l=Markdown&q=%22hub-mirror-action%22&type=code) related blogs from users:

Expand Down
128 changes: 128 additions & 0 deletions templates/hub-mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
spec:
inputs:
job-name:
description: "Job name to run the mirror"
default: "hub-mirror"
stage:
description: "Pipeline stage for the job"
default: "sync"
image:
description: "Docker image with hubmirror CLI (built from this repo)"
type: string
cache-key:
description: "Cache key for mirror cache directories"
default: "hub-mirror-$CI_RUNNER_EXECUTABLE_ARCH"
cache-path:
description: "Directory to cache repo clones (relative to CI project dir)"
default: "hub-mirror-cache"
src:
description: "Source account, e.g. github/kunpengcompute"
type: string
dst:
description: "Destination account, e.g. gitee/kunpengcompute"
type: string
dst-key:
description: "SSH private key for destination"
type: string
dst-token:
description: "API token for destination"
type: string
account-type:
description: "Account type: user/org/group"
default: "user"
src-account-type:
description: "Source account type override"
default: ""
dst-account-type:
description: "Destination account type override"
default: ""
src-endpoint:
description: "Source GitLab endpoint for self-hosted"
default: ""
dst-endpoint:
description: "Destination GitLab endpoint for self-hosted"
default: ""
clone-style:
description: "Clone style: https or ssh"
default: "https"
black-list:
description: "Comma-separated blacklist of repos"
default: ""
white-list:
description: "Comma-separated whitelist of repos"
default: ""
static-list:
description: "Comma-separated static repo list"
default: ""
force-update:
description: "Force push to destination"
type: boolean
default: false
debug:
description: "Enable debug logs"
type: boolean
default: false
timeout:
description: "Timeout per git command, e.g. 30m"
default: "30m"
api-timeout:
description: "API request timeout in seconds"
type: number
default: 60
mappings:
description: "Repo mappings, e.g. A=>B, C=>CC"
default: ""
lfs:
description: "Enable Git LFS support"
type: boolean
default: false
---
"$[[ inputs.job-name ]]":
stage: $[[ inputs.stage ]]
image:
name: $[[ inputs.image ]]
entrypoint: [""]
variables:
GIT_STRATEGY: none
cache:
key: $[[ inputs.cache-key ]]
paths:
- $[[ inputs.cache-path ]]
script:
- set -eu
- LFS="$[[ inputs.lfs ]]"
- mkdir -p ~/.ssh
- printf "%s" "$[[ inputs.dst-key ]]" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- printf "StrictHostKeyChecking no\n" >> ~/.ssh/config
- |
if [ "$LFS" = "true" ]; then
git lfs install
fi
- |
CACHE_PATH="$[[ inputs.cache-path ]]"
if [ "${CACHE_PATH#/}" = "$CACHE_PATH" ]; then
CACHE_PATH="$CI_PROJECT_DIR/$CACHE_PATH"
fi
mkdir -p "$CACHE_PATH"
- |
hubmirror \
--src "$[[ inputs.src ]]" \
--dst "$[[ inputs.dst ]]" \
--dst-token "$[[ inputs.dst-token ]]" \
--account-type "$[[ inputs.account-type ]]" \
--src-account-type "$[[ inputs.src-account-type ]]" \
--dst-account-type "$[[ inputs.dst-account-type ]]" \
--src-endpoint "$[[ inputs.src-endpoint ]]" \
--dst-endpoint "$[[ inputs.dst-endpoint ]]" \
--clone-style "$[[ inputs.clone-style ]]" \
--cache-path "$CACHE_PATH" \
--black-list "$[[ inputs.black-list ]]" \
--white-list "$[[ inputs.white-list ]]" \
--static-list "$[[ inputs.static-list ]]" \
--force-update "$[[ inputs.force-update ]]" \
--debug "$[[ inputs.debug ]]" \
--timeout "$[[ inputs.timeout ]]" \
--api-timeout "$[[ inputs.api-timeout ]]" \
--mappings "$[[ inputs.mappings ]]" \
--lfs "$[[ inputs.lfs ]]"
Loading