-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add yarn ipfs command to deploy on IPFS #1030
Open
portdeveloper
wants to merge
8
commits into
main
Choose a base branch
from
feat/ipfs-manual
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3da1015
Add config for yarn ipfs
portdeveloper 5fef988
Show errors in yarn ipfs
portdeveloper 470f9c1
Fix formatting in next.config.js
portdeveloper 1547922
Update deploy-ipfs to use nifty ink
portdeveloper 6026051
Change deploy-ipfs.js to deploy-ipfs.mjs
portdeveloper f7cbc7c
Remove unused stuff from yarn.lock
portdeveloper 0c139a0
Fix build flag not getting detected
portdeveloper 8f06d03
Merge branch 'main' into feat/ipfs-manual
portdeveloper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
"test": "yarn hardhat:test", | ||
"vercel": "yarn workspace @se-2/nextjs vercel", | ||
"vercel:yolo": "yarn workspace @se-2/nextjs vercel:yolo", | ||
"ipfs": "yarn workspace @se-2/nextjs ipfs", | ||
"verify": "yarn hardhat:verify" | ||
}, | ||
"packageManager": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { exec } from "child_process"; | ||
import { dirname, join } from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { promisify } from "util"; | ||
|
||
const execAsync = promisify(exec); | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
async function checkIpfsDaemon() { | ||
try { | ||
await execAsync("ipfs --version"); | ||
// Check if daemon is running and has peers | ||
const { stdout } = await execAsync("ipfs swarm peers"); | ||
const peerCount = stdout.split("\n").filter(Boolean).length; | ||
|
||
if (peerCount < 1) { | ||
console.log("⚠️ Warning: Your IPFS node has no peers. Content might not be accessible immediately."); | ||
console.log("Waiting for peers to connect..."); | ||
// Wait for peers to connect | ||
await new Promise(resolve => setTimeout(resolve, 10000)); | ||
const { stdout: newStdout } = await execAsync("ipfs swarm peers"); | ||
const newPeerCount = newStdout.split("\n").filter(Boolean).length; | ||
if (newPeerCount < 1) { | ||
console.log("Still no peers connected. You might want to:"); | ||
console.log("1. Check your internet connection"); | ||
console.log("2. Ensure your IPFS daemon is not behind a firewall"); | ||
console.log("3. Try running 'ipfs daemon --enable-pubsub-experiment' for better connectivity"); | ||
} else { | ||
console.log(`✓ Connected to ${newPeerCount} peers`); | ||
} | ||
} else { | ||
console.log(`✓ Connected to ${peerCount} peers`); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
console.error("❌ IPFS is not installed or daemon is not running."); | ||
console.log("Please install IPFS and start the daemon:"); | ||
console.log("1. Install IPFS: https://docs.ipfs.tech/install/"); | ||
console.log("2. Start the daemon: ipfs daemon"); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
async function addDirectoryToIpfs(path) { | ||
console.log("📦 Adding directory to IPFS..."); | ||
|
||
try { | ||
// Add the entire directory to IPFS and get the hash | ||
const { stdout } = await execAsync(`ipfs add -r -Q "${path}"`); | ||
const cid = stdout.trim(); | ||
|
||
// Announce the content to the network | ||
try { | ||
await execAsync(`ipfs dht provide ${cid}`); | ||
console.log("✓ Announced content to the IPFS network"); | ||
} catch (error) { | ||
console.log(error); | ||
console.log("⚠️ Warning: Could not announce content to the network. Content might take longer to be available."); | ||
} | ||
|
||
return cid; | ||
} catch (error) { | ||
console.error("Error adding directory to IPFS:", error); | ||
throw error; | ||
} | ||
} | ||
|
||
async function main() { | ||
// First check if IPFS is installed and running | ||
await checkIpfsDaemon(); | ||
|
||
// Get the path to the out directory | ||
const outDir = join(__dirname, "..", "out"); | ||
|
||
console.log("🚀 Uploading to IPFS..."); | ||
const cid = await addDirectoryToIpfs(outDir); | ||
|
||
// Give the network some time to propagate the content | ||
console.log("\n⏳ Waiting for network propagation..."); | ||
await new Promise(resolve => setTimeout(resolve, 5000)); | ||
|
||
console.log("\n✨ Upload complete! Your site is now available at:"); | ||
console.log(`🔗 IPFS Gateway: https://ipfs.io/ipfs/${cid}`); | ||
console.log("\n💡 To ensure your site stays available:"); | ||
console.log("1. Keep your IPFS daemon running"); | ||
console.log("2. Pin the CID on other nodes: ipfs pin add " + cid); | ||
console.log("\n💡 If the gateway times out, you can:"); | ||
console.log("1. Wait a few minutes and try again"); | ||
console.log("2. Install the IPFS Companion browser extension"); | ||
} | ||
|
||
main().catch(err => { | ||
console.error("Error uploading to IPFS:", err); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to avoid daemon? For example using https://web3.storage/docs/w3up-client/ or https://docs.storacha.network/w3up-client/ ? Asking without trying, but probably it simplifies DX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is a valid concern, but I wanted to keep everything manual just for the sake of showing that it can be done this way.