Can be used as a template for developing a concourse resource.
Table of Contents
Documentation and Reference
- concourse-resource-template docker image on DockerHub
- This repos github webpage built with concourse
A concourse resource is a docker image.
It requires 3 kinds of scripts or executables,
- check - Detecting new versions of the STUFF (e.g. git version)
- in - GET STUFF
- out - PUT STUFF
You build your resource with a Dockerfile by using the
concourse docker base image
and adding your scripts/executables to /opt/resource
.
The three scripts/executables can be written with bash, go, etc.
- My go is build is located in /build-resource-using-go (In development)
- My bash build is located in /build-resource-using-bash
check is performed before anything can use the resource. It is used to determine if the STUFF has changed (checks version of STUFF).
Concourse will send stdin for check
to parse, where the source
and comes from the pipeline and the version comes from the check.
{
"source": {
"source1": "source1 info",
"source2": "source2 info",
"source3": "source3 info"
},
"version": {
"ref": "null"
}
}
In this example, I will mimic a getting a new version and increment until version 5.
Check will send stdout that will be used in the next step in the pipeline.
[
{
"ref": "1"
}
]
The in is performed after a check has confirmed there is something there. For my resource, in will mimic fetching STUFF and place a file in the working directory.
Concourse will send stdin for in
to parse, where the source
and params come from the pipeline and the version comes from the check.
{
"params": {
"param1": "get param1",
"param2": "get param2",
"param3": "get param3"
},
"source": {
"source1": "source1 info",
"source2": "source2 info",
"source3": "source3 info"
},
"version": {
"ref": "1"
}
}
In this example, I will mimic a fetch some STUFF and place a file
get_fetch.json
in the working directory.
Input will send stdout that will be used in the next step in the pipeline.
{
"version": {
"ref": "1"
},
"metadata": [
{ "name": "author", "value": "Jeff DeCola"},
{ "name": "author_date", "value": "March 2023"},
{ "name": "executable", "value": "in"},
{ "name": "version", "value": "1" }
]
}
The out will mimic updating STUFF and is performed after the task.
Concourse will send stdin for out
to parse, where the source
and params come from the pipeline.
{
"params": {
"param1": "put param1",
"param2": "put param2",
"param3": "put param3"
},
"source": {
"source1": "source1 info",
"source2": "source2 info",
"source3": "source3 info"
}
}
In this example, I will mimic a push/deploy to STUFF and place a file
put_fetch.json
in the working directory.
It is important you must recheck version here. So you must get the version.
You send stdout that will be used in the next step in the pipeline.
{
"version": {
"ref": "1"
},
"metadata": [
{ "name": "author", "value": "Addie DeCola"},
{ "name": "author_date", "value": "April 2021"},
{ "name": "executable", "value": "out"},
{ "name": "version", "value": "1" }
]
}
I am using bash shell scripts to build the resource docker image. Using go is still in development.
To build.sh using the Dockerfile,
cd build-resource-using-bash/build
sh build-resource.sh
Note how a concourse base image is used to build the resource.
To push.sh the resource docker image to dockerhub,
cd build-resource-using-bash/push
sh push.sh
You can check this docker image,
docker images jeffdecola/concourse-resource-template
docker run --name concourse-resource-template -dit jeffdecola/concourse-resource-template
docker exec -i -t concourse-resource-template /bin/bash
cd /opt/resource
tree
docker logs concourse-resource-template
docker rm -f concourse-resource-template
Now we can test the resource in a concourse pipeline.
To set-pipeline.sh for concourse,
cd test-this-resource
sh set-pipeline.sh.
Where the pipeline.yml,
#------------------------------------------------------------------------------------------
jobs:
#**********************************************
- name: job-test-concourse-resource-template
#**********************************************
plan:
# GET REPO FROM GITHUB
- get: concourse-resource-template
trigger: true
# CONCOURSE RESOURCE TEMPLATE
- get: concourse-resource-template-test
params:
param1: "get param1"
param2: "get param2"
param3: "get param3"
# RUN TASK IN REPO USING ALPINE DOCKER IMAGE
- task: task-test-concourse-resource-template
file: concourse-resource-template/test-this-resource/tasks/task-test-concourse-resource-template.yml
# TASK SUCCESS
on_success:
do:
# CONCOURSE RESOURCE TEMPLATE
- put: concourse-resource-template-test
params:
param1: "put param1"
param2: "put param2"
param3: "put param3"
#------------------------------------------------------------------------------------------
resource_types:
- name: jeffs-resource
type: docker-image
source:
repository: jeffdecola/concourse-resource-template
tag: latest
#------------------------------------------------------------------------------------------
resources:
- name: concourse-resource-template
type: git
icon: github
source:
uri: git@github.com:jeffdecola/concourse-resource-template.git
branch: master
private_key: ((git_private_key))
- name: concourse-resource-template-test
type: jeffs-resource
source:
source1: "source1 info"
source2: "source2 info"
source3: "source3 info"
Note: You will need to put your ((git_private_key))
in a .credentials
file in the root of this repo.