๐ Today _I_Learned/Git
[GitHub] Organization GitLab์ผ๋ก ๋ฏธ๋ฌ๋งํ๊ธฐ
nooopy
2023. 3. 30. 19:25
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 ๋ฏธ๋ฌ๋ง ์์ฑ