5
5
# Script for merging together pipeline configuration files
6
6
# (via Spruce!) and configuring Concourse.
7
7
#
8
- # author: James Hunt <[email protected] >
9
-
10
- # created: 2016-03-04
8
+ # original authors: James Hunt <[email protected] >
9
+
10
+ # created: 2016-03-04
11
+ # maintainer: Benjamin Gandon (Gstack)
11
12
12
13
need_command () {
13
- local cmd=${1:? need_command() - no command name given}
14
-
15
- if [[ ! -x " $( command -v $cmd ) " ]]; then
16
- echo >&2 " ${cmd} is not installed."
17
- if [[ " ${cmd} " == " spruce" ]]; then
18
- echo >&2 " Please download it from https://github.com/geofffranks/spruce/releases"
19
- fi
20
- exit 2
21
- fi
14
+ local cmd=${1:? " need_command() - no command name given" }
15
+
16
+ if [[ ! -x " $( command -v ${ cmd} ) " ]]; then
17
+ echo >&2 " ${cmd} is not installed."
18
+ if [[ " ${cmd} " == " spruce" ]]; then
19
+ echo >&2 " Please download it from https://github.com/geofffranks/spruce/releases"
20
+ fi
21
+ exit 2
22
+ fi
22
23
}
23
24
24
25
NO_FLY=
@@ -45,33 +46,35 @@ usage() {
45
46
}
46
47
47
48
open_pipeline () {
48
- url=$( show_pipeline_url)
49
+ url=$( show_pipeline_url)
49
50
cleanup
50
- if [[ -x /usr/bin/open ]]; then
51
- exec /usr/bin/open " $url "
52
- else
53
- echo " Sorry, but I was not able to automagically open"
54
- echo " your Concourse Pipeline in the browser."
55
- echo
56
- echo " Here's a link you can click on, though:"
57
- echo
58
- echo " $url "
59
- echo
60
- exit 0;
61
- fi
51
+ if [[ -x /usr/bin/open ]]; then
52
+ exec /usr/bin/open " ${ url} "
53
+ else
54
+ echo " Sorry, but I was not able to automagically open"
55
+ echo " your Concourse Pipeline in the browser."
56
+ echo
57
+ echo " Here's a link you can click on, though:"
58
+ echo
59
+ echo " ${ url} "
60
+ echo
61
+ exit 0;
62
+ fi
62
63
}
63
64
64
65
show_pipeline_url () {
65
- spruce merge --skip-eval pipeline.yml ${settings_file} > .deploy.yml
66
- concourse_url=$( spruce json .deploy.yml | jq -r " .meta.url" )
67
- team=$( spruce json .deploy.yml | jq -r " .meta.team // \" main\" " )
68
- pipeline=$( spruce merge --skip-eval \
69
- --cherry-pick meta.pipeline \
70
- --cherry-pick meta.name \
71
- .deploy.yml | spruce merge - | spruce json | jq -r " .meta.pipeline" )
72
-
73
- echo " $concourse_url /teams/$team /pipelines/$pipeline "
74
- exit 0
66
+ spruce merge --skip-eval pipeline.yml ${settings_file} > .deploy.yml
67
+ concourse_url=$( spruce json .deploy.yml | jq -r " .meta.url" )
68
+ team=$( spruce json .deploy.yml | jq -r " .meta.team // \" main\" " )
69
+ pipeline=$(
70
+ spruce merge --skip-eval \
71
+ --cherry-pick meta.pipeline \
72
+ --cherry-pick meta.name \
73
+ .deploy.yml \
74
+ | spruce merge - | spruce json | jq -r " .meta.pipeline"
75
+ )
76
+ echo " ${concourse_url} /teams/${team} /pipelines/${pipeline} "
77
+ exit 0
75
78
}
76
79
77
80
for arg do
@@ -90,16 +93,16 @@ for arg do
90
93
esac
91
94
done
92
95
93
- cd $( dirname $ BASH_SOURCE [0])
96
+ cd " $( dirname " ${ BASH_SOURCE[0]} " ) "
94
97
echo >&2 " Working in $( pwd) "
95
98
need_command spruce
96
99
97
100
# Allow for target-specific settings
98
101
settings_file=" $( ls -1 settings.yml ${CONCOURSE_TARGET: +" settings-${CONCOURSE_TARGET} .yml" } 2> /dev/null | head -n1) "
99
- if [[ -z " $settings_file " ]]
102
+ if [[ -z " ${ settings_file} " ]]
100
103
then
101
- echo >&2 " Missing local settings in ci/settings.yml${CONCOURSE_TARGET: +" or ci/settings-${CONCOURSE_TARGET} .yml" } !"
102
- exit 1
104
+ echo >&2 " Missing local settings in ci/settings.yml${CONCOURSE_TARGET: +" or ci/settings-${CONCOURSE_TARGET} .yml" } !"
105
+ exit 1
103
106
fi
104
107
105
108
echo >&2 " Using settings found in ${settings_file} "
@@ -113,26 +116,26 @@ trap "cleanup" QUIT TERM EXIT INT
113
116
spruce merge pipeline.yml ${settings_file} > .deploy.yml
114
117
PIPELINE=$( spruce json .deploy.yml | jq -r ' .meta.pipeline // ""' )
115
118
if [[ -z ${PIPELINE} ]]; then
116
- echo >&2 " Missing pipeline name in ci/settings.yml!"
117
- exit 1
119
+ echo >&2 " Missing pipeline name in ci/settings.yml!"
120
+ exit 1
118
121
fi
119
122
120
123
TARGET_FROM_SETTINGS=$( spruce json .deploy.yml | jq -r ' .meta.target // ""' )
121
124
if [[ -z ${CONCOURSE_TARGET} ]]; then
122
- TARGET=${TARGET_FROM_SETTINGS}
123
- elif [[ " $CONCOURSE_TARGET " != " $TARGET_FROM_SETTINGS " ]]
125
+ TARGET=${TARGET_FROM_SETTINGS}
126
+ elif [[ " ${ CONCOURSE_TARGET} " != " ${ TARGET_FROM_SETTINGS} " ]]
124
127
then
125
- echo >&2 " Target in {$settings_file } differs from target in \$ CONCOURSE_TARGET"
126
- echo >&2 " \$ CONCOURSE_TARGET: $CONCOURSE_TARGET "
127
- echo >&2 " Target in file: $TARGET_FROM_SETTINGS "
128
- exit 1
128
+ echo >&2 " Target in {${ settings_file} } differs from target in \$ CONCOURSE_TARGET"
129
+ echo >&2 " \$ CONCOURSE_TARGET: ${ CONCOURSE_TARGET} "
130
+ echo >&2 " Target in file: ${ TARGET_FROM_SETTINGS} "
131
+ exit 1
129
132
else
130
- TARGET=${CONCOURSE_TARGET}
133
+ TARGET=${CONCOURSE_TARGET}
131
134
fi
132
135
133
136
if [[ -z ${TARGET} ]]; then
134
- echo >&2 " Missing Concourse Target in ci/settings.yml!"
135
- exit 1
137
+ echo >&2 " Missing Concourse Target in ci/settings.yml!"
138
+ exit 1
136
139
fi
137
140
138
141
fly_cmd=" ${FLY_CMD:- fly} "
@@ -146,6 +149,6 @@ case "${VALIDATE_PIPELINE}" in
146
149
esac
147
150
148
151
set +x
149
- $fly_cmd --target ${TARGET} ${fly_opts} --config .deploy.yml
152
+ ${ fly_cmd} --target ${TARGET} ${fly_opts} --config .deploy.yml
150
153
[[ -n ${VALIDATE_PIPELINE} ]] && exit 0
151
- $fly_cmd --target ${TARGET} unpause-pipeline --pipeline ${PIPELINE}
154
+ ${ fly_cmd} --target ${TARGET} unpause-pipeline --pipeline ${PIPELINE}
0 commit comments