Giter Club home page Giter Club logo

repo_pull_sync_docker_image's Introduction

GitLab Repo Mirror Pull Sync - Docker Image + GitLab Scheduled Pipeline

Useful Docker image that can be used in combination with a GitLab Scheduled Pipelines for pulling remote repositories.

Normally, GitLab Community Edition (GitLab CE) only offers you to mirroring repositories via push direction. This Docker image with yaml file + scheduler allows you to sync a repository via pull mirror direction!

Have the "GitLab mirror pull" feature for free, even when using GitLab CE! Use the steps below to get started.

Docker Image

We are following Docker image in our pipeline: danger89/repo_mirror_pull (source)

GitLab Pipeline

GitLab Scheduled Pipeline yaml file (.gitlab-ci.yml). No changes are needed, the variables can be changed in the GitLab Schedule (see next heading).

If the rebase fails the pipeline aborts automatically (so no git push).

repo_pull_sync:
  image: danger89/repo_mirror_pull:latest
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
    - if: $REMOTE_URL
    - if: $REMOTE_BRANCH
    - if: $ACCESS_TOKEN
  before_script:
    - git config --global user.name "${GITLAB_USER_NAME}"
    - git config --global user.email "${GITLAB_USER_EMAIL}"
  script:
    - git checkout $CI_DEFAULT_BRANCH
    - git pull
    - git remote remove upstream || true
    - git remote add upstream $REMOTE_URL
    - git fetch upstream
    - git rebase upstream/$REMOTE_BRANCH
    - git push "https://${GITLAB_USER_LOGIN}:${ACCESS_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:${CI_DEFAULT_BRANCH}"

Note: If you want to use git merge instead of git rebase that is up to you. You can change the script above to your needs.

Create GitLab Schedule

Create Project Access token fist:

  • Go to: Settings -> Access Tokens. Check 'api' as the scope. Save the secret token for later.

Create a new GitLab Schedule:

  • Go to: CI/CD -> Schedules -> New schedule. With the following 3 variables:
    • REMOTE_URL (example: https://github.com/project/repo.git)
    • REMOTE_BRANCH (example: master)
    • ACCESS_TOKEN (see Access Token in the first step! Example: gplat-234hcand9q289rba89dghqa892agbd89arg2854)
  • Save pipeline schedule
  • Press the Play button to trigger the Schedule prematurely (for testing purpose)

repo_pull_sync_docker_image's People

Contributors

melroy89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

repo_pull_sync_docker_image's Issues

access token portion of the readme

I'd recommend adding a section in the readme that you either will need to unprotect the main branch of your mirrored copy of the git repo or you'll need to select the role of "maintainer" when making the project access token. Since the main branch is normally protected the default role of "guest" will not have the ability to push any updates to the repo even with an scope set to "api".

Question: What happens if the merge fails?

First of all, thank your for this idea. I'm using your gitlab-ci.yml in my own Gitlab :)

But what happens if the merge fails (e.g. when the upstream edited the same file as me in a different way)? Usually, an editor would be opened to resolve the conflicts which is not possible in a CI job. Would the job just fail without pushing it? This would be good, as I would receive an email then to resolve it manually.

Or might rebasing be a more suitable approach?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.