DEV Community

Yoshiyuki Kato
Yoshiyuki Kato

Posted on

How to create an original Concourse Resource

Concourse CI is an awesome CI tool developed by pivotal. It provides simplified scheme to define pipelines and rich visualization of their status. To compose a pipeline on Concourse, you can use existing Concourse Resource to define usual tasks such as git operation and slack notification. And also, it is not difficult for you to provide your original concourse resource.

A concourse resource is a docker image. It requires 3 kinds of scripts: check, in and out. You can create your original concourse resource by implementing these scripts, and putting them in the path of /opt/resources with executable permission.

It is required for each script to output result of its execution by json in appropriate format as follows:

check

A list of version info json.

[
  {
      "ref": "a ref value",
      "key": "value"
  }
]

in

  • version: A version info json.
  • metadata: A list of metadata json
    • item:
      • name: name of a metadata
      • value: value of a metadata
{ 
    "version": {
        "ref": "a ref value",
        "key": "value"
    },
    "metadata": [
        { 
            "name": "metadata_name",
            "value": "metadata_value"
        }
    ]
}

out

  • version: A version info json.
  • metadata: A list of metadata json
    • item:
      • name: name of a metadata
      • value: value of a metadata
{ 
    "version": {
        "ref": "a ref value",
        "key": "value"
    },
    "metadata": [
        { 
            "name": "metadata_name",
            "value": "metadata_value"
        }
    ]
}

Create Hello World Resource πŸŒ…

Now let's create a super simple concourse resource, helloworld. A project of this resource consists of 3 shell scripts and a Dockerfile. The structure is:

.
β”œβ”€β”€ Dockerfile
└── assets
    β”œβ”€β”€ check
    β”œβ”€β”€ in
    └── out

check

#!/bin/bash
echo '[{ "ref": "none",  "message": "Hello World!" }]'

in

#!/bin/bash
echo '{ "version": { "ref": "none", "message": "Hello World" }, "metadata": [{ "name": "message", "value": "Hello World" }] }'

out

#!/bin/bash
echo '{ "version": { "ref": "none", "message": "Hello World" }, "metadata": [{ "name": "message", "value": "Hello World" }] }'

Dockerfile

FROM alpine:3.7
RUN apk add --update --upgrade --no-cache bash
ADD assets /opt/resource
RUN chmod +x /opt/resource/*
WORKDIR /
ENTRYPOINT ["/bin/bash"]

As you know, it is easy to publish the project as a dockerhub repo. You only have to put the project to your github repo, and set automated build to the repo from dockerhub.

...Published? Cool!
Then, let's create a hello world pipeline on your Concourse.

# save this file as helloworld.yaml
resource_types:
- name: helloworld
  type: docker-image
  source:
    # set repo of your helloworld resource
    repository: {{YOUR_ACCOUNT/HELLOWORLD_RESOURCE}}
    ## or use my helloworld resource
    # repository: yoshiyuki/concourse-helloworld-resource

resources:
- name: helloworld
  type: helloworld

jobs:
- name: Hello World
  plan:
  - get: helloworld
  - put: helloworld
$ fly -t ci set-pipeline helloworld -c helloworld.yaml


Hello World! Enjoy! 😎

Top comments (0)