From eb6f38e099075299838f390e65dae8bc5287ccdf Mon Sep 17 00:00:00 2001 From: Radha <86818441+DrW3RK@users.noreply.github.com> Date: Tue, 24 Jan 2023 19:50:55 +0100 Subject: [PATCH] Remove IPFS refs (#4351) * Remove IPFS refs * Update deploy-kusama-staging.yml * Update deploy-polkadot-prod.yml * Update deploy-polkadot-staging.yml * Delete ipfs-cluster-pin.js --- .github/workflows/deploy-kusama-staging.yml | 37 ---- .github/workflows/deploy-polkadot-staging.yml | 48 ------ scripts/ipfs-cluster-pin.js | 160 ------------------ 3 files changed, 245 deletions(-) delete mode 100644 scripts/ipfs-cluster-pin.js diff --git a/.github/workflows/deploy-kusama-staging.yml b/.github/workflows/deploy-kusama-staging.yml index c7b17ca6e728..6978986a0107 100644 --- a/.github/workflows/deploy-kusama-staging.yml +++ b/.github/workflows/deploy-kusama-staging.yml @@ -19,34 +19,6 @@ jobs: with: fetch-depth: 0 - # - name: Clone and run the site - # run: | - # sudo apt-get install netcat - # yarn - # yarn kusama:start & - # while ! nc -z localhost 3000; do - # sleep 1 - # echo waiting for website up... - # done - # yarn kusama:pdf - - # - name: Upload PDF - # uses: actions/upload-artifact@v2 - # with: - # name: kusama-wiki - # path: kusama-guide/static/kusama-wiki.pdf - - # - name: Build - # run: yarn; yarn kusama:build - # env: - # BUILDING: true - - # - name: Upload to IPFS - # uses: aquiladev/ipfs-action@v0.1.4 - # with: - # path: ./kusama-guide/build - # timeout: 120000 - - name: Publish run: | git config --global user.email "polkadot-wiki-deploy@users.noreply.github.com" @@ -55,12 +27,3 @@ jobs: yarn && yarn kusama:build && echo "staging.kusama.network" > kusama-guide/static/CNAME && GIT_USER=w3fdeploy PUBLISHING=true PROJECT_NAME=kusama-guide-staging yarn run kusama:publish-gh-pages - - # setup ipfs cluster tools - - # wget https://dist.ipfs.io/ipfs-cluster-ctl/v0.14.0/ipfs-cluster-ctl_v0.14.0_linux-amd64.tar.gz - # tar xf ./ipfs-cluster-ctl_v0.14.0_linux-amd64.tar.gz - # chmod +x ./ipfs-cluster-ctl/ipfs-cluster-ctl - # export PATH=$PATH:`pwd`/ipfs-cluster-ctl - # which ipfs-cluster-ctl - # node ./scripts/ipfs-cluster-pin.js --auth ${{ secrets.CLUSTER_BASIC_AUTH_USER }}:${{ secrets.CLUSTER_BASIC_AUTH_PASSWORD }} --websiteDir ./kusama-guide/build --pinName kusama-guide-staging diff --git a/.github/workflows/deploy-polkadot-staging.yml b/.github/workflows/deploy-polkadot-staging.yml index 9a378816bb9e..48ea4b099a3a 100644 --- a/.github/workflows/deploy-polkadot-staging.yml +++ b/.github/workflows/deploy-polkadot-staging.yml @@ -19,46 +19,6 @@ jobs: with: fetch-depth: 0 - # - name: Clone and run the site - # run: | - # sudo apt-get install netcat - # yarn - # yarn polkadot:start & - # while ! nc -z localhost 3000; do - # sleep 1 - # echo waiting for website up... - # done - # yarn polkadot:pdf - - # - name: Upload PDF - # uses: actions/upload-artifact@v2 - # with: - # name: polkadot-wiki - # path: polkadot-wiki/static/polkadot-wiki.pdf - - # - name: Build - # run: yarn; yarn polkadot:build - # env: - # BUILDING: true - - # - name: Upload PDF to IPFS - # id: ipfs_pdf - # uses: aquiladev/ipfs-action@v0.1.4 - # with: - # path: ./polkadot-wiki/static/polkadot-wiki.pdf - # timeout: 120000 - - # - name: Inject - # run: yarn; yarn polkadot:inject - # env: - # IPFS_PDF_HASH: ${{ steps.ipfs_pdf.outputs.hash }} - - # - name: Upload to IPFS - # uses: aquiladev/ipfs-action@v0.1.4 - # with: - # path: ./polkadot-wiki/build/polkadot-wiki - # timeout: 120000 - - name: Publish run: | git config --global user.email "polkadot-wiki-deploy@users.noreply.github.com" @@ -66,11 +26,3 @@ jobs: echo "machine github.com login w3fdeploy password ${{ secrets.ACCESS_KEY }}" > ~/.netrc yarn && yarn polkadot:build && echo "staging.polkadot.network" > polkadot-wiki/static/CNAME && GIT_USER=w3fdeploy PUBLISHING=true PROJECT_NAME=polkadot-wiki-staging yarn run polkadot:publish-gh-pages - - # setup ipfs cluster tools - - # wget https://dist.ipfs.io/ipfs-cluster-ctl/v0.14.0/ipfs-cluster-ctl_v0.14.0_linux-amd64.tar.gz - # tar xf ./ipfs-cluster-ctl_v0.14.0_linux-amd64.tar.gz - # chmod +x ./ipfs-cluster-ctl/ipfs-cluster-ctl - # export PATH=$PATH:`pwd`/ipfs-cluster-ctl - # node ./scripts/ipfs-cluster-pin.js --auth ${{ secrets.CLUSTER_BASIC_AUTH_USER}}:${{ secrets.CLUSTER_BASIC_AUTH_PASSWORD}} --websiteDir ./polkadot-wiki/build --pinName polkadot-wiki-staging diff --git a/scripts/ipfs-cluster-pin.js b/scripts/ipfs-cluster-pin.js deleted file mode 100644 index 9031b92fc4d6..000000000000 --- a/scripts/ipfs-cluster-pin.js +++ /dev/null @@ -1,160 +0,0 @@ -const yargs = require("yargs"); -const { create, globSource } = require("ipfs-http-client"); -const { execSync } = require("child_process"); -const cloudflare = require("cloudflare"); - -const argv = yargs(process.argv) - .option("websiteDir", { - alias: "d", - description: "root directory to find files", - type: "string", - }) - .option("pinName", { - alias: "n", - description: "required. eg. polkadot-wiki", - type: "string", - }) - .option("auth", { - alias: "a", - description: "required. eg. asdf:1234", - type: "string", - }) - .option("cloudflareToken", { - alias: "cf", - description: "required", - type: "string", - }) - .option("zoneId", { - alias: "zid", - description: "required", - type: "string", - }) - .help() - .alias("help", "h").argv; - -if (!argv.websiteDir || !argv.pinName || !argv.auth || !argv.cloudflareToken || !argv.zoneId) { - throw new Error("Must pass --websiteDir, --auth, --cloudflareToken, --zoneId, and --pinName arguments."); -} - -var runCommandOnCluster = async (command, retries = 10) => { - // Note: js-cluster-api doesn't support libp2p so we have to use it via the compiled Go version via shell - const clusterCommander = async (command) => execSync( - `ipfs-cluster-ctl \ - --enc json \ - --basic-auth ${argv.auth} \ - --host /dns4/ipfs.w3f.community/tcp/9096/p2p/12D3KooWEGmyEGpLWN8HF2ToNX8sykBaPXTSx2BKiT4YnmAa9UKN \ - ${command} \n`, - { - encoding: 'utf-8', - stdio: null, - }); - - return clusterCommander(command).then( - (result) => { - try { - return JSON.parse(result); - } catch (err) { - // https://github.com/ipfs/ipfs-cluster/issues/1365 - console.log("Could not parse IPFS Cluster JSON response. This is not fatal."); - return null; - } - }, - (error) => { - if (retries > 0) { - console.log("Retrying cluster command..."); - return runCommandOnCluster(command, retries - 1); - } else { - return error; - } - }); -} - -// return CID as string from a named pin on the cluster -const getCidByPinName = async (pinName) => { - const pins = await runCommandOnCluster('status'); - const prevCidObject = pins.find(pin => pin.name == pinName); - return prevCidObject ? prevCidObject.cid["/"] : null; -} - - -class CFClient { - - constructor(pinName, apiToken) { - - this.cf = cloudflare({ - email: "jake@web3.foundation", - key: apiToken - }) - - this.zone = CFClient._getZoneFromPinName(pinName); - } - - static _getZoneFromPinName(pinName) { - const zones = { - "polkadot-wiki": "polkadot-wiki.w3f.community", - "kusama-guide": "kusama-guide.w3f.community" - } - - return zones[pinName]; - } - - async updateDNSLinkFromCID (newMultiaddr) { - const newRecord = { - type: "TXT", - name: this.zone, - content: `dnslink=/ipfs/${newMultiaddr}`, - ttl: 120, // seconds - } - - try { - const recordsList = this.cf.dnsRecords.browse(argv.zoneId); - const existingRecord = recordsList.find(record => record.name === this.zone); - - return this.cf.dnsRecords.edit({ - zone_id: argv.zoneId, - id: existingRecord.id, - record: newRecord, - }) - } catch (e) { - console.log('DNS Record does not exist:'); - console.log(newRecord); - console.log('Adding...'); - - return this.cf.dnsRecords.add({ - zone_id: argv.zoneId, - record: newRecord, - }) - } - } -} - -const main = async () => { - const cf = new CFClient(argv.pinName, argv.cloudflareToken); // we can derive which dns zone to use based on the pinName - // get and unpin the previous build from the cluster, if exists - const prevCid = await getCidByPinName(argv.pinName); - if (prevCid) { - await runCommandOnCluster(`pin rm ${prevCid}`); - console.log(`Unpinned '${argv.pinName}' (CID ${prevCid}).`); - } else { - console.log(`No existing pin named '${argv.pinName}'.`); - } - - // pin new build to cluster with new name - console.log(`Uploading and pinning '${argv.websiteDir}' to the cluster as '${argv.pinName}'...`); - await runCommandOnCluster(`add -r --name ${argv.pinName} ${argv.websiteDir}`); - const cid = await getCidByPinName(argv.pinName); - console.log(`Successfully added and pinned '${argv.pinName}' (CID ${cid}).`); - console.log("If above values are non-null, previous errors are non-fatal."); - - await cf.updateDNSLinkFromCID(cid); // update the - - // update DNS entry - // https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record - // https://github.com/cloudflare/node-cloudflare -}; - -try { - main(); -} catch (err) { - throw new Error(err.toString()); -}