The thoughts of G. Allen Morris III

Using gitlab.com to publish your website.

February 24th 2018

This morning I decided that it was time to clean up this little blog.

One of my problems is updating the site, but with gitlab it is quite easy to set a hook to get it to publish the web site for me after each push.

To get each push to update our web server we create an .gitlab-ci.yml file with the following text in it.

image: ruby:2.3

before_script:
  - gem install bundler --no-ri --no-rdoc
  - bundle install --jobs $(nproc)  "${FLAGS[@]}"

stages:
  - build
  - test
  - deploy

update_server:
  stage: deploy
  script:
    - rake update
  only:
    - master
  tags:
    - docker

And in my Rakefile I have

require "net/http"
require "uri"

uri = URI.parse('https://www.gam3.net/cgi-bin/update_blog?secret=' + ENV['SECRET'])

desc "Update the web server."
task :update do
  res = Net::HTTP.get_response(uri)
  puts res.body
end

Now after every push an endpoint is called by gitlab. By adding more code to the .gitlab-ci.yml file I can have it test the code before it called the endpoint, or only update the server when a particular type or tag is pushed.

On the server side I just hava simple cgi-bin script that runs 'git pull' and restarts apache when it is accessed.

https://gitlab.com/gam3/myBlog