Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ceejbot
Last active August 11, 2021 16:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceejbot/a9cf6516ef19c84c22fd516ff3073f20 to your computer and use it in GitHub Desktop.
Save ceejbot/a9cf6516ef19c84c22fd516ff3073f20 to your computer and use it in GitHub Desktop.
Using Honeycomb's buildevents tool inside a github action
name: deploy service tar
on:
push:
branches:
- 'deploy/*'
jobs:
docker:
name: Build and archive service
runs-on: ubuntu-latest
env:
# these env vars are used by the honeycomb buildevents
BUILDEVENT_APIKEY: ${{ secrets.BUILDEVENT_APIKEY }}
BUILDEVENT_DATASET: 'builds'
BUILDEVENT_CIPROVIDER: 'github-actions'
steps:
- run: echo $(date +%s) > ../build-start
- uses: actions/checkout@v2
# install language-specific build tools here (for us, this is node)
# this is a bit of bash to wrap up reporting to slack
- name: create slack script
run: |
cat <<EOF > slack
#!/bin/bash
curl -X POST --data-urlencode "payload={\"channel\": \"#deploys\", \"username\": \"deployomat-9000\", \"text\": \"\$1\", \"icon_emoji\": \":robot_face:\"}" ${{ secrets.SLACK_DEPLOYS_CHANNEL }}
EOF
chmod +x slack
sudo mv slack /usr/local/bin
- name: install honeycomb buildevents tool
run: |
sudo curl -L -o /usr/local/bin/buildevents https://github.com/honeycombio/buildevents/releases/download/v0.4.9/buildevents-linux-amd64
sudo chmod 755 /usr/local/bin/buildevents
# this is a unique but informative to humans name for the build
- name: name this build
run: |
echo $(echo $GITHUB_REF | sed -n "s/refs\/heads\/deploy\/\(.\+\)/\1/p") > environment
echo $(git rev-parse --short HEAD) > git-hash
echo "$GIHUB_REPOSITORY-$(cat git-hash)-$GITHUB_RUN_ID" > build-tag
echo "tag: $(cat build-tag)"
- name: slack build start
run: |
slack ":gear: <https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|$GIHUB_REPOSITORY@$(cat git-hash)> deploying to \`$(cat environment)\`"
# actual build steps go here
# you can wrap these into a trace step if they're complex
# or use the `cmd` wrapper if they're not
- name: tar
run: buildevents cmd $(cat build-tag) 0 tar -- tar cfzv /tmp/output.tar.gz --exclude=.git --exclude=.env --exclude=.github .
# a bunch of metadata building elided from this step, but the s3 metadata includes
# the build tag we constructed above, so the deploying host can connect its work to this
- name: aws s3 cp
run: |
buildevents cmd $tag 0 aws-s3-cp -- aws s3 cp --metadata "$metadata" /tmp/output.tar.gz $url
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: capture buildevents step
if: always()
run: buildevents step $(cat build-tag) 0 $(cat ../build-start) build-service
- name: finalize and send failed buildevents build
if: failure()
run: |
buildevents build $(cat build-tag) $(cat ../build-start) failure > trace-url
slack ":warning: <https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|$GIHUB_REPOSITORY@$(cat git-hash)> build for \`$(cat environment)\` failed; <$(cat trace-url)|build statistics>"
- name: report build success to slack
if: success()
run: |
slack ":white_check_mark: <https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|$GIHUB_REPOSITORY@$(cat git-hash)> build for \`$(cat environment)\` complete"
# note that we don't close the trace here! we do that on scripts that run on the target boxes, so we can
# carry the trace all the way through the deploy process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment