The thoughts of G. Allen Morris III

Using 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

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

  - build
  - test
  - deploy

  stage: deploy
    - rake update
    - master
    - docker

And in my Rakefile I have

require "net/http"
require "uri"

uri = URI.parse('' + ENV['SECRET'])

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

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.