-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepipe
executable file
·69 lines (59 loc) · 1.96 KB
/
repipe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# ci/repipe
#
# Script for merging together pipeline configuration files
# (via Spruce!) and configuring Concourse.
#
# author: James Hunt <[email protected]>
# Dennis Bell <[email protected]>
# created: 2016-03-04
need_command() {
local cmd=${1:?need_command() - no command name given}
if [[ ! -x "$(command -v $cmd)" ]]; then
echo >&2 "${cmd} is not installed."
if [[ "${cmd}" == "spruce" ]]; then
echo >&2 "Please download it from https://github.com/geofffranks/spruce/releases"
fi
exit 2
fi
}
cd $(dirname $BASH_SOURCE[0])
echo "Working in $(pwd)"
need_command spruce
# Allow for target-specific settings
settings_file="$(ls -1 settings.yml ${CONCOURSE_TARGET:+"settings-${CONCOURSE_TARGET}.yml"} 2>/dev/null | tail -n1)"
if [[ -z "$settings_file" ]]
then
echo >&2 "Missing local settings in ci/settings.yml${CONCOURSE_TARGET:+" or ci/settings-${CONCOURSE_TARGET}.yml"}!"
exit 1
fi
echo >&2 "Using settings found in ${settings_file}"
set -e
trap "rm -f .deploy.yml" QUIT TERM EXIT INT
spruce merge pipeline.yml ${settings_file} > .deploy.yml
PIPELINE=$(spruce json .deploy.yml | jq -r '.meta.pipeline // ""')
if [[ -z ${PIPELINE} ]]; then
echo >&2 "Missing pipeline name in ci/settings.yml!"
exit 1
fi
TARGET_FROM_SETTINGS=$(spruce json .deploy.yml | jq -r '.meta.target // ""')
if [[ -z ${CONCOURSE_TARGET} ]]; then
TARGET=${TARGET_FROM_SETTINGS}
elif [[ "$CONCOURSE_TARGET" != "$TARGET_FROM_SETTINGS" ]]
then
echo >&2 "Target in {$settings_file} differs from target in \$CONCOURSE_TARGET"
echo >&2 " \$CONCOURSE_TARGET: $CONCOURSE_TARGET"
echo >&2 " Target in file: $TARGET_FROM_SETTINGS"
exit 1
else
TARGET=${CONCOURSE_TARGET}
fi
if [[ -z ${TARGET} ]]; then
echo >&2 "Missing Concourse Target in ci/settings.yml!"
exit 1
fi
fly_cmd="${FLY_CMD:-fly}"
set +x
$fly_cmd --target ${TARGET} set-pipeline --pipeline ${PIPELINE} --config .deploy.yml
$fly_cmd --target ${TARGET} unpause-pipeline --pipeline ${PIPELINE}