diff --git a/boshrelease/helpers/credhub-examples.sh b/boshrelease/helpers/credhub-examples.sh new file mode 100755 index 0000000..6c7a4a3 --- /dev/null +++ b/boshrelease/helpers/credhub-examples.sh @@ -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)\"" diff --git a/boshrelease/helpers/initial_settings.yml b/boshrelease/helpers/initial_settings.yml new file mode 100644 index 0000000..188197e --- /dev/null +++ b/boshrelease/helpers/initial_settings.yml @@ -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>" ))' diff --git a/cfpush/helpers/credhub-examples.sh b/cfpush/helpers/credhub-examples.sh new file mode 100755 index 0000000..4162b65 --- /dev/null +++ b/cfpush/helpers/credhub-examples.sh @@ -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\"" diff --git a/cfpush/helpers/initial_settings.yml b/cfpush/helpers/initial_settings.yml new file mode 100644 index 0000000..f16e600 --- /dev/null +++ b/cfpush/helpers/initial_settings.yml @@ -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 diff --git a/docker/base/helpers/credhub-examples.sh b/docker/base/helpers/credhub-examples.sh new file mode 100755 index 0000000..25e57fa --- /dev/null +++ b/docker/base/helpers/credhub-examples.sh @@ -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" diff --git a/docker/base/helpers/initial_settings.yml b/docker/base/helpers/initial_settings.yml new file mode 100644 index 0000000..208dbba --- /dev/null +++ b/docker/base/helpers/initial_settings.yml @@ -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)" diff --git a/go/helpers/credhub-examples.sh b/go/helpers/credhub-examples.sh new file mode 100755 index 0000000..c54d44c --- /dev/null +++ b/go/helpers/credhub-examples.sh @@ -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)\"" diff --git a/go/helpers/initial_settings.yml b/go/helpers/initial_settings.yml new file mode 100644 index 0000000..f2387fe --- /dev/null +++ b/go/helpers/initial_settings.yml @@ -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)" diff --git a/setup b/setup index bcc56a2..5cd1911 100755 --- a/setup +++ b/setup @@ -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 @@ -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