|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# PRECONDITIONS |
| 4 | +# |
| 5 | +# It is assumed that: |
| 6 | +# 1. that you have setup a personal github access token (https://github.com/settings/tokens) |
| 7 | +# with admin:repo_hook scope and set up the environment |
| 8 | +# variables: |
| 9 | +# GH_USERNAME=<github user name> |
| 10 | +# GITHUB_PAT_TOKEN=<token generated> |
| 11 | + |
| 12 | +REPOSITORY_PATH="<owner>/<repository>" |
| 13 | +REPOSITORY="https://github.com/$REPOSITORY_PATH" |
| 14 | +OWNER="<email of owner>" |
| 15 | +SHARED_SECRET=<Any shared secret to be used by the webhook> |
| 16 | +WEBHOOK_HOSTNAME=webhook.radix.equinor.com|webhook.playground.radix.equinor.com|webhook.us.radix.equinor.com |
| 17 | + |
| 18 | +# Set access token for use in call to command line |
| 19 | +# Users should get this as part of their Radix application |
| 20 | +export APP_SERVICE_ACCOUNT_TOKEN= |
| 21 | + |
| 22 | +echo "Create application" |
| 23 | +PUBLIC_KEY=$(rx create application \ |
| 24 | + --token-environment \ |
| 25 | + --from-config \ |
| 26 | + --repository $REPOSITORY \ |
| 27 | + --owner $OWNER \ |
| 28 | + --shared-secret $SHARED_SECRET 2>&1) |
| 29 | + |
| 30 | +# Wait for application to be reconciled |
| 31 | +sleep 3 |
| 32 | + |
| 33 | +echo "Add webhook" |
| 34 | +RESPONSE=$(curl -X POST -H "Content-Type: application/json" -u ${GH_USERNAME}:${GITHUB_PAT_TOKEN} \ |
| 35 | + https://api.github.com/repos/$REPOSITORY_PATH/hooks \ |
| 36 | + -d '{"name":"web", "active": true, "config": { "url": "https://'${WEBHOOK_HOSTNAME}/events/github'", "content_type": "json", "secret": "'$SHARED_SECRET'" }}' 2>&1) |
| 37 | + |
| 38 | +echo "Add deploy key" |
| 39 | +PAYLOAD='{"title":"playground", "key": "'$PUBLIC_KEY'" }' |
| 40 | +RESPONSE=$(curl -X POST -H "Content-Type: application/json" -u ${GH_USERNAME}:${GITHUB_PAT_TOKEN} \ |
| 41 | + https://api.github.com/repos/$REPOSITORY_PATH/keys \ |
| 42 | + -d "$PAYLOAD" 2>&1) |
| 43 | + |
| 44 | +echo "Build from master branch" |
| 45 | +rx build-deploy \ |
| 46 | + --token-environment \ |
| 47 | + --from-config \ |
| 48 | + -f |
| 49 | + |
| 50 | +sleep 3 |
| 51 | +echo "Set environment secret" |
| 52 | +rx set environment-secret \ |
| 53 | + --token-environment \ |
| 54 | + --from-config \ |
| 55 | + --await-reconcile \ |
| 56 | + -e <your environment> \ |
| 57 | + --component <your component> \ |
| 58 | + -s <your secret name> \ |
| 59 | + -v '<your secret value>' |
| 60 | + |
| 61 | +echo "" |
| 62 | +read -p "Delete application again? (Y/n) " -n 1 -r |
| 63 | +if [[ "$REPLY" =~ (N|n) ]]; then |
| 64 | + echo "" |
| 65 | + echo "Chicken!" |
| 66 | +fi |
| 67 | + |
| 68 | +rx delete application \ |
| 69 | + --from-config |
0 commit comments