Skip to content

Commit 51ef698

Browse files
committed
feat: Prevent Infura timeouts when only pinner
Was pinning locally then sending Infura the hash for pinning like with Pinata, but that doesn't work because Infura doesn't take a host_nodes field to speed up finding the local peer with the data so it ends up timing out. Now we just send via HTTPS directly, no need for local daemon or port forwarding (unless also deploying to Pinata). Also: - Add --port option for IPFS daemon used to pin to Pinata - Check if daemon port is externally reachable (js-ipfs doesn't do port forwarding yet) - Remove ipv6 stuff that is unsupported by Pinata - Improve status output
1 parent d235243 commit 51ef698

File tree

5 files changed

+1981
-1851
lines changed

5 files changed

+1981
-1851
lines changed

README.md

Lines changed: 74 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,22 @@
1010
</a>
1111
</p>
1212

13-
## 🚨 WARNING: This is alpha software and very much in "works for me" status. APIs and CLI options will change. Use with caution, but please use it, give feedback, and consider contributing :) If it works for you too, [please let me know on this issue](https://github.com/agentofuser/ipfs-deploy/issues/1 'feedback').
13+
## 🚨 WARNING: This is beta software and very much in "works for me" status. APIs and CLI options will change. Use with caution, but please use it, give feedback, and consider contributing :) If it works for you too, [please let me know on this issue](https://github.com/agentofuser/ipfs-deploy/issues/1 'feedback').
1414

1515
The goal of `@agentofuser/ipfs-deploy` is to make it as easy as possible to
16-
deploy a static website to IPFS.
16+
**deploy a static website to IPFS.**
1717

1818
## Table of Contents
1919

20-
- [Security](#security)
21-
- [Background](#background)
2220
- [Install](#install)
2321
- [Usage](#usage)
2422
- [API](#api)
23+
- [Security](#security)
24+
- [Background](#background)
2525
- [Contributing](#contributing)
2626
- [Who's Using](#users)
2727
- [License](#license)
2828

29-
## Security
30-
31-
We use `dotenv` to handle credentials. Don't commit your `.env` file to source
32-
control.
33-
34-
## Background
35-
36-
You can start using `ipfs-deploy` without signing up for anything.
37-
38-
Default settings deploy to [infura.io](https://infura.io), which doesn't
39-
request an account to pin our stuff. They probably do some rate-limiting, but
40-
either way, take it easy on them. Being able to try things out without friction
41-
and without giving out personal info is a very important smooth on-ramp.
42-
43-
So far, `ipfs-deploy` integrates with these services:
44-
45-
- [Infura.io](https://infura.io): freemium pinning service. Doesn't require
46-
signup.
47-
- [Pinata.cloud](https://pinata.cloud): freemium pinning service. Gives more
48-
control over what's uploaded. You can delete, label, and add metadata.
49-
- [Cloudflare DNS](https://cloudflare.com): freemium DNS API. Supports CNAME
50-
for naked domains and integrates with their IPFS gateway at
51-
[cloudflare-ipfs.com](https://cloudflare-ipfs.com).
52-
53-
Feel free to request or add support to other services.
54-
55-
Cloudflare IPFS doesn't host the content itself (it's a cached gateway), so a
56-
stable pinning service is needed if you don't want to rely on your computer's
57-
IPFS daemon's availability to serve your website.
58-
59-
These are free services subject to their terms. Not a decentralization nirvana
60-
by any stretch of the imagination, but a nice way to get started quickly with a
61-
blog, static website, or frontend web app.
62-
63-
If you use this package to deploy your website, send a pull request so I can
64-
add it to the README. (I reserve the right to exercise discretion.)
65-
6629
## Install
6730

6831
### As a library:
@@ -97,12 +60,37 @@ Just remember to have the credentials properly set up as instructed below.
9760

9861
## Usage
9962

100-
### As an executable:
63+
You can get started just by typing out **ipd** and it will have smart defaults.
64+
65+
It deploys to a service that doesn't need signup and gives you a link like
66+
`ipfs.io/ipfs/hash` that you can use to see if everything went ok.
67+
68+
When you don't specify a path argument to deploy, **ipfs-deploy** tries to
69+
guess it for you based on the build directories used by the most popular static
70+
site generators:
71+
72+
```javascript
73+
const guesses = [
74+
'_site', // jekyll, hakyll
75+
'site',
76+
'public', // gatsby, hugo
77+
'dist', // nuxt
78+
'output', // pelican
79+
'out', // hexo
80+
'build', // metalsmith, middleman
81+
'website/build', // docusaurus
82+
'docs',
83+
]
84+
```
85+
86+
---
87+
88+
The `--help` option has some additional usage examples:
10189

10290
```
10391
Examples:
10492
ipfs-deploy # Deploys relative path "public" to
105-
ipfs.infura.io/ipfs/<hash>; doesn't
93+
ipfs.infura.io/ipfs/hash; doesn't
10694
update DNS; copies and opens URL.
10795
These defaults are chosen so as not
10896
to require signing up for any
@@ -117,16 +105,17 @@ Examples:
117105
DNS
118106
```
119107

120-
I won't go over how to set up Pinata and Cloudflare right now, but you can read
121-
up on that over at:
108+
To use Pinata and Cloudflare you need to sign up for those services. You can
109+
read up on that over at:
122110

123111
https://www.cloudflare.com/distributed-web-gateway
124112

125113
and:
126114

127115
https://pinata.cloud/documentation#GettingStarted
128116

129-
(Infura doesn't require creating an account.)
117+
(Infura doesn't require creating an account and is therefore the default
118+
pinning service used.)
130119

131120
After setting up your Cloudflare and Pinata accounts, in your website's
132121
repository root, create or edit the file `.env` with your domain and
@@ -178,13 +167,13 @@ Then to run it, execute:
178167
npm run deploy
179168
```
180169

181-
### As a library:
170+
## API
182171

183172
This is still pretty unstable and subject to change, so I will just show how
184173
the executable currently uses the API.
185174

186175
```javascript
187-
const deploy = require('ipfs-deploy')
176+
const deploy = require('@agentofuser/ipfs-deploy')
188177

189178
;(async () => {
190179
try {
@@ -212,6 +201,43 @@ const deploy = require('ipfs-deploy')
212201
})()
213202
```
214203

204+
## Security
205+
206+
We use `dotenv` to handle credentials. Don't commit your `.env` file to source
207+
control.
208+
209+
## Background
210+
211+
So far, `ipfs-deploy` integrates with these services:
212+
213+
- [Infura.io](https://infura.io): freemium pinning service. Doesn't require
214+
signup. (Default.)
215+
- [Pinata.cloud](https://pinata.cloud): freemium pinning service. Gives more
216+
control over what's uploaded. You can delete, label, and add metadata.
217+
- [Cloudflare DNS](https://cloudflare.com): freemium DNS API. Supports CNAME
218+
for naked domains and integrates with their IPFS gateway at
219+
[cloudflare-ipfs.com](https://cloudflare-ipfs.com).
220+
221+
Feel free to request or add support to other services and send a PR.
222+
223+
You can start using `ipfs-deploy` without signing up for anything.
224+
225+
Default settings deploy to [infura.io](https://infura.io), which doesn't
226+
request an account to pin stuff. They probably do some rate-limiting, but
227+
either way, take it easy on them. Being able to try IPFS out without friction
228+
and without giving out personal info is a very important smooth on-ramp.
229+
230+
Cloudflare IPFS doesn't host the content itself (it's a cached gateway), so a
231+
stable pinning service is needed if you don't want to rely on your computer's
232+
IPFS daemon's availability to serve your website.
233+
234+
These are free services subject to their terms. Not a decentralization nirvana
235+
by any stretch of the imagination, but a nice way to get started quickly with a
236+
blog, static website, or frontend web app.
237+
238+
If you use this package to deploy your website, please send a pull request so I
239+
can add it to the README. (I reserve the right to exercise discretion.)
240+
215241
## Contributing
216242

217243
PRs accepted. Please open an issue first so we can talk about it.

bin/ipfs-deploy.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const deploy = require('../index')
66

77
require('dotenv').config()
88

9-
const argv = yargs
9+
const parser = yargs
1010
.scriptName('ipfs-deploy')
1111
.usage(
1212
'$0 [options] [path]',
@@ -42,6 +42,12 @@ const argv = yargs
4242
'path'
4343
)} will be uploaded`,
4444
},
45+
port: {
46+
default: '4002',
47+
describe:
48+
'Externally reachable port for pinners to connect to ' +
49+
'local IPFS node',
50+
},
4551
})
4652
.example(
4753
'$0',
@@ -67,18 +73,28 @@ const argv = yargs
6773
)
6874
}
6975
)
70-
.epilogue(
71-
'For help or more information, ping me on Twitter ' +
72-
'at https://twitter.com/agentofuser'
73-
)
7476
.help()
75-
.alias('h', 'help').argv
77+
.alias('h', 'help')
7678

7779
async function main() {
80+
const processArgv = process.argv.slice(1)
81+
const yargsParse = new Promise((resolve, reject) => {
82+
parser.parse(processArgv, (err, argv, output) => {
83+
if (err) {
84+
reject(err)
85+
} else {
86+
resolve({ argv, output })
87+
}
88+
})
89+
})
90+
91+
const { argv, output } = await yargsParse
92+
7893
const deployOptions = {
7994
publicDirPath: argv.path,
8095
copyPublicGatewayUrlToClipboard: !argv.noClipboard,
8196
open: !argv.O,
97+
port: argv.port,
8298
remotePinners: argv.p,
8399
dnsProviders: argv.d,
84100
siteDomain: argv.siteDomain,
@@ -94,7 +110,19 @@ async function main() {
94110
},
95111
}
96112

97-
await deploy(deployOptions)
113+
process.stdout.write(output)
114+
115+
if (argv.h) {
116+
// Had to do this because couldn't get yargs#epilogue() to work
117+
process.stdout.write(`
118+
For help or more information, ping me at
119+
https://twitter.com/${chalk.whiteBright('agentofuser')}
120+
`)
121+
} else {
122+
await deploy(deployOptions)
123+
}
98124
}
99125

100-
main()
126+
;(async () => {
127+
await main()
128+
})()

0 commit comments

Comments
 (0)