mirror-to-gitea/README.md

111 lines
4.0 KiB
Markdown
Raw Normal View History

2023-02-03 23:19:23 +00:00
# Automatically Mirror Github Repo To Your Gitea Server
2019-03-09 12:47:07 +00:00
2019-03-09 13:09:05 +00:00
## Badges
2019-03-09 13:05:29 +00:00
[![image pulls](https://img.shields.io/docker/pulls/jaedle/mirror-to-gitea.svg)](https://cloud.docker.com/repository/docker/jaedle/mirror-to-gitea)
2019-03-09 13:01:04 +00:00
2019-03-09 13:09:05 +00:00
## Description
2019-03-09 13:01:04 +00:00
2023-02-03 23:19:23 +00:00
This script automatically mirrors the repositories from a github-user or github-organization to your gitea server.
Once started, it will create a mirrored repository under a given token for a gitea user, completely automatically.
2019-03-09 12:47:07 +00:00
Example:
A github user `github-user` has public repositories `dotfiles` and `zsh-config`.
2023-02-03 23:19:23 +00:00
Starting the script with a gitea token for the account `gitea-user` will create the following mirrored repositories:
2019-03-09 12:47:07 +00:00
2023-02-03 23:19:23 +00:00
- github.com/github-user/dotfiles → your-gitea.url/gitea-user/dotfiles
- github.com/github-user/zsh-config → your-gitea.url/gitea-user/zsh-config
2019-03-09 12:47:07 +00:00
The mirror settings are default by your gitea instance.
2023-02-03 23:19:23 +00:00
It is also possible to mirror private repos, which can be configred here in [#parameters](#parameters). When mirroring private repos, they will be created as private repos on your gitea server.
2021-05-16 11:08:32 +01:00
2019-03-09 12:47:07 +00:00
## Prerequisites
2023-02-03 23:19:23 +00:00
- A github user or organization with repositories
- Configured Gitea instance up and running
- User for Gitea with generated token (Settings -> Applications -> Generate New Token)
- Docker or Docker Compose
2019-03-09 12:47:07 +00:00
2023-02-03 23:19:23 +00:00
### Docker Run
2019-03-09 12:47:07 +00:00
```sh
2023-02-03 23:19:23 +00:00
docker run \
2019-03-09 12:47:07 +00:00
-d \
--restart always \
2019-03-09 12:49:37 +00:00
-e GITHUB_USERNAME=github-user \
2023-02-03 23:19:23 +00:00
-e GITEA_URL=https://your-gitea.url \
2019-03-09 12:47:07 +00:00
-e GITEA_TOKEN=please-exchange-with-token \
jaedle/mirror-to-gitea:latest
```
2023-02-03 23:19:23 +00:00
This will a spin up a docker container which will run forever, mirroring all your repositories once every hour to your gitea server.
### Docker Compose
```yaml
version: "3.3"
services:
mirror-to-gitea:
image: jaedle/mirror-to-gitea:latest
restart: always
environment:
- GITHUB_USERNAME=github-user
- GITEA_URL=https://your-gitea.url
- GITEA_TOKEN=please-exchange-with-token
#- GITHUB_TOKEN=please-exchange-with-token # Optional, set to mirror private repos
#- MIRROR_PRIVATE_REPOSITORIES=true # Optional, set to mirror private repos
# - DELAY=3600 # Optional, set to change the delay between checks (in seconds)
container_name: mirror-to-gitea
```
## Building from Source
### Prerequisites
- NodeJS
- NPM
### Build
```sh
npm install
```
If errors occur, try deleting the `package-lock.json` file and run `npm install` again.
### Build Docker Image
```sh
docker build -t mirror-to-gitea .
```
### Run With NodeJS
```sh
export GITHUB_USERNAME=github-user
export GITEA_URL=https://your-gitea.url
export GITEA_TOKEN=please-exchange-with-token
node src/index.js
```
Also export `GITHUB_TOKEN` and `MIRROR_PRIVATE_REPOSITORIES` if you want to mirror private repos, or `DELAY` if you want to change the delay between checks.
### Run With Docker
In the above Docker run command, replace `jaedle/mirror-to-gitea:latest` with `mirror-to-gitea`.
In your Docker Compose file, replace `jaedle/mirror-to-gitea:latest` with `build: .`. Then run `docker compose build` and `docker compose up -d`.
## Parameters
2019-03-09 13:27:21 +00:00
2023-02-03 23:19:23 +00:00
### Required
- `GITHUB_USERNAME`: The name of your user or organization which public repos should be mirrored
- `GITEA_URL`: The url of your gitea server
- `GITEA_TOKEN`: The token for your gitea user (Settings -> Applications -> Generate New Token)
2019-03-09 12:47:07 +00:00
2023-02-03 23:19:23 +00:00
### Optional
- `GITHUB_TOKEN`: [GitHub personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token). **Attention: if this is set, the token will be transmitted to your specified Gitea instance!**
- `MIRROR_PRIVATE_REPOSITORIES`: If set to `true`, your private GitHub repositories will also be mirrored to gitea. The `GITHUB_TOKEN` parameter must be set for this to work.
- `DELAY`: How often to check for new repositories in seconds. Default is 3600 (1 hour).
2019-03-09 12:47:07 +00:00
## Things to do
2023-02-03 23:19:23 +00:00
- Refactoring
- Think about how to test
- Better logging
- Use github token to solve problems with rate limits
- Add gitlab support
- And so on..