How to migrate from GitHub Pages to GitLab Pages

GitLab is on a roll.

They are, and have been, gaining a lot of steam in winning over professionals and laymen alike (i.e. me). When I found my educational promotion on GitHub was about to expire, along with access to free private repos, I turned to GitLab. They are really trying to make you feel inclined to do the same.

Rolling out a static website on GitHub is a bit easier than GitLab. This is mainly because their documentation is a bit more “follow x-y-z”, and they handle more things automatically (e.g. GitLab requires setting up a pipeline). But once you sort out barely more complicated DNS settings and follow a guide on a no-frills .gitlab-ci.yml file to configure said pipeline, you should be in business with GitLab pages.

Here is what I did:

  1. Already have a functioning static HTML website in a git repo (which was hosted on GitHub). I also already have multiple domains registered, with various [DNS] settings pre-configured for redirects as desired.
  2. Sign in to GitLab.com and copy the repo to my group.
    importGithub
    Go to ‘New Project’ and import the repo containing my static website.

    importGithub2
    Note: I imported from a group for my company, Corvae LLC, to a new group. The group name in GitHub is ‘CorvaeOfficial’ and in GitLab it is ‘Corvae’. I had to keep this in mind when changing the namespace and domain to get things to work.
  3. Set up my SSH key so I can easily commit updates.
  4. Commit a new .gitlab-ci.yml file that I found online for HTML:
    pages:
     stage: deploy
     script:
     - mkdir .public
     - cp -r * .public
     - mv .public public
     artifacts:
     paths:
     - public
     only:
     - master

    This auto-runs whenever there is a new commit and builds the site from ‘master’.

  5. Move all content files (e.g. css and html files) to ‘/public’ to make it consistent with the new GitLab CI/CD just configured.
  6. Add ‘www.corvae.com’ and ‘corvae.com’ new domains to the repo in my repo Settings > Pages:
    dns1.PNG
  7. Configure my DNS changes. I happen to use NameCheap.
    1. Remove the incumbent CNAME DNS Records (I also removed from the repo the CNAME file that GitHub looks for)
    2. Add two A Records (same IP Address for all GitLab Pages):
      dns2
    3. Add two TXT Records (‘@’ and ‘www’ hosts again) for both ‘www.corvae.com’ and ‘corvae.com’ as copied from the keys given in Settings > Pages (this is specific to your repo domains you added).Getting this to work was the only “struggle” and it prompted me to write this basic tutorial. What I was missing was a solid understanding of what I was configuring in the DNS settings that are entailed in this step.
  8. Go to the domains and check for verification for both domains. If they are not verified, it won’t work.

 

See Also:

  1. GitLab Pages Documentation
  2. GitLab Pages Get Started Guide
Advertisement

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s