GitHub Organization GitLab으로 미러링하기

gahyun·2023년 1월 17일
0

GitHub

목록 보기
1/2
post-thumbnail

GitHub organization 만들기는 이전 게시물에서 만들어 두었고, gitlab에서 group만들고 미러링하는 것을 이 게시물에서 보여주려고 한다.

GitLab

1. GitLab - new Group - create Group

2. group 이름, 초대 이메일 넣고 생성

3. group내에서 new project 생성

  • readme는 체크 해제 필수!!!

4. gitlab settings > CI/CD 환경변수 설정

5. gitlab token 발급 (복사 / 보관)

  • 프로필 > preference

  • token 생성


GitHub

1. organization repository > settings > security

  • TARGET_TOKEN = gitHub token 입력

  • TARGET_URL = gitlab url

  • TARGET_USERNAME = gitlab 아이디

2. github에 PUSH 할 폴더에 파일 2개 추가

.github/workflows/sync.gitlab.yml

name: Sync this repository to another repository

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  push-to-gitlab:
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0 # Fetch all history for all tags and branches

      - name: Set remote repository
        env: # Retrieve env variable from GiGHub secrets
          gitlab_url: ${{ secrets.TARGET_URL }}
          gitlab_username: ${{ secrets.TARGET_USERNAME }}
          gitlab_token: ${{ secrets.TARGET_TOKEN }}
        run: | # 토큰을 조합해서 저렇게 URL을 만들면 비번없이 push가 됩니다.
          git remote add gitlab https://${gitlab_username}:${gitlab_token}@${gitlab_url#https://};
      - name: Force push everthing
        run: | # 모든 브랜치와 태그에 대하여 push합니다. gitlab에서 보호설정이 걸려있으면 Fail할 수 있습니다.
          git push -f --all gitlab;
          git push -f --tags gitlab;

.gitlab-ci.yml

stages:
  - dockerbuild-push

package:
  only:
    - main
  image: docker:latest
  stage: dockerbuild-push
  services:
    - docker:dind
  before_script:
    - docker login registry.gitlab.com -u $GITLAB_USER -p $GITLAB_PASSWORD
  script:
    - docker build -t registry.gitlab.com/$GROUP_NAME/$PROJECT_NAME .
    - docker push registry.gitlab.com/$GROUP_NAME/$PROJECT_NAME
  after_script:
    - docker logout
  • 두 개 파일 추가하고 commit-push하면 github와 gitlab 미러링 완성

0개의 댓글