Skip to content

Commit

Permalink
Initial ci/settings.yml is populated with example parameters (#27)
Browse files Browse the repository at this point in the history
* initialize settings.yml for boshrelease; assume credhub

* go template attempts to construct ci/settings.yml + display credhub commands

* configure fly -t target using $fly_target

* add initial_settings + credhub helper for cfpush

* credhub helper for docker/base

* assume boshrelease meta.bosh-lite targetting a bosh-lite

* easier to change team before running commands
  • Loading branch information
drnic committed Nov 12, 2018
1 parent 111f4e5 commit df524e9
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 3 deletions.
12 changes: 12 additions & 0 deletions boshrelease/helpers/credhub-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
echo "Example commands for setting up credhub for your pipeline:"
echo "team=$team"
echo "credhub set -n /concourse/\$team/git-commit-email -t value -v \"\$(git config user.email)\""
echo "credhub set -n /concourse/\$team/git-commit-name -t value -v \"\$(git config user.name)\""
echo "credhub set -n /concourse/\$team/aws-access-key -t value -v \"\$(grep access_key_id config/private.yml | awk '{print \$2}')\""
echo "credhub set -n /concourse/\$team/aws-secret-key -t value -v \"\$(grep secret_access_key config/private.yml | awk '{print \$2}')\""
echo "credhub set -n /concourse/\$team/$name/slack-username -t value -v concourse"
echo "credhub set -n /concourse/\$team/$name/slack-icon-url -t value -v https://cl.ly/2F421Y300u07/concourse-logo-blue-transparent.png"
echo
echo "credhub set -n /concourse/\$team/$name/slack-webhook -t value -v https://slack.com/skip-slack-for-now"
echo "credhub set -n /concourse/\$team/github-access-token -t value -v \"\$(echo \$GITHUB_TOKEN)\""
echo "credhub set -n /concourse/\$team/github-private-key -t value -v \"\$(cat ~/.ssh/id_rsa)\""
40 changes: 40 additions & 0 deletions boshrelease/helpers/initial_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
meta:
name: $(grep final_name config/final.yml | awk '{print $2}')
target: ${fly_target}
url: ${fly_target_url}

test-errand: ~

initial_version: 1.0.0

git:
email: ((git-commit-email))
name: ((git-commit-name))

bosh-lite:
target: ((bosh-lite-environment))
cacert: ((bosh-lite-ca-cert))
username: ((bosh-lite-client))
password: ((bosh-lite-client-secret))

aws:
bucket: (( grab meta.pipeline ))
region_name: us-east-1
access_key: ((aws-access-key))
secret_key: ((aws-secret-key))

github:
owner: cloudfoundry-community
repo: (( grab meta.pipeline ))
branch: $(git branch --no-color | awk '{print $2}')
private_key: ((github-private-key))
access_token: ((github-access-token))

slack:
webhook: ((slack-webhook))
username: ((slack-username))
icon: ((slack-icon-url))
channel: (( concat meta.name "-boshrelease" ))
blob_success: '(( concat "$BUILD_PIPELINE_NAME: New version of $BUILD_JOB_NAME was detected, and updated in master. <" meta.url "/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME| Cut a new release?>" ))'
blob_failure: '(( concat "$BUILD_PIPELINE_NAME: :airplane_arriving: <" meta.url "/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME| Failed to update the blob for $BUILD_JOB_NAME>" ))'
9 changes: 9 additions & 0 deletions cfpush/helpers/credhub-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
echo "Example commands for setting up credhub for your pipeline:"
echo
echo "For GitHub:"
echo "credhub set -n /concourse/$team/github-access-token -t value -v \"\$(echo \$GITHUB_TOKEN)\""
echo "credhub set -n /concourse/$team/github-private-key -t value -v \"\$(cat ~/.ssh/id_rsa)\""
echo
echo "For Cloud Foundry ($(jq .Target -r ~/.cf/config.json)):"
echo "credhub set -n /concourse/$team/cf-username -t value -v \"your-username\""
echo "credhub set -n /concourse/$team/cf-password -t value -v \"your-password\""
23 changes: 23 additions & 0 deletions cfpush/helpers/initial_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
meta:
name: $(basename $PWD)
target: ${fly_target}
url: ${fly_target_url}

github:
owner: $(jq .OrganizationFields.Name -r ~/.cf/config.json)
repo: $(basename $PWD)
branch: $(git branch --no-color | awk '{print $2}')
private_key: ((github-private-key))
access_token: ((github-access-token))

cf:
api: $(jq .Target -r ~/.cf/config.json)
skip_cert_check: false
username: ((cf-username))
password: ((cf-password))
appname: $(basename $PWD)
organization: $(jq .OrganizationFields.Name -r ~/.cf/config.json)
spaces:
staging: $(basename $PWD)-staging
production: $(basename $PWD)-production
15 changes: 15 additions & 0 deletions docker/base/helpers/credhub-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
echo "Example commands for setting up credhub for your pipeline:"
echo "credhub set -n /concourse/$team/git-commit-email -t value -v \"\$(git config user.email)\""
echo "credhub set -n /concourse/$team/git-commit-name -t value -v \"\$(git config user.name)\""
echo "credhub set -n /concourse/$team/slack-username -t value -v concourse"
echo "credhub set -n /concourse/$team/slack-icon-url -t value -v https://cl.ly/2F421Y300u07/concourse-logo-blue-transparent.png"
echo
echo "credhub set -n /concourse/$team/$name/slack-webhook -t value -v https://slack.com/skip-slack-for-now"
echo "credhub set -n /concourse/$team/aws-access-key -t value -v \"AWS_ACCESS_KEY\""
echo "credhub set -n /concourse/$team/aws-secret-key -t value -v \"AWS_SECRET_KEY\""
echo "credhub set -n /concourse/$team/github-access-token -t value -v \"\$(echo \$GITHUB_TOKEN)\""
echo "credhub set -n /concourse/$team/github-private-key -t value -v \"\$(cat ~/.ssh/id_rsa)\""
echo
echo "credhub set -n /concourse/$team/dockerhub-username -t value -v \"\$(whoami)\""
echo "credhub set -n /concourse/$team/dockerhub-email -t value -v \"\$(git config user.email)\""
echo "credhub set -n /concourse/$team/dockerhub-password -t value -v \"PASSWORD"
36 changes: 36 additions & 0 deletions docker/base/helpers/initial_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
meta:
name: $(basename $PWD)
target: ${fly_target}
url: ${fly_target_url}

initial_version: 1.0.0

git:
email: ((git-commit-email))
name: ((git-commit-name))

dockerhub:
username: ((dockerhub-username))
email: ((dockerhub-email))
password: ((dockerhub-password))
repository: (( concat meta.github.owner "/" meta.name ))

aws:
bucket: (( grab meta.pipeline ))
region_name: us-east-1
access_key: ((aws-access-key))
secret_key: ((aws-secret-key))

github:
owner: $(jq .OrganizationFields.Name -r ~/.cf/config.json)
repo: $(basename $PWD)
branch: $(git branch --no-color | awk '{print $2}')
private_key: ((github-private-key))
access_token: ((github-access-token))

slack:
webhook: ((slack-webhook))
username: ((slack-username))
icon: ((slack-icon-url))
channel: "#$(basename $PWD)"
11 changes: 11 additions & 0 deletions go/helpers/credhub-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
echo "Example commands for setting up credhub for your pipeline:"
echo "credhub set -n /concourse/$team/git-commit-email -t value -v \"\$(git config user.email)\""
echo "credhub set -n /concourse/$team/git-commit-name -t value -v \"\$(git config user.name)\""
echo "credhub set -n /concourse/$team/slack-username -t value -v concourse"
echo "credhub set -n /concourse/$team/slack-icon-url -t value -v https://cl.ly/2F421Y300u07/concourse-logo-blue-transparent.png"
echo
echo "credhub set -n /concourse/$team/$name/slack-webhook -t value -v https://slack.com/skip-slack-for-now"
echo "credhub set -n /concourse/$team/aws-access-key -t value -v \"AWS_ACCESS_KEY\""
echo "credhub set -n /concourse/$team/aws-secret-key -t value -v \"AWS_SECRET_KEY\""
echo "credhub set -n /concourse/$team/github-access-token -t value -v \"\$(echo \$GITHUB_TOKEN)\""
echo "credhub set -n /concourse/$team/github-private-key -t value -v \"\$(cat ~/.ssh/id_rsa)\""
35 changes: 35 additions & 0 deletions go/helpers/initial_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
meta:
name: $(basename $PWD)
target: ${fly_target}
url: ${fly_target_url}

initial_version: 1.0.0

go:
version: "1.9"
binary: $(basename $PWD)
cmd_module: .

git:
email: ((git-commit-email))
name: ((git-commit-name))

aws:
bucket: (( grab meta.pipeline ))
region_name: us-east-1
access_key: ((aws-access-key))
secret_key: ((aws-secret-key))

github:
owner: $(basename $(dirname $PWD))
repo: $(basename $PWD)
branch: $(git branch --no-color | awk '{print $2}')
private_key: ((github-private-key))
access_token: ((github-access-token))

slack:
webhook: ((slack-webhook))
username: ((slack-username))
icon: ((slack-icon-url))
channel: "#$(basename $PWD)"
29 changes: 26 additions & 3 deletions setup
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,30 @@ case "${1}" in
;;
esac

template=$1
target=${2:-$(pwd)}
export template=$1
export target=${2:-$(pwd)}

apply_shell_expansion() {
declare file="$1"
declare data=$(< "$file")
declare delimiter="__apply_shell_expansion_delimiter__"
declare command="cat <<$delimiter"$'\n'"$data"$'\n'"$delimiter"
eval "$command"
}

initial_settings_yml() {
local settings_yml=${target}/ci/settings.yml
if [[ -f ${src}/${template}/helpers/initial_settings.yml ]]; then
export team=${team:-main}
export name=$(basename $target)
export fly_target=${fly_target:-$(fly targets | head -n1 | tail -n1 | awk '{print $1}')}
export fly_target_url=$(bosh int ~/.flyrc --path /targets/${fly_target}/api)
apply_shell_expansion ${src}/${template}/helpers/initial_settings.yml > $settings_yml
${src}/${template}/helpers/credhub-examples.sh
else
echo "--- {}" > $settings_yml
fi
}

[ -n ${template} ] || usage "ERROR: Missing pipeline template type" 1
[ -d ${target} ] || usage "ERROR: ${target} path not found" 1
Expand All @@ -35,6 +57,7 @@ pattern="^($(echo "$pipeline_types" | tr "\n" "|" | sed -e "s/\|*$//"))$"
echo "Installing ${template} pipeline in ${target}..."
mkdir -p ${target}/ci
cp -R ${src}/${template}/* ${target}/ci/
rm -rf ${target}/ci/helpers
cp ${src}/repipe ${target}/ci/
[ -f ${target}/ci/settings.yml ] || echo "--- {}" > ${target}/ci/settings.yml
[ -f ${target}/ci/settings.yml ] || initial_settings_yml ${template} ${target}
exit 0

0 comments on commit df524e9

Please sign in to comment.