diff --git a/concourse/tasks/cf_push.yml b/concourse/tasks/cf_push.yml index ed204f446..0ff08e67a 100644 --- a/concourse/tasks/cf_push.yml +++ b/concourse/tasks/cf_push.yml @@ -19,3 +19,4 @@ params: SECRETS_DIR: CUSTOM_SCRIPT_DIR: CF_MANIFEST: + VARS_FILES_SUFFIX: vars.yml diff --git a/scripts/cf/push.sh b/scripts/cf/push.sh index edb3f3e0c..5be3c5ccf 100755 --- a/scripts/cf/push.sh +++ b/scripts/cf/push.sh @@ -29,7 +29,7 @@ validate(){ fi } -validate +#validate CURRENT_DIR=$(pwd) OUTPUT_DIR=${OUTPUT_DIR:-${CURRENT_DIR}/generated-files} @@ -38,16 +38,25 @@ ADDITIONAL_RESSOURCE=${ADDITIONAL_RESSOURCE:-additional-resource} CF_MANIFEST=${CF_MANIFEST:-manifest.yml} +API_OPTIONS="--skip-ssl-validation" + +echo "copying file from $ADDITIONAL_RESSOURCE to $OUTPUT_DIR" +cp -r $ADDITIONAL_RESSOURCE/. $OUTPUT_DIR/ +VARS_FILES="" +ls ${OUTPUT_DIR}/* +for a_vars_file in $(ls ${OUTPUT_DIR}/*${VARS_FILES_SUFFIX}); do + VARS_FILES="${VARS_FILES} --vars-file ${a_vars_file}" +done + +echo "Vars files detected: <${VARS_FILES}>" -API_OPTIONS="--skip-ssl-validation" #TODO add an option to manage ssl validation +cf --version cf api "$CF_API_URL" $API_OPTIONS cf auth "$CF_USERNAME" "$CF_PASSWORD" -echo "copying file from $ADDITIONAL_RESSOURCE to $OUTPUT_DIR" -cp -r $ADDITIONAL_RESSOURCE/. $OUTPUT_DIR/ if [ -n "$CUSTOM_SCRIPT_DIR" -a -f "$CUSTOM_SCRIPT_DIR/pre-cf-push.sh" ] then @@ -58,10 +67,19 @@ else echo "ignoring pre CF push. No $CUSTOM_SCRIPT_DIR/pre-cf-push.sh detected" fi +VARS_FILES="" + +for a_vars_file in $(ls ./${OUTPUT_DIR}/*${VARS_FILES_SUFFIX}); do + VARS_FILES="${VARS_FILES} --vars-file ${a_vars_file}" +done + +echo "Vars files detected: <${VARS_FILES}>" + + cf target -o "$CF_ORG" -s "$CF_SPACE" set +e -cf push -f ${CF_MANIFEST} |tee /tmp/cf-push.log +cf push -f ${CF_MANIFEST} ${VARS_FILES}|tee /tmp/cf-push.log ret_code=$? if [ $ret_code -ne 0 ] then diff --git a/spec/tasks/cf_push/task_spec.rb b/spec/tasks/cf_push/task_spec.rb index fbe97c429..b3d0ee51e 100644 --- a/spec/tasks/cf_push/task_spec.rb +++ b/spec/tasks/cf_push/task_spec.rb @@ -1,7 +1,6 @@ -# encoding: utf-8 -# require 'spec_helper.rb' require 'yaml' require 'tmpdir' +require_relative '../task_spec_helper' describe 'cf push task' do @@ -15,23 +14,23 @@ before(:context) do generated_files = Dir.mktmpdir - # @output = execute('-c concourse/tasks/cf_push.yml ' \ - # '-i scripts-resource=. ' \ - # '-i templates-resource=spec/tasks/cf_push/template-resource ' \ - # '-i credentials-resource=spec/tasks/cf_push/credentials-resource ' \ - # '-i additional-resource=spec/tasks/cf_push/additional-resource ' \ - # "-o generated-files=#{generated_files} ", - # 'CUSTOM_SCRIPT_DIR' =>'', - # 'SECRETS_DIR' => '' ) + @output = execute('-c concourse/tasks/cf_push.yml ' \ + '-i scripts-resource=. ' \ + '-i templates-resource=spec/tasks/cf_push/template-resource ' \ + '-i credentials-resource=spec/tasks/cf_push/credentials-resource ' \ + '-i additional-resource=spec/tasks/cf_push/additional-resource ' \ + "-o generated-files=#{generated_files} ", + 'CUSTOM_SCRIPT_DIR' =>'', + 'SECRETS_DIR' => '' ) end after(:context) do FileUtils.rm_rf generated_files end - it 'displays an ignore message' - # expect(@output).to include('ignoring pre CF push. No /pre-cf-push.sh detected') - + it 'displays an ignore message' do + expect(@output).to include('ignoring pre CF push. No /pre-cf-push.sh detected') + end end context 'when a custom pre-push script script is detected' do