Skip to content

Commit df524e9

Browse files
authored
Initial ci/settings.yml is populated with example parameters (#27)
* 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
1 parent 111f4e5 commit df524e9

File tree

9 files changed

+207
-3
lines changed

9 files changed

+207
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
echo "Example commands for setting up credhub for your pipeline:"
2+
echo "team=$team"
3+
echo "credhub set -n /concourse/\$team/git-commit-email -t value -v \"\$(git config user.email)\""
4+
echo "credhub set -n /concourse/\$team/git-commit-name -t value -v \"\$(git config user.name)\""
5+
echo "credhub set -n /concourse/\$team/aws-access-key -t value -v \"\$(grep access_key_id config/private.yml | awk '{print \$2}')\""
6+
echo "credhub set -n /concourse/\$team/aws-secret-key -t value -v \"\$(grep secret_access_key config/private.yml | awk '{print \$2}')\""
7+
echo "credhub set -n /concourse/\$team/$name/slack-username -t value -v concourse"
8+
echo "credhub set -n /concourse/\$team/$name/slack-icon-url -t value -v https://cl.ly/2F421Y300u07/concourse-logo-blue-transparent.png"
9+
echo
10+
echo "credhub set -n /concourse/\$team/$name/slack-webhook -t value -v https://slack.com/skip-slack-for-now"
11+
echo "credhub set -n /concourse/\$team/github-access-token -t value -v \"\$(echo \$GITHUB_TOKEN)\""
12+
echo "credhub set -n /concourse/\$team/github-private-key -t value -v \"\$(cat ~/.ssh/id_rsa)\""
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
meta:
3+
name: $(grep final_name config/final.yml | awk '{print $2}')
4+
target: ${fly_target}
5+
url: ${fly_target_url}
6+
7+
test-errand: ~
8+
9+
initial_version: 1.0.0
10+
11+
git:
12+
email: ((git-commit-email))
13+
name: ((git-commit-name))
14+
15+
bosh-lite:
16+
target: ((bosh-lite-environment))
17+
cacert: ((bosh-lite-ca-cert))
18+
username: ((bosh-lite-client))
19+
password: ((bosh-lite-client-secret))
20+
21+
aws:
22+
bucket: (( grab meta.pipeline ))
23+
region_name: us-east-1
24+
access_key: ((aws-access-key))
25+
secret_key: ((aws-secret-key))
26+
27+
github:
28+
owner: cloudfoundry-community
29+
repo: (( grab meta.pipeline ))
30+
branch: $(git branch --no-color | awk '{print $2}')
31+
private_key: ((github-private-key))
32+
access_token: ((github-access-token))
33+
34+
slack:
35+
webhook: ((slack-webhook))
36+
username: ((slack-username))
37+
icon: ((slack-icon-url))
38+
channel: (( concat meta.name "-boshrelease" ))
39+
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?>" ))'
40+
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>" ))'

cfpush/helpers/credhub-examples.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
echo "Example commands for setting up credhub for your pipeline:"
2+
echo
3+
echo "For GitHub:"
4+
echo "credhub set -n /concourse/$team/github-access-token -t value -v \"\$(echo \$GITHUB_TOKEN)\""
5+
echo "credhub set -n /concourse/$team/github-private-key -t value -v \"\$(cat ~/.ssh/id_rsa)\""
6+
echo
7+
echo "For Cloud Foundry ($(jq .Target -r ~/.cf/config.json)):"
8+
echo "credhub set -n /concourse/$team/cf-username -t value -v \"your-username\""
9+
echo "credhub set -n /concourse/$team/cf-password -t value -v \"your-password\""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
meta:
3+
name: $(basename $PWD)
4+
target: ${fly_target}
5+
url: ${fly_target_url}
6+
7+
github:
8+
owner: $(jq .OrganizationFields.Name -r ~/.cf/config.json)
9+
repo: $(basename $PWD)
10+
branch: $(git branch --no-color | awk '{print $2}')
11+
private_key: ((github-private-key))
12+
access_token: ((github-access-token))
13+
14+
cf:
15+
api: $(jq .Target -r ~/.cf/config.json)
16+
skip_cert_check: false
17+
username: ((cf-username))
18+
password: ((cf-password))
19+
appname: $(basename $PWD)
20+
organization: $(jq .OrganizationFields.Name -r ~/.cf/config.json)
21+
spaces:
22+
staging: $(basename $PWD)-staging
23+
production: $(basename $PWD)-production
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
echo "Example commands for setting up credhub for your pipeline:"
2+
echo "credhub set -n /concourse/$team/git-commit-email -t value -v \"\$(git config user.email)\""
3+
echo "credhub set -n /concourse/$team/git-commit-name -t value -v \"\$(git config user.name)\""
4+
echo "credhub set -n /concourse/$team/slack-username -t value -v concourse"
5+
echo "credhub set -n /concourse/$team/slack-icon-url -t value -v https://cl.ly/2F421Y300u07/concourse-logo-blue-transparent.png"
6+
echo
7+
echo "credhub set -n /concourse/$team/$name/slack-webhook -t value -v https://slack.com/skip-slack-for-now"
8+
echo "credhub set -n /concourse/$team/aws-access-key -t value -v \"AWS_ACCESS_KEY\""
9+
echo "credhub set -n /concourse/$team/aws-secret-key -t value -v \"AWS_SECRET_KEY\""
10+
echo "credhub set -n /concourse/$team/github-access-token -t value -v \"\$(echo \$GITHUB_TOKEN)\""
11+
echo "credhub set -n /concourse/$team/github-private-key -t value -v \"\$(cat ~/.ssh/id_rsa)\""
12+
echo
13+
echo "credhub set -n /concourse/$team/dockerhub-username -t value -v \"\$(whoami)\""
14+
echo "credhub set -n /concourse/$team/dockerhub-email -t value -v \"\$(git config user.email)\""
15+
echo "credhub set -n /concourse/$team/dockerhub-password -t value -v \"PASSWORD"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
meta:
3+
name: $(basename $PWD)
4+
target: ${fly_target}
5+
url: ${fly_target_url}
6+
7+
initial_version: 1.0.0
8+
9+
git:
10+
email: ((git-commit-email))
11+
name: ((git-commit-name))
12+
13+
dockerhub:
14+
username: ((dockerhub-username))
15+
email: ((dockerhub-email))
16+
password: ((dockerhub-password))
17+
repository: (( concat meta.github.owner "/" meta.name ))
18+
19+
aws:
20+
bucket: (( grab meta.pipeline ))
21+
region_name: us-east-1
22+
access_key: ((aws-access-key))
23+
secret_key: ((aws-secret-key))
24+
25+
github:
26+
owner: $(jq .OrganizationFields.Name -r ~/.cf/config.json)
27+
repo: $(basename $PWD)
28+
branch: $(git branch --no-color | awk '{print $2}')
29+
private_key: ((github-private-key))
30+
access_token: ((github-access-token))
31+
32+
slack:
33+
webhook: ((slack-webhook))
34+
username: ((slack-username))
35+
icon: ((slack-icon-url))
36+
channel: "#$(basename $PWD)"

go/helpers/credhub-examples.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
echo "Example commands for setting up credhub for your pipeline:"
2+
echo "credhub set -n /concourse/$team/git-commit-email -t value -v \"\$(git config user.email)\""
3+
echo "credhub set -n /concourse/$team/git-commit-name -t value -v \"\$(git config user.name)\""
4+
echo "credhub set -n /concourse/$team/slack-username -t value -v concourse"
5+
echo "credhub set -n /concourse/$team/slack-icon-url -t value -v https://cl.ly/2F421Y300u07/concourse-logo-blue-transparent.png"
6+
echo
7+
echo "credhub set -n /concourse/$team/$name/slack-webhook -t value -v https://slack.com/skip-slack-for-now"
8+
echo "credhub set -n /concourse/$team/aws-access-key -t value -v \"AWS_ACCESS_KEY\""
9+
echo "credhub set -n /concourse/$team/aws-secret-key -t value -v \"AWS_SECRET_KEY\""
10+
echo "credhub set -n /concourse/$team/github-access-token -t value -v \"\$(echo \$GITHUB_TOKEN)\""
11+
echo "credhub set -n /concourse/$team/github-private-key -t value -v \"\$(cat ~/.ssh/id_rsa)\""

go/helpers/initial_settings.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
meta:
3+
name: $(basename $PWD)
4+
target: ${fly_target}
5+
url: ${fly_target_url}
6+
7+
initial_version: 1.0.0
8+
9+
go:
10+
version: "1.9"
11+
binary: $(basename $PWD)
12+
cmd_module: .
13+
14+
git:
15+
email: ((git-commit-email))
16+
name: ((git-commit-name))
17+
18+
aws:
19+
bucket: (( grab meta.pipeline ))
20+
region_name: us-east-1
21+
access_key: ((aws-access-key))
22+
secret_key: ((aws-secret-key))
23+
24+
github:
25+
owner: $(basename $(dirname $PWD))
26+
repo: $(basename $PWD)
27+
branch: $(git branch --no-color | awk '{print $2}')
28+
private_key: ((github-private-key))
29+
access_token: ((github-access-token))
30+
31+
slack:
32+
webhook: ((slack-webhook))
33+
username: ((slack-username))
34+
icon: ((slack-icon-url))
35+
channel: "#$(basename $PWD)"

setup

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,30 @@ case "${1}" in
2323
;;
2424
esac
2525

26-
template=$1
27-
target=${2:-$(pwd)}
26+
export template=$1
27+
export target=${2:-$(pwd)}
28+
29+
apply_shell_expansion() {
30+
declare file="$1"
31+
declare data=$(< "$file")
32+
declare delimiter="__apply_shell_expansion_delimiter__"
33+
declare command="cat <<$delimiter"$'\n'"$data"$'\n'"$delimiter"
34+
eval "$command"
35+
}
36+
37+
initial_settings_yml() {
38+
local settings_yml=${target}/ci/settings.yml
39+
if [[ -f ${src}/${template}/helpers/initial_settings.yml ]]; then
40+
export team=${team:-main}
41+
export name=$(basename $target)
42+
export fly_target=${fly_target:-$(fly targets | head -n1 | tail -n1 | awk '{print $1}')}
43+
export fly_target_url=$(bosh int ~/.flyrc --path /targets/${fly_target}/api)
44+
apply_shell_expansion ${src}/${template}/helpers/initial_settings.yml > $settings_yml
45+
${src}/${template}/helpers/credhub-examples.sh
46+
else
47+
echo "--- {}" > $settings_yml
48+
fi
49+
}
2850

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

0 commit comments

Comments
 (0)