If you’re deploying GitLab with an intent to replace GitHub (or another public code repository), GitLab makes it straightforward by providing hooks right within the project-creation tooling.
GitLab offers two ways to set up integrations with GitHub: you can set up an OAuth application or use a Personal Access Token. GitLab recommends the OAuth method, because it associates all user activity on GitHub repositories with those on your self-hosted GitLab repositories. It’s a nice integration that makes for a seamless transition. Using the Personal Access Token method is easier, but it doesn’t give you all the bells and whistles.
GitLab also recommended using the same namespace (user name) in both services. So in my case, I created a GitLab account user name “jtonello” to match my GitHub one.
To start the integration, log in to your GitHub account, and navigate to Settings and Developer Settings. In the menu, choose OAuth Apps and click the “New OAuth App” button.
Here you’ll provide some basic information, including an application name and the full URL to your GitLab application home page. Critical among these is the Authorization callback URL, which must be an address GitHub can reach. This is where setting up a fully qualified domain name on your GitLab server comes in handy. If you’re working in a home lab on a NATed network, set up your router to forward port 80 or 443 to your GitLab server. In this way, you can use the WAN IP address of your router as your callback URL. I used my router’s DDNS feature with No-IP to do this with a ddns.net domain name GitHub could see and communicate with.
When you click the “Register application” button, you’ll be taken to GitHub’s OAuth application page, which shows a new Client ID and Client Secret for the application you just created. You’ll use these to complete the setup back on your GitLab host.
Don’t share them. They’re keys to your GitHub repository!
Back on your GitLab CE omnibus host, open /etc/gitlab/gitlab.rb, the main GitLab
DEEP DIVE
configuration file, and add the GitHub provider details you just created:
gitlab_rails['omniauth_providers'] = [ {
"name" => "github",
"app_id" => "YOUR_APP_ID",
"app_secret" => "YOUR_APP_SECRET", "args" => { "scope" => "user:email" } }
]
You’ll also need to make a few changes in /etc/gitlab/gitlab.rb for the initial OmniAuth Figure 5. When creating a new OAuth application in GitHub, make sure the Authorization callback URL matches that of your GitLab server and that it’s accessible.
DEEP DIVE
Configuration. In the omnibus version, uncomment and edit the following lines to look like this:
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['saml', ↪'twitter']
gitlab_rails['omniauth_auto_link_ldap_user'] = true
gitlab_rails['omniauth_block_auto_created_users'] = true
Once you save the file, you’ll need to reconfigure your GitLab server, a step that automatically restarts the various GitLab services:
$ sudo gitlab-ctl reconfigure
Figure 6. Successful setup of the OAuth integration enables a direct view of GitHub repositories from within GitLab.
DEEP DIVE
Although the reconfigure command takes only a moment (you’ll see activity scrolling by on your terminal), be patient for the GitLab services to restart. It may take a minute or two.
When the services are back up, go to the GitLab login page where you’ll now see a GitHub login option. If all went well, you now can create a new project and import repositories directly from GitHub.
Do this by clicking the “New project” button on the GitLab Projects page and choosing “GitHub” from the list on the “Import project” tab. The first time you do this, you’ll be prompted to authorize the OAuth connection with GitHub, and then you’ll see a “List your GitHub repositories” button. If you’ve decided instead to use a Personal Access Token to create your link to GitHub, you’ll see that here too.
Figure 7. This view inside GitLab shows a complete list of your GitHub projects, which can be imported as is under the current user or a different GitLab user, or it can be renamed.
DEEP DIVE
You’ll know the authorization is successful if you see the import page, and you’ll likely get an obligatory email from GitHub telling you that a third-party OAuth application has been added to you account.
You now can choose to import some or all of your GitHub repositories. You can save them to your current user account or select another. Depending on the size of the repository and your network speed, this will take anywhere from a few seconds to a few minutes.
Wrapping Up
With GitLab up and running, go ahead and try to create some new projects or clone existing ones to your workstation. GitLab even shows you the commands to run (Figure 8).
Figure 8. When you create a new project in GitLab, it offers basic Git instructions on how to get started.
DEEP DIVE
You’re now ready to commit code and expand your Git skills. ◾
John Tonello is Sr. Technical Marketing Manager for Puppet Inc. He’s been a Linux user and enthusiast since building his first Slackware system from diskette 20 years ago.
Send comments or feedback
via http://www.linuxjournal.com/contact or email [email protected].
Resources
Differences between GitHub and GitLab GitLab Application Integration List Install GitLab
Enable HTTPS for GitLab
Integrate GitLab with GitHub using OAuth Bitnami GitLab .ova