Installing Gogs Git Server on OpenShift and make it using WebHooks to trigger builds

August 29, 2017
Tags: ,

Based on the following project, we are going to set up a Gogs Git-Server on our local OpenShift Environment, which we have set up here:

As we want to reuse our Gogs Server for some situations, we need to use the persistent version of the Template. First of all we need to have 2 persistent volumes:

$ cat <<-EOF | oc create -f -
apiVersion: v1
kind: PersistentVolume
  name: pv0001
    storage: 1Gi
  - ReadWriteOnce
    path: /var/exports/openshift/pv0001
  persistentVolumeReclaimPolicy: Recycle

$ cat <<-EOF | oc create -f -
apiVersion: v1
kind: PersistentVolume
  name: pv0002
    storage: 1Gi
  - ReadWriteOnce
    path: /var/exports/openshift/pv0002
  persistentVolumeReclaimPolicy: Recycle

We then need to create a new project where we are going to serve Gogs from:

$ oc new-project ci

And finally we are creating the new application:

$ oc process -f  —param=GOGS_VERSION=0.11.4 | oc create -f -

Please have a look here to see which version of Gogs is available for use in OpenShift:

Once Gogs is up and running successfully, try to access it via Browser:

Configure Gogs

If that works, go to openshift Web UI, login as user who has created the Gogs project, select into the Gogs project and go to Resources —> Config Maps —> gogs-config

Click on Actions —> Edit

And edit the following entries:

  • Set INSTALL_LOCK to False
  • Set SKIP_TLS_VERIFY to True

While the first property tells Gogs to provide an /install URL, the second property tells Gogs to ignore that we are using self signed certificates. Otherwise, Gogs would not be able to access the OpenShfit API.

After ‘Saving’ the config map, trigger a redeployment of the Gogs system (only Gogs, not the gogs-postgresql service). This makes sure that Gogs has the new parameters in use.

Now visit the URL again and Gogs will automatically send you over to the /install URL and lets you specify certain parameters for installation.

You have to specify database password and you should create a new user (which is automatically an admin user then). I called my user ‘gogs’ and provided a password ‘gogs’.

Click on ‘Save’ and you’ll be redirected to the overview page of Gogs.

If that all works, you should now go back to OpenShift and edit the gogs-config Config Map again to change INSTALL_LOCK to become True again (otherwise, you would always end up in the configuration page, once you’ve restarted Gogs. Or OpenShift).

Creating a new Gogs-Repository and let OpenShift be triggered by Gogs

Go to Gogs and create a new repository. I called mine ‚Sinatra‘ as I’d like to use the simple application called ‚simple-openshift-sinatra-s2i‘:

Go and clone it to your desktop and add the files to your newly created repository inside Gogs. Now go to OpenShift, login via developer user and do the following:

$ oc new-project sinatra
$ oc new-app
$ oc status

After a while you should see a new app up and running. Go and test it. Now we want to use the generated Generic WebHook URL in Gogs to trigger a new Build in OpenShift. For this either do an:

$ oc describe bc/sinatra

And you’ll see something like this:

Wanjas-MBP:devel wanja$ oc describe bc/sinatra
Name: sinatra
Namespace: sinatra
Created: 17 hours ago
Labels: app=sinatra
Latest Version: 2
Strategy: Source
From Image: ImageStreamTag openshift/ruby:2.3
Output to: ImageStreamTag sinatra:latest
Build Run Policy: Serial
Triggered by: Config, ImageChange
Webhook GitHub:

Webhook Generic:

Build Status Duration Creation Time
sinatra-2 complete 28s 2017-08-28 18:52:10 +0200 CEST
sinatra-1 complete 1m13s 2017-08-28 18:48:52 +0200 CEST

Just take the URL of „WebHook Generic“ and use it inside Gogs to trigger the build once there is a new push into this repository.

That’s it. You’ll now be able to do automated test builds on every commit (=push).

Thank you for reading.


Leave a Reply


Subscribe to our newsletter.

Please select all the ways you would like to hear from Open Sourcerers:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our newsletter platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.