If you’re switching over from GitHub to GitLab or vice versa, you might want to sync up your repositories so that if there’s an update to one, it’ll be reflected in the other.
GitLab has some cool features to import a repository from GitHub pretty easily as a project. Once you import a project over, you’ll want to make sure the repos get synced. Click on ‘Settings’ > ‘Repository’.
I clicked ‘Mirror repository’ and under my Git repository URL, I have
https://git@github.com/WilliamQLiu/my_repo_name.git
. For Authentication Method, I’m using a ‘Password’, which
is a Token that I generated on GitHub (I’m using Token since I have 2FA).
You can generate a token under ‘Settings’ > ‘Repository’ and add a ‘Deploy Token’. That way you can run say git clone using that token.
E.g. git clone https://my-token-username:my-token-password@gitlab.com/mycompany/mydept/myproject.git
I setup a remote repository that I want to update anytime my GitLab repo changes.
I clicked ‘Settings’ > ‘Repository’ > ‘Mirroring repositories’ > ‘Mirror a repository’ and for the URL I have:
https://<enter_my_token>@github.com/WilliamQLiu/my_repo_name.git
.
Don’t worry, the Token is hidden. Since I’m using a token, I’m going to use a ‘https’ url instead of ssh url. For ‘Authentication Method’, you can leave that as ‘None’ since we have our token in the url.
That’s it, you should be synced!
Depending on the files you have in your repo, GitLab will run different configurations and commands:
.gitlab-ci.yml
- what scripts and environments to runPipfile
or runtime.txt
- specify the version of PythonIf you don’t have any of the above, you can enable ‘AutoDevops’ where GitLab will try to guess what you’re building using a Heroku buildpack. To enable, click on ‘Settings > CI/CD > Auto Devops > Enable Auto DevOps’
So if you want to test the CI system without having to keep making updates thinking you fixed an issue (only to have one or two tests fail), you can use gitlab runner.
https://docs.gitlab.com/runner/install/linux-manually.html
Give permissions for the file to execute:
sudo chmod +x /usr/bin/gitlab-runner
Create a GitLab CI user:
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
Install and run as a service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
Start and Stop the Service
sudo gitlab-runner start
sudo gitlab-runner stop
Install gitlab-ci-multi-runner, which is the exact same application that runs the tests on the GitLab CI instance:
gitlab-ci-multi-runner exec docker <test_name_command>
e.g. gitlab-ci-multi-runner exec docker test
A test command could be like pytest
It’ll check for a .gitlab-ci.yml file in your repo and run that.
A .gitlab-ci.yml
file will define a set of jobs. Certain keywords like before_script
will be executed before
each job.
See documentation here: https://docs.gitlab.com/ee/ci/yaml/README.html
The default gitlab ci file is here:
https://gitlab.com/gitlab-org/gitlab-ci-yml/blob/master/Auto-DevOps.gitlab-ci.yml
There’s a built-in linter under your project (as /ci/lint
)
https://gitlab.com/MyTeam/my_repo/-/ci/lint
Insert your .gitlab-ci.yml file there and Validate it.