Skip to content

Instantly share code, notes, and snippets.

@technosophos
Created November 10, 2017 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save technosophos/bd13903c536e7a07dd1a3c58aedea2c7 to your computer and use it in GitHub Desktop.
Save technosophos/bd13903c536e7a07dd1a3c58aedea2c7 to your computer and use it in GitHub Desktop.
Git post-receive hook that creates Brigade event
#!/bin/bash
while read oldrev newrev refname
do
short_sha=${newrev:0:8}
ulid=$(/usr/local/bin/ulid)
build_id="acid-worker-${ulid}-${short_sha}"
e_build_id=$(echo "$build_id" | base64 -w 0)
e_project_id=$(echo "$ACID_PROJECT_ID" | base64 -w 0)
e_acidjs=$(git show ${newrev}:acid.js | base64 -w 0)
e_payload=$(echo "{}" | base64 -w 0)
e_event=$(echo "post-receive" | base64 -w 0)
e_provider=$(echo "acid-git-server" | base64 -w 0)
e_commit=$(echo "$newrev" | base64 -w 0)
echo "Deploying $newrev"
cat << EOF > "/tmp/secret.yaml"
apiVersion: v1
kind: Secret
metadata:
name: ${build_id}
labels:
build: ${ulid}
commit: ${newrev}
component: build
heritage: acid
project: ${ACID_PROJECT_ID}
data:
script: |-
${e_acidjs}
payload: |-
${e_payload}
project_id: ${e_project_id}
event_type: ${e_event}
event_provider: ${e_provider}
commit: ${e_commit}
build_id: ${e_build_id}
EOF
#kubectl create secret -f /tmp/secret.yaml
echo "Generated:"
cat /tmp/secret.yaml
kubectl create -f /tmp/secret.yaml
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment