Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: support variable substitution for cf apps #234

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
43 changes: 31 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,53 @@ 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
# we need VARS_FILES to be expanded with spaces
# shellcheck disable=SC2086
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