Skip to content

Commit

Permalink
TODO:
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
o-orand committed Jan 18, 2019
1 parent 7d85b83 commit f3765aa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
1 change: 1 addition & 0 deletions concourse/tasks/cf_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ params:
SECRETS_DIR:
CUSTOM_SCRIPT_DIR:
CF_MANIFEST:
VARS_FILES_SUFFIX: vars.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cf-app:
generic-app:
cf_api_url: https://my-cloudfroundry.org
cf_api_url: https://api.run.pivotal.io
cf_username: a-test-User
cf_password: a-test-Password
cf_organization: my-test-org
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<html>
<body>
Hello World
Hello World, I'm COA sample app
</body>
</html>
42 changes: 30 additions & 12 deletions scripts/cf/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ validate(){
FAILURE=$((4 + $FAILURE))
fi

if [ $FAILURE -ne 0 ]
if [ ${FAILURE} -ne 0 ]
then
exit $FAILURE
exit ${FAILURE}
fi
}

validate
#validate

CURRENT_DIR=$(pwd)
OUTPUT_DIR=${OUTPUT_DIR:-${CURRENT_DIR}/generated-files}
Expand All @@ -38,34 +38,52 @@ 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
echo "pre CF push script detected"
chmod +x $CUSTOM_SCRIPT_DIR/pre-cf-push.sh
GENERATE_DIR=$OUTPUT_DIR BASE_TEMPLATE_DIR=$CUSTOM_SCRIPT_DIR $CUSTOM_SCRIPT_DIR/pre-cf-push.sh
chmod +x ${CUSTOM_SCRIPT_DIR}/pre-cf-push.sh
GENERATE_DIR="${OUTPUT_DIR}" BASE_TEMPLATE_DIR="${CUSTOM_SCRIPT_DIR}" "${CUSTOM_SCRIPT_DIR}/pre-cf-push.sh"
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 ]
if [ ${ret_code} -ne 0 ]
then
DISPLAY_LOG_CMD=$(grep "TIP: use 'cf logs" /tmp/cf-push.log |cut -d\' -f2)
eval $DISPLAY_LOG_CMD
exit $ret_code
eval ${DISPLAY_LOG_CMD}
exit ${ret_code}
fi
25 changes: 12 additions & 13 deletions spec/tasks/cf_push/task_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down

0 comments on commit f3765aa

Please sign in to comment.