Sign inSign up

karser/gitbitlabhub

By karser

•Updated almost 2 years ago

Mirror Bitbucket / Gitlab / Github repositories using simple webhooks. Alpine based, pure bash

Image
0

100K+

karser/gitbitlabhub repository overview

⁠GitBitLabHub: Mirror your repositories between Bitbucket / Gitlab / Github using simple webhooks.

Docker Pulls

  • It's a simple shell script (written in pure bash, even the webserver part).
  • The docker image is Alpine based and the size is about 10 MB.
  • Single container mirrors a single repository.
  • Single-threaded. It will ignore the next webhook while the previous one is being processed. DDoS protection out-of-the-box :).

⁠Why mirror repositories?

  • You can pipe multiple services. For example, use Bitbucket private repositories as a primary storage and self-hosted Gitlab instance as a purely CI/CD tool.
  • Better safe than sorry. Mirroring repos is the only backup option for SaaS.

⁠How to use

⁠How to run using docker
docker run -it \
    -e [email protected]:vendor/src_repo.git \
    -e [email protected]:2222/vendor/dest_repo.git \
    -e SRC_DEPLOY_KEY=base64_encoded_key \
    -e DEST_DEPLOY_KEY=base64_encoded_key \
    -p 8181:8080/tcp \
    karser/gitbitlabhub

where SRC_DEPLOY_KEY and DEST_DEPLOY_KEY can be obtained by running

base64 -w 0 < ~/.ssh/project_src_id_rsa
base64 -w 0 < ~/.ssh/project_dest_id_rsa

The URL will be http://localhost:8181⁠

⁠How to run using docker-compose and traefik
version: '3.3'

services:
  gitbitlabhub_repo1:
    image: karser/gitbitlabhub
    restart: always
    networks:
      - webproxy
    environment:
      SRC_REPO: '[email protected]:vendor/src_repo.git'
      DEST_REPO: '[email protected]:2222/vendor/dest_repo.git'
      SRC_DEPLOY_KEY: 'base64_encoded_key'
      DEST_DEPLOY_KEY: 'base64_encoded_key'
    labels:
      - "traefik.enable=true"
      - "traefik.backend=gitbitlabhub_repo1"
      - "traefik.frontend.rule=Host:gitbitlabhub.example.com;PathPrefixStrip:/vendor/src_repo"
      - "traefik.port=8080"
      - "traefik.docker.network=webproxy"
    volumes:
      - ./gitbitlabhub:/storage

networks:
  webproxy:
    external: true

The URL will be https://gitbitlabhub.example.com/vendor/src_repo⁠

⁠How to setup mirroring

  1. Generate 2 deployment keys for source and destination:
ssh-keygen -t rsa -f ~/.ssh/project_src_id_rsa
ssh-keygen -t rsa -f ~/.ssh/project_dest_id_rsa

Add these keys to the repository settings of source and destination correspondingly.

cat ~/.ssh/project_src_id_rsa.pub
cat ~/.ssh/project_dest_id_rsa.pub

The Source deployment key can be marked as readonly. Depending on the platform it's called Deploy Token or Access key. See how to add deployment/access keys to bitbucket⁠, bitbucket access keys⁠, gitlab⁠, github⁠.

  1. Run this container with all environment variables configured properly (see How to use⁠ section).

  2. Create the webhook in the source repository. See how to create a webhook in bitbucket⁠, gitlab⁠, github⁠.

⁠How to build

docker build --tag karser/gitbitlabhub:latest .
docker push karser/gitbitlabhub:latest

Tag summary

Content type

Image

Digest

sha256:f5d894050…

Size

11.8 MB

Last updated

almost 2 years ago

docker pull karser/gitbitlabhub