Skip to content

Commit 6867fad

Browse files
authored
FT-150: (#545)
Add instruction for local debugging Add logic to fail on error Add parameters to easily overwrite image name, version and registry Signed-off-by: Laurent <[email protected]>
1 parent 707764f commit 6867fad

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

incubating/pipeline-trigger-merge/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,23 @@ MergeTriggersIntoPipelines:
4949
SPEC: spec.yml
5050
ONLY_CHANGED: true
5151
TRIGGERS_SUBDIR: "triggers"
52-
```
52+
```
53+
54+
## Testing and Debugging
55+
56+
In order to speed up development (or debugging), we recommend to run the image
57+
locally and mounting the your local folder to your container.
58+
59+
To do that,
60+
61+
1. we will be running docker run (be sure the daemon is running on your local box)
62+
2. mount local folder there your spec and triggers are located
63+
3. mount the .cfconfig file (to be able to call the CLI)
64+
4. Pass variables as environment variables
65+
66+
```sh
67+
docker run -v ~/.cfconfig:/root/.cfconfig -v $(pwd)/sample:/foo \
68+
-e SPEC=/foo/spec.yml \
69+
-e TRIGGERS='/foo/TRIGGERS /foo/trig1.yml' \
70+
quay.io/codefreshplugins/pipeline-trigger-merge:1.1.0
71+
```

incubating/pipeline-trigger-merge/merge.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#/bin/#!/usr/bin/env bash
1+
#!/bin/bash
22

33
process_dir() {
44
echo "Processing trigger directory $1"
@@ -25,11 +25,40 @@ process_file() {
2525
fi
2626
echo "WARNING: Unknown trigger file $1"
2727
}
28-
export curdir=`pwd`
29-
export count=1
28+
29+
# exit on error
30+
set -e
31+
echo "pipeline-trigger-merge v1.1.0"
32+
33+
count=1
3034
echo "Merging pipeline spec $SPEC with triggers $TRIGGERS"
3135
for f in `echo $TRIGGERS` ; do
36+
# is path absolute
37+
if [[ "$f" = /* ]] ; then
38+
curdir="/"
39+
else
40+
curdir=`pwd`
41+
fi
3242
process_file $f
3343
done
44+
3445
echo "Creating/Updating final pipeline"
35-
codefresh create pipeline -f $SPEC || codefresh replace -f $SPEC
46+
47+
# Get pipeline name
48+
echo "Checking if pipeline already exists"
49+
name=$(yq '.metadata.name' $SPEC)
50+
codefresh get pip $name > pipeline.log 2>&1 || true
51+
52+
#Check if pipeline exists
53+
if [ `grep -c PIPELINE_NOT_FOUND pipeline.log` -eq 0 ] ; then
54+
echo "Updating final pipeline"
55+
cmd="codefresh replace -f $SPEC"
56+
else
57+
echo "Creating final pipeline"
58+
cmd="codefresh create pipeline -f $SPEC"
59+
fi
60+
61+
# Check for error when creating/updating the pipeline
62+
echo "Checking for errors"
63+
$cmd 2>&1 | tee pipeline.log
64+
exit `grep -c 'Yaml validation errors' pipeline.log`

incubating/pipeline-trigger-merge/sample/spec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ spec:
2727
build:
2828
title: "Building Docker image"
2929
type: "build"
30+
registry: docker
3031
image_name: "codefresh-io/cli"
3132
working_directory: "${{clone}}"
3233
tag: "latest"

incubating/pipeline-trigger-merge/step.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ kind: step-type
22
version: '1.0'
33
metadata:
44
name: pipeline-trigger-merge
5-
version: 1.0.2
5+
version: 1.1.0
66
isPublic: true
77
description: >-
88
Merge a pipeline spec and a list of triggers (files or directories) to
@@ -65,14 +65,29 @@ spec:
6565
"TRIGGERS_SUBDIR": {
6666
"type": "string",
6767
"description": "The subdirectory that holds a pipeline's triggers if looping. Defaults to 'triggers'."
68+
},
69+
"REGISTRY": {
70+
"type": "string",
71+
"description": "Docker Registry for step's image.",
72+
"default": "quay.io"
73+
},
74+
"IMAGE": {
75+
"type": "string",
76+
"description": "Image name for step's image.",
77+
"default": "codefreshplugins/pipeline-trigger-merge"
78+
},
79+
"IMAGE_TAG": {
80+
"type": "string",
81+
"description": "Image tag for step's image.",
82+
"default": "1.1.0"
6883
}
6984
}
7085
}
7186
7287
stepsTemplate: |-
7388
pipeline-trigger-merge:
7489
name: pipeline-trigger-merge
75-
image: quay.io/codefreshplugins/pipeline-trigger-merge:1.0.2
90+
image: '[[.Arguments.REGISTRY]]/[[.Arguments.IMAGE]]:[[.Arguments.IMAGE_TAG]]'
7691
environment:
7792
[[ range $key, $val := .Arguments ]]
7893
- '[[ $key ]]=[[ $val ]]'

0 commit comments

Comments
 (0)