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"
  }
]
Enter fullscreen mode Exit fullscreen mode

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"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

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"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

check

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

in

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

out

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

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"]
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
$ fly -t ci set-pipeline helloworld -c helloworld.yaml
Enter fullscreen mode Exit fullscreen mode


Hello World! Enjoy! 😎

Top comments (0)