Skip to content

Commit f3765aa

Browse files
committed
TODO:
- document usage in reference dataset - add minimal tests WIP-tasks(cf_push): support variable substitution for cf apps a file ending with `vars.yml` in application template dir is detected as file with `variables` to be injected into application manifest. fix #188
1 parent 7d85b83 commit f3765aa

5 files changed

Lines changed: 45 additions & 27 deletions

File tree

concourse/tasks/cf_push.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ params:
1919
SECRETS_DIR:
2020
CUSTOM_SCRIPT_DIR:
2121
CF_MANIFEST:
22+
VARS_FILES_SUFFIX: vars.yml

docs/reference_dataset/config_repository/hello-world-root-depls/cf-apps-deployments/generic-app/enable-cf-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cf-app:
22
generic-app:
3-
cf_api_url: https://my-cloudfroundry.org
3+
cf_api_url: https://api.run.pivotal.io
44
cf_username: a-test-User
55
cf_password: a-test-Password
66
cf_organization: my-test-org
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<html>
22
<body>
3-
Hello World
3+
Hello World, I'm COA sample app
44
</body>
55
</html>

scripts/cf/push.sh

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ validate(){
2323
FAILURE=$((4 + $FAILURE))
2424
fi
2525

26-
if [ $FAILURE -ne 0 ]
26+
if [ ${FAILURE} -ne 0 ]
2727
then
28-
exit $FAILURE
28+
exit ${FAILURE}
2929
fi
3030
}
3131

32-
validate
32+
#validate
3333

3434
CURRENT_DIR=$(pwd)
3535
OUTPUT_DIR=${OUTPUT_DIR:-${CURRENT_DIR}/generated-files}
@@ -38,34 +38,52 @@ ADDITIONAL_RESSOURCE=${ADDITIONAL_RESSOURCE:-additional-resource}
3838

3939
CF_MANIFEST=${CF_MANIFEST:-manifest.yml}
4040

41+
API_OPTIONS="--skip-ssl-validation"
4142

43+
echo "copying file from $ADDITIONAL_RESSOURCE to $OUTPUT_DIR"
44+
cp -r ${ADDITIONAL_RESSOURCE}/. ${OUTPUT_DIR}/
45+
46+
VARS_FILES=""
47+
ls "${OUTPUT_DIR}/*"
48+
for a_vars_file in $(ls "${OUTPUT_DIR}/*${VARS_FILES_SUFFIX}"); do
49+
VARS_FILES="${VARS_FILES} --vars-file ${a_vars_file}"
50+
done
51+
52+
echo "Vars files detected: <${VARS_FILES}>"
4253

43-
API_OPTIONS="--skip-ssl-validation"
4454

4555
#TODO add an option to manage ssl validation
56+
cf --version
4657
cf api "$CF_API_URL" $API_OPTIONS
4758
cf auth "$CF_USERNAME" "$CF_PASSWORD"
4859

49-
echo "copying file from $ADDITIONAL_RESSOURCE to $OUTPUT_DIR"
50-
cp -r $ADDITIONAL_RESSOURCE/. $OUTPUT_DIR/
5160

5261
if [ -n "$CUSTOM_SCRIPT_DIR" -a -f "$CUSTOM_SCRIPT_DIR/pre-cf-push.sh" ]
5362
then
5463
echo "pre CF push script detected"
55-
chmod +x $CUSTOM_SCRIPT_DIR/pre-cf-push.sh
56-
GENERATE_DIR=$OUTPUT_DIR BASE_TEMPLATE_DIR=$CUSTOM_SCRIPT_DIR $CUSTOM_SCRIPT_DIR/pre-cf-push.sh
64+
chmod +x ${CUSTOM_SCRIPT_DIR}/pre-cf-push.sh
65+
GENERATE_DIR="${OUTPUT_DIR}" BASE_TEMPLATE_DIR="${CUSTOM_SCRIPT_DIR}" "${CUSTOM_SCRIPT_DIR}/pre-cf-push.sh"
5766
else
5867
echo "ignoring pre CF push. No $CUSTOM_SCRIPT_DIR/pre-cf-push.sh detected"
5968
fi
6069

70+
VARS_FILES=""
71+
72+
for a_vars_file in $(ls "./${OUTPUT_DIR}/*${VARS_FILES_SUFFIX}"); do
73+
VARS_FILES="${VARS_FILES} --vars-file ${a_vars_file}"
74+
done
75+
76+
echo "Vars files detected: <${VARS_FILES}>"
77+
78+
6179
cf target -o "$CF_ORG" -s "$CF_SPACE"
6280

6381
set +e
64-
cf push -f ${CF_MANIFEST} |tee /tmp/cf-push.log
82+
cf push -f "${CF_MANIFEST}" ${VARS_FILES}|tee /tmp/cf-push.log
6583
ret_code=$?
66-
if [ $ret_code -ne 0 ]
84+
if [ ${ret_code} -ne 0 ]
6785
then
6886
DISPLAY_LOG_CMD=$(grep "TIP: use 'cf logs" /tmp/cf-push.log |cut -d\' -f2)
69-
eval $DISPLAY_LOG_CMD
70-
exit $ret_code
87+
eval ${DISPLAY_LOG_CMD}
88+
exit ${ret_code}
7189
fi

spec/tasks/cf_push/task_spec.rb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# encoding: utf-8
2-
# require 'spec_helper.rb'
31
require 'yaml'
42
require 'tmpdir'
3+
require_relative '../task_spec_helper'
54

65
describe 'cf push task' do
76

@@ -15,23 +14,23 @@
1514
before(:context) do
1615
generated_files = Dir.mktmpdir
1716

18-
# @output = execute('-c concourse/tasks/cf_push.yml ' \
19-
# '-i scripts-resource=. ' \
20-
# '-i templates-resource=spec/tasks/cf_push/template-resource ' \
21-
# '-i credentials-resource=spec/tasks/cf_push/credentials-resource ' \
22-
# '-i additional-resource=spec/tasks/cf_push/additional-resource ' \
23-
# "-o generated-files=#{generated_files} ",
24-
# 'CUSTOM_SCRIPT_DIR' =>'',
25-
# 'SECRETS_DIR' => '' )
17+
@output = execute('-c concourse/tasks/cf_push.yml ' \
18+
'-i scripts-resource=. ' \
19+
'-i templates-resource=spec/tasks/cf_push/template-resource ' \
20+
'-i credentials-resource=spec/tasks/cf_push/credentials-resource ' \
21+
'-i additional-resource=spec/tasks/cf_push/additional-resource ' \
22+
"-o generated-files=#{generated_files} ",
23+
'CUSTOM_SCRIPT_DIR' =>'',
24+
'SECRETS_DIR' => '' )
2625
end
2726

2827
after(:context) do
2928
FileUtils.rm_rf generated_files
3029
end
3130

32-
it 'displays an ignore message'
33-
# expect(@output).to include('ignoring pre CF push. No /pre-cf-push.sh detected')
34-
31+
it 'displays an ignore message' do
32+
expect(@output).to include('ignoring pre CF push. No /pre-cf-push.sh detected')
33+
end
3534
end
3635

3736
context 'when a custom pre-push script script is detected' do

0 commit comments

Comments
 (0)