|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -eu -o pipefail |
3 | 3 |
|
4 | | -STEMCELL_LINE="ubuntu-resolute" |
5 | | - |
6 | | -REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" |
7 | | - |
8 | 4 | if [[ -n "${DEBUG:-}" ]]; then |
9 | 5 | set -x |
10 | 6 | fi |
11 | 7 |
|
12 | | -fly="${FLY_CLI:-fly}" |
| 8 | +REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" |
| 9 | + |
| 10 | +STEMCELL_LINE="ubuntu-resolute" |
| 11 | + |
| 12 | +pipelines_dir="${REPO_ROOT}/ci" |
| 13 | +pipeline_name="${STEMCELL_LINE}" |
| 14 | +pipeline_template="pipeline-template.yml" |
| 15 | +pipeline_vars="pipeline-vars.yml" |
| 16 | + |
13 | 17 | concourse_target="${CONCOURSE_TARGET:-stemcell}" |
| 18 | +fly="${FLY_CLI:-fly}" |
14 | 19 |
|
15 | 20 | until "${fly}" -t "${concourse_target}" status; do |
16 | 21 | "${fly}" -t "${concourse_target}" login |
17 | 22 | sleep 1 |
18 | 23 | done |
19 | 24 |
|
20 | | -pipelines_dir="${REPO_ROOT}/ci/pipelines" |
21 | | -vars_file_name="vars.yml" |
22 | | - |
23 | | -mapfile -t available_pipelines < \ |
24 | | - <( find "${pipelines_dir}" -maxdepth 1 -type f -name '*.yml' | grep -v "${vars_file_name}" | sort ) |
25 | | - |
26 | | -if (( ${#available_pipelines[@]} == 0 )); then |
27 | | - echo "No pipelines found under '${pipelines_dir}'" >&2 |
28 | | - exit 1 |
29 | | -fi |
30 | | - |
31 | | -i=1 |
32 | | -echo "Choose a pipeline to configure:" |
33 | | -for pipeline in "${available_pipelines[@]}"; do |
34 | | - pipeline_choice_label=$(echo "${pipeline#"${pipelines_dir}/"}" | cut -d/ -f 1) |
35 | | - printf "%4s. %s\n" "${i}" "${pipeline_choice_label}" |
36 | | - i=$((i + 1)) |
37 | | -done |
38 | | -read -rp "pipeline: " pipeline_index |
| 25 | +echo "Rendering..." |
| 26 | +rendered_template="$(ytt -f "${pipelines_dir}/${pipeline_template}" -f "${pipelines_dir}/${pipeline_vars}")" |
39 | 27 | echo "" |
40 | 28 |
|
41 | | -if ! [[ "${pipeline_index}" =~ ^[0-9]+$ ]] || (( pipeline_index < 1 || pipeline_index > ${#available_pipelines[@]} )); then |
42 | | - echo "Invalid selection: '${pipeline_index}'" >&2 |
43 | | - exit 1 |
44 | | -fi |
45 | | - |
46 | | -pipeline_file=${available_pipelines[(pipeline_index-1)]} |
47 | | -if [ ! -f "${pipeline_file}" ]; then |
48 | | - echo "No pipeline found: '${pipeline_file}'" >&2 |
49 | | - exit 1 |
50 | | -fi |
51 | | - |
52 | | -pipeline_name=$(basename "${pipeline_file%".yml"}") |
53 | | - |
54 | | -echo "Configuring '${pipeline_name}' using '${pipeline_file#"${pipelines_dir}/"}'..." |
| 29 | +echo "Validating..." |
| 30 | +fly validate-pipeline --strict --config <(echo "${rendered_template}") |
55 | 31 | echo "" |
56 | 32 |
|
57 | | -rendered_template="$(ytt -f "${pipeline_file}" -f "${pipelines_dir}/${vars_file_name}")" |
58 | | - |
59 | | -"${fly}" -t "${concourse_target}" set-pipeline \ |
60 | | - -p "${STEMCELL_LINE}-${pipeline_name}" \ |
| 33 | +echo "Configuring..." |
| 34 | +"${fly}" -t "${concourse_target}" set-pipeline -p "${pipeline_name}" \ |
61 | 35 | -c <(echo "${rendered_template}") |
0 commit comments