How to create an original Concourse Resource
Tags: concourseci, docker, beginners
Published: 2018-12-17 09:00:09

---
title: How to create an original Concourse Resource
published: true
description: Introducing how to create an original Concourse Resource with a simple example.
tags: concourse-ci, docker, beginner
---

[Concourse CI](https://concourse-ci.org/) 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](https://concourse-ci.org/implementing-resources.html).

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.
```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

```json
{ 
    "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

```json
{ 
    "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`](https://github.com/YoshiyukiKato/concourse-helloworld-resource). A project of this resource consists of 3 shell scripts and a Dockerfile. The structure is:

```tree
.
├── Dockerfile
└── assets
    ├── check
    ├── in
    └── out
```

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

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

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

### Dockerfile
```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.

```yaml
# 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
```

```shell
$ fly -t ci set-pipeline helloworld -c helloworld.yaml
```

![](https://i.imgur.com/3arGMnE.png)
![](https://i.imgur.com/4fiJ9tO.png)

Hello World! Enjoy! 😎