Skip to content

Commit

Permalink
Add cloudflare + pinata to CI (#76)
Browse files Browse the repository at this point in the history
* Add staging cloudflare ci

* Add pinata

* Clean up
  • Loading branch information
raymondjacobson authored and michellebrier committed Oct 9, 2023
1 parent 83e658e commit 1f0a750
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 17 deletions.
38 changes: 22 additions & 16 deletions packages/protocol-dashboard/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ jobs:
update-staging-records:
working_directory: ~/protocol-dashboard
docker:
- image: circleci/python:2.7-jessie
- image: circleci/node:10.13
steps:
- run:
name: install-awscli
command: sudo pip install awscli
- attach_workspace:
at: ./
- run:
name: Update AWS records
name: Update Cloudflare records
command: |
DNS_NAME=_dnslink.dashboard.staging.audius.org
CID=$(cat ./build_cid.txt)
echo '{"Comment": "Update the ipfs CID for the protocol dashboard","Changes": [ {"Action": "UPSERT","ResourceRecordSet": {"Name": "'"$DNS_NAME"'","Type": "TXT","TTL": 600,"ResourceRecords": [ {"Value": "\"dnslink=/ipfs/'"$CID"'\"" } ] } } ]}' | tee change-record.json
aws route53 change-resource-record-sets --hosted-zone-id Z1MUWPKHC6C6L4 --change-batch file://$(pwd)/change-record.json
curl -X PUT "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE}/dns_records/${CLOUDFLARE_STAGE_DASHBOARD_DNS_ID}" \
-H "X-Auth-Email: ${CLOUDFLARE_AUTH_EMAIL}" \
-H "Authorization: Bearer ${CLOUDFLARE_AUTH_KEY}" \
-H "Content-Type: application/json" \
--data '{"type":"TXT","name":"'"$DNS_NAME"'","content":"\"dnslink=/ipfs/'"$CID"'\"","ttl":1,"proxied":false}'
build-prod:
working_directory: ~/protocol-dashboard
Expand Down Expand Up @@ -162,20 +162,20 @@ jobs:
update-prod-records:
working_directory: ~/protocol-dashboard
docker:
- image: circleci/python:2.7-jessie
- image: circleci/node:10.13
steps:
- run:
name: install-awscli
command: sudo pip install awscli
- attach_workspace:
at: ./
- run:
name: Update AWS records
name: Update Cloudflare records
command: |
DNS_NAME=_dnslink.dashboard.audius.org
CID=$(cat ./build_cid.txt)
echo '{"Comment": "Update the ipfs CID for the protocol dashboard","Changes": [ {"Action": "UPSERT","ResourceRecordSet": {"Name": "'"$DNS_NAME"'","Type": "TXT","TTL": 600,"ResourceRecords": [ {"Value": "\"dnslink=/ipfs/'"$CID"'\"" } ] } } ]}' | tee change-record.json
aws route53 change-resource-record-sets --hosted-zone-id Z1MUWPKHC6C6L4 --change-batch file://$(pwd)/change-record.json
curl -X PUT "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE}/dns_records/${CLOUDFLARE_PROD_DASHBOARD_DNS_ID}" \
-H "X-Auth-Email: ${CLOUDFLARE_AUTH_EMAIL}" \
-H "Authorization: Bearer ${CLOUDFLARE_AUTH_KEY}" \
-H "Content-Type: application/json" \
--data '{"type":"TXT","name":"'"$DNS_NAME"'","content":"\"dnslink=/ipfs/'"$CID"'\"","ttl":1,"proxied":false}'
workflows:
version: 2
Expand All @@ -193,6 +193,7 @@ workflows:
branches:
only: /^main$/
- update-staging-ga-build:
context: Pinata
requires:
- deploy-staging
filters:
Expand All @@ -206,7 +207,9 @@ workflows:
branches:
only: /^main$/
- update-staging-records:
context: Audius Client
context:
- Audius Client
- Cloudflare API
requires:
- hold-update-staging-records
filters:
Expand All @@ -230,6 +233,7 @@ workflows:
branches:
only: /^main$/
- update-prod-ga-build:
context: Pinata
requires:
- deploy-prod
filters:
Expand All @@ -243,7 +247,9 @@ workflows:
branches:
only: /^main$/
- update-prod-records:
context: Audius Client
context:
- Audius Client
- Cloudflare API
requires:
- hold-update-prod-records
filters:
Expand Down
67 changes: 67 additions & 0 deletions packages/protocol-dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/protocol-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"devDependencies": {
"@babel/preset-typescript": "^7.10.4",
"@openzeppelin/test-helpers": "^0.5.6",
"@pinata/sdk": "^1.1.13",
"@types/3box": "^1.22.0",
"@types/classnames": "^2.2.10",
"@types/jest": "^24.9.1",
Expand Down
29 changes: 28 additions & 1 deletion packages/protocol-dashboard/scripts/updateBuild.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const fs = require('fs')
const fetch = require('node-fetch')
const AbortController = require('abort-controller')
const pinataSDK = require('@pinata/sdk')

const pinata = pinataSDK(process.env.PINATA_KEY_NAME, process.env.PINATA_KEY_SECRET)

const args = process.argv
console.log(process.argv)
Expand Down Expand Up @@ -67,6 +70,7 @@ const updateContentNodePeers = async () => {
}
console.log('Added ipfs peers')
console.log(JSON.stringify(connections, null, ' '))
return addr
}

const updateGABuild = async () => {
Expand All @@ -91,11 +95,34 @@ const pinGABuild = async () => {
return cid
}

const pinPinata = async (cid, addr) => {
const options = {
pinataMetadata: {
name: `Dashboard build ${env} ${cid} - ${new Date().toISOString()}`
},
pinataOptions: {
hostNodes: [
addr
]
}
}
return new Promise((resolve, reject) => {
pinata.pinByHash(cid, options)
.then((result) => {
console.log(`CID ${cid} pinned to pinata`)
resolve(result)
}).catch((err) => {
reject(err)
})
})
}

const run = async () => {
try {
await updateContentNodePeers()
const addr = await updateContentNodePeers()
await updateGABuild()
const cid = await pinGABuild()
await pinPinata(cid, addr)
fs.writeFileSync(`./build_cid.txt`, cid)
process.exit()
} catch (err) {
Expand Down

0 comments on commit 1f0a750

Please sign in to comment.