GoCD Playground:

This is a small set of tools that will setup a local development environment for GoCD using Docker containers.

Features include:

  • Single command setup make setup
  • Setup elastic agents using Docker runtime
  • Complete set of all required components (repository, server, agent, elastic agent base image)

Components

  • GoCD server
  • GoCD agent
  • Gogs Git server

Setup

  • Install Dependencies: make, Docker, Docker-compose
  • Run Make setup
    • creates files:
      • gohome/.ssh/id_rsa
      • gohome/.ssh/id_rsa.pub - ssh key used by GoCD to access repos for material fetching
      • agentAutoRegisterKey - contains the AutoRegister Key for GoCD agents
    • brings up:
      • GoCD server
      • Gogs server
      • GoCD agents

Configuration

  • Create a new user on the Gogs Server
  • Create a new repo for pipeline code on Gogs
  • Create some pipeline configuration inside the repo
    • You can use this as a starting point
    • Any files matching *.gocd.yaml* will be used by GoCD by default
  • Add the public key as publish key to the new git repo
  • Configure the GoCD server to use your newly created repo as a pipeline config source
    • Insert this snippet in the Config XML right after the <server> entry
 <config-repos>
    <config-repo pluginId="yaml.config.plugin" id="ots-pipeline-code">
      <git url="http://gogs:3000/my-user/my-pipeline-code-repo.git" />
    </config-repo>
  </config-repos>
  • Create a git repo on your production source control or reuse an existing one
  • Configure your production GoCD similarly, but against the production source control pipeline repository
  • Configure the production git repository as another git remote to your local clone of the pipeline repository

Pipeline development workflow

  • Edit the pipeline yaml as you see fit
  • Commit locally and push to the Gogs git remote
    • The change should be applied by GoCD shortly
    • In case of failure, the previous version will be kept and any errors will be shown on the top right corner of the GoCD UI
  • Iterate over the pipeline code locally with repeated commits (you can also amend the same commit) until you're happy with the configuration
  • When ready, tidy up your local git history and push to the production git remote to update your production GoCD configuration

Using elastic agents

Plugin setup

  • Go to the plugins page and open settings for the Docker Elastic Agent Plugin
    • Go Server URL: https://172.17.0.1:8154/go
      • edit with your hosts IP on the docker bridge network if required
      • the elastic agents will be connected to the default bridge network and have to connect to the playground endpoints via the forwarded ports on the server
    • Agent auto-register Timeout: between 1-3 minutes
    • Docker URI: unix:///var/run/docker.sock
    • Use Private Registry: False

Agent Profile setup

  • Go to the Elastic Agent Profiles and add a new profile
    • Id: Chose a name to your liking
    • Docker image: e.g. playground-base-agent
      • this is built by make as part of the setup target and contains the required credentials for access to the Gogs server
    • Host entries:
      • 172.17.0.1 gogs (edit with your host IP on the docker bridge network if required)
  • In your pipeline reference the created agent profile
  • If you want to create your own agent images base them on playground-base-agent to have the SSH keys created by the setup target built-in

Management:

Resources: