Browse Source

Deploy to ipfs (#2778)

* Deploy to ipfs

* PINATA secrets

* Make <hash>.ipfs

* Use pinata sdk

* pin.json
Jaco Greeff 4 years ago
parent
commit
b220fc3a50
6 changed files with 357 additions and 177 deletions
  1. 3 1
      .github/workflows/push-master.yml
  2. 1 1
      README.md
  3. 4 2
      package.json
  4. 10 0
      packages/apps/public/ipfs/keep.txt
  5. 35 0
      scripts/ipfsUpload.js
  6. 304 173
      yarn.lock

+ 3 - 1
.github/workflows/push-master.yml

@@ -8,7 +8,7 @@ jobs:
   master:
     strategy:
       matrix:
-        step: ['build:release:www', 'build:release:electron', 'build:release:ipfs']
+        step: ['build:release:www', 'build:release:electron']
     name: ${{ matrix.step }}
     if: "! contains(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/apps'"
     runs-on: ubuntu-latest
@@ -22,6 +22,8 @@ jobs:
         GH_PAGES_SRC: packages/apps/build
         GH_PAT: ${{ secrets.GH_PAT }}
         NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
+        PINATA_API_KEY: ${{ secrets.PINATA_API_KEY }}
+        PINATA_SECRET_KEY: ${{ secrets.PINATA_SECRET_KEY }}
       run: |
         yarn install --immutable | grep -v 'YN0013'
         yarn ${{ matrix.step }}

+ 1 - 1
README.md

@@ -8,7 +8,7 @@
 
 A Portal into the Polkadot and Substrate networks. Provides a view and interaction layer from a browser.
 
-This can be accessed as a hosted application via [https://polkadot.js.org/apps/](https://polkadot.js.org/apps/) to explorer any of the supported Polkadot and Substrate chains
+This can be accessed as a hosted application via [https://polkadot.js.org/apps/](https://polkadot.js.org/apps/) or you can access the [IPFS hosted version](https://polkadot.js.org/apps/ipfs) to explore any of the supported Polkadot and Substrate chains
 
 **Important** If you are a chain developer and would like to add support for your chain to the UI, all the local configuration (API types, settings, logos) can be customized in [the apps-config package](packages/apps-config#README.md), complete with instructions of what goes where.
 

+ 4 - 2
package.json

@@ -23,8 +23,9 @@
     "build:electron": "echo \"Dummy\"",
     "build:i18n": "i18next-scanner --config i18next-scanner.config.js && node ./scripts/i18nSort.js",
     "build:release:electron": "echo \"Dummy\"",
-    "build:release:ipfs": "echo \"Dummy\"",
-    "build:release:www": "yarn polkadot-ci-ghact-build && yarn polkadot-ci-ghact-docs",
+    "build:release:ipfs": "node scripts/ipfsUpload.js",
+    "build:release:ghpages": "yarn polkadot-ci-ghact-docs",
+    "build:release:www": "yarn polkadot-ci-ghact-build && yarn build:release:ipfs && yarn build:release:ghpages",
     "build:www": "rm -rf packages/apps/build && mkdir -p packages/apps/build && yarn run build:i18n && cd packages/apps && NODE_ENV=production webpack --config webpack.config.js",
     "docs": "echo \"skipping docs\"",
     "clean": "polkadot-dev-clean-build",
@@ -40,6 +41,7 @@
     "@babel/core": "^7.9.6",
     "@babel/register": "^7.9.0",
     "@babel/runtime": "^7.9.6",
+    "@pinata/sdk": "^1.1.9",
     "@polkadot/dev": "^0.53.5",
     "@polkadot/ts": "^0.3.22",
     "@types/bn.js": "^4.11.6",

+ 10 - 0
packages/apps/public/ipfs/keep.txt

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Redirecting to latest deployed IPFS instance</title>
+    <meta http-equiv="refresh" content="2; url=${url}" />
+  </head>
+  <body>
+    <p>Redirecting you to <a href="${url}">${url}</a></p>
+  </body>
+</html>

+ 35 - 0
scripts/ipfsUpload.js

@@ -0,0 +1,35 @@
+// Copyright 2017-2020 @polkadot/apps authors & contributors
+// This software may be modified and distributed under the terms
+// of the Apache-2.0 license. See the LICENSE file for details.
+
+const fs = require('fs');
+const pinataSDK = require('@pinata/sdk');
+
+const ROOT = 'packages/apps/build';
+
+const pinata = pinataSDK(process.env.PINATA_API_KEY, process.env.PINATA_SECRET_KEY);
+
+async function main () {
+  const result = await pinata.pinFromFS(ROOT);
+  const url = `https://ipfs.io/ipfs/${result.IpfsHash}/`; // `https://gateway.pinata.cloud/ipfs/${pinnedHash}/`;
+  const html = `<!DOCTYPE html>
+<html>
+  <head>
+    <title>Redirecting to latest deployed IPFS instance</title>
+    <meta http-equiv="refresh" content="2; url=${url}" />
+  </head>
+  <body>
+    <p>Redirecting you to <a href="${url}">${url}</a></p>
+  </body>
+</html>`;
+
+  fs.writeFileSync(`${ROOT}/ipfs/index.html`, html);
+  fs.writeFileSync(`${ROOT}/ipfs/pin.json`, JSON.stringify(result));
+  fs.writeFileSync(`${ROOT}/ipfs/${result.IpfsHash}.ipfs`, result.IpfsHash);
+
+  console.log(`Deployed to ${url}`);
+}
+
+main()
+  .catch(console.error)
+  .finally(() => process.exit());

File diff suppressed because it is too large
+ 304 - 173
yarn.lock


Some files were not shown because too many files changed in this diff