20

I would love to use git to host my website, and would love a platform I can log into online to go along with it (something like Github). You would think in which case, that Github pages would be the perfect route for me, though I don't want to use Github pages. I would like to host this all on my own servers like you do with Github enterprise (but for free).

I have found Gitlab and was wondering if there is anyway I can use Gitlab like Github pages. Is it possible?

  • By gitlab-like you mean GitLab's markdown and ability to update website by just pushing to a git repo? – phoops May 25 '14 at 13:29
  • I mean having my website automatically update when I make a change in a gitlab repo, so yes. – Ben Watkins May 25 '14 at 17:36
  • 1
    GitHub Pages just uses Jekyll. So install that + a web server which serves static pages, and maybe throw in a few git hooks for automated deploys of pushed content, and you're basically done. – Ajedi32 Feb 13 '15 at 16:17
  • Hey @Ajedi32 the problem with this approach is that for every new project you have the git repo and the web server setup. With GitHub pages it's just another branch that you push. – fiorix Apr 26 '15 at 2:11
  • @fiorix Yeah, if you want to automate things to that degree you'll probably need a somewhat more complex solution. Still doable though, you just need to hook in to the GitLab project creation system somehow (though I don't know how exactly, my guess is the simplest way would probably involve watching the filesystem, or perhaps some calls to the GitLab API). – Ajedi32 Apr 26 '15 at 2:19
18

Good News!

Since 8.3 (Dec 2015) GitLab has "GitLab Pages". https://about.gitlab.com/2015/12/22/gitlab-8-3-released/

This feature is available on GitLab.com (which runs EE) where you can have free, unlimited repositories, public/private.

Here is documentation for GitLab Pages, explaining how you can host for free your static websites on GitLab. http://doc.gitlab.com/ee/pages/README.html

5

I'm not really sure what you're asking. You say you want to host on your own server but your question says you want to host like gitlab pages which is not your own server.

In any case maybe this will help

This is what I do

on local pc

mkdir folderforwebsite
cd folderforwebsite
git init
echo "hello world" > index.html
git add index.html
git commit -m "initial commit"

I now have a repo locally. Copy it to the server

scp -r ../folderforwebsite username@mydomain.com:/path/from/root/to/webfolder

Now I have it on the remote server.

ssh name@mydomain.com 'cd path/to/webfolder; git checkout -b live`

Now there's both a master and live branch on the website. I do this since AFAICT you can't push to the current branch. So now we have a "live" branch which is current on the remote and a "master" branch which is not

Finally add a remote to my local repo

git remote add web ssh://name@mydomain.com/path/from/root/to/webfolder

Now, anytime I want to update the website I check stuff into my local master branch and then run this script

#!/bin/sh
set -e
set -v
git push web master
ssh username@mydomain.com git merge --ff-only master

The git push pushes my changes to the non-current branch on the webserver. The ssh then logs into the webserver and fast-forwards the changes in "master" to the current branch. In this case the "live" branch.

--ff-only says to fail if there are changes on the server.

If there are changes on the server I can pull them into my local master with

git pull web live

On more thing. Before I do any of this I setup SSH keys on the remote server so I don't have to type any passwords

This has absolutely no connection to github or gitlab. I might push my changes there as well but they're not connected.

4

There is a nodejs project that implements this: https://github.com/Glavin001/GitLab-Pages

2

With a little searching of various questions on Google, I found a way. It may not be the best way and it may be over complicated, but it should work and that's the main thing. Though, if you know a better way or can find one, please do let me know!

I found that you can deploy your code to your servers via Git hooks. All you need to do is SSH into your server, create a git repo and then set up a hook for you to push commits to this repo. This will allow you to push your commits to your servers, but has nothing to do with gitlab at this point.

The next step is to add the push url for gitlab to the same remote. This way, you will be pushing to both gitlab and the site itself each time. As a result, both the gitlab repo and the actual site will both be in sync. Though this is a hack and is definitely not efficient.

I found how to deploy your code to your servers via git from this blog post: http://sebduggan.com/blog/deploy-your-website-changes-using-git/

I found that you could add two push urls to your remotes in git from this question on stackoverflow: https://stackoverflow.com/questions/14290113/git-pushing-code-to-two-remotes

As I said, if you can find a better way, please do let me know. This will work, but it means having two versions of the same code. Of course, this is very messy and is a big waste of your server's storage.

1

Currently, the best you can do is to GitLab CI to push to a static server like Amazon S3.

If you can deploy with Git, the following (unsolved) question is specific to how to do it with gitlab: https://stackoverflow.com/questions/14288288/gitlab-repository-mirroring

There is a specific request for that at the feature tracker: http://feedback.gitlab.com/forums/176466-general/suggestions/5599145-preview-render-static-html-pages-pushed-to-repos

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.