mirror of
https://github.com/amark/gun.git
synced 2025-11-23 22:15:55 +00:00
Merge branch 'master' of http://github.com/amark/gun
This commit is contained in:
commit
8cd8c4f6fb
49
.github/workflows/ci.yml
vendored
49
.github/workflows/ci.yml
vendored
@ -1,20 +1,23 @@
|
||||
name: ci
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
env:
|
||||
project: 'release-node'
|
||||
project: 'gun'
|
||||
|
||||
jobs:
|
||||
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [14.x] # [12.x, 14.x]
|
||||
os: [ubuntu-latest] #, macos-latest, windows-latest]
|
||||
node-version: [ 14.x ]
|
||||
os: [ ubuntu-latest ]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
||||
# checkout the code
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
@ -22,11 +25,13 @@ jobs:
|
||||
- name: Version
|
||||
uses: tcurdt/action-verify-version-npm@master
|
||||
|
||||
# setup the node version
|
||||
- name: Setup Node ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
# cache node_modules if we can
|
||||
- name: Cache
|
||||
id: cache-modules
|
||||
uses: actions/cache@v2
|
||||
@ -34,42 +39,24 @@ jobs:
|
||||
path: node_modules
|
||||
key: ${{ matrix.node-version }}-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
|
||||
|
||||
# ottherweise run install
|
||||
- name: Install
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: npm install
|
||||
|
||||
# run tests
|
||||
- name: Test
|
||||
run: npm test
|
||||
|
||||
# create release artifacts to publish as github release
|
||||
# - name: Upload
|
||||
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
||||
# uses: actions/upload-artifact@v2
|
||||
# with:
|
||||
# name: ${{ env.project }}_${{ matrix.os }}_${{ matrix.node-version }}
|
||||
# path: |
|
||||
# !.git
|
||||
# !.github
|
||||
# !node_modules
|
||||
# .
|
||||
|
||||
# only create a release for tags named 'v*'
|
||||
release:
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
||||
needs: [test]
|
||||
needs: [ test ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
# - name: Download
|
||||
# uses: actions/download-artifact@v2
|
||||
# with:
|
||||
# path: artifacts
|
||||
# - name: Archives
|
||||
# run: find artifacts -mindepth 1 -maxdepth 1 -exec tar -C {} -cvzf {}.tgz . \;
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
# with:
|
||||
# files: |
|
||||
# artifacts/*.tgz
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||
# create github release (which triggers the release workflows)
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||
|
||||
17
.github/workflows/cleanup.yml
vendored
17
.github/workflows/cleanup.yml
vendored
@ -1,17 +0,0 @@
|
||||
name: cleanup
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '1 1 * * 1' # once a week clean out old artifacts
|
||||
|
||||
jobs:
|
||||
|
||||
expire:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Expire Artifacts
|
||||
uses: kolpav/purge-artifacts-action@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
expire-in: 1hour
|
||||
@ -2,10 +2,10 @@ name: dockerhub
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
types: [ published ]
|
||||
|
||||
env:
|
||||
project: 'release-node'
|
||||
project: 'gun'
|
||||
|
||||
jobs:
|
||||
|
||||
@ -26,10 +26,19 @@ jobs:
|
||||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
||||
|
||||
- name: Tag
|
||||
- name: Build
|
||||
run: |
|
||||
docker tag ${{ env.project }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.project }}:${GITHUB_REF/refs\/tags\/v/}
|
||||
docker tag ${{ env.project }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.project }}:latest
|
||||
echo "SHA=$GITHUB_SHA"
|
||||
docker build --build-arg \
|
||||
SHA=$GITHUB_SHA \
|
||||
BUILD_DATE=$(date +'%Y-%m-%d') \
|
||||
VCS_REF=${GITHUB_REF/refs\/tags\/v/} \
|
||||
VCS_URL=$GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} \
|
||||
VERSION=${GITHUB_REF/refs\/tags\/v/} \
|
||||
--label "sha=$GITHUB_SHA" \
|
||||
--tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.project }}:${GITHUB_REF/refs\/tags\/v/} \
|
||||
--tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.project }}:latest \
|
||||
.
|
||||
|
||||
- name: Push
|
||||
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.project }}
|
||||
@ -2,7 +2,7 @@ name: npm
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
types: [ published ]
|
||||
|
||||
jobs:
|
||||
|
||||
29
Dockerfile
29
Dockerfile
@ -1,5 +1,15 @@
|
||||
FROM alpine:latest
|
||||
# Build-time metadata as defined at http://label-schema.org
|
||||
# install packages
|
||||
FROM node:14-alpine as builder
|
||||
RUN mkdir /work
|
||||
WORKDIR /work
|
||||
RUN apk add --no-cache alpine-sdk python
|
||||
COPY package*.json ./
|
||||
RUN mkdir -p node_modules
|
||||
RUN npm ci --only=production
|
||||
|
||||
# fresh image without dev packages
|
||||
FROM node:14-alpine
|
||||
# build-time metadata as defined at http://label-schema.org
|
||||
ARG BUILD_DATE
|
||||
ARG VCS_REF
|
||||
ARG VCS_URL
|
||||
@ -12,15 +22,14 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
|
||||
org.label-schema.vendor="The Gun Database Team" \
|
||||
org.label-schema.version=$VERSION \
|
||||
org.label-schema.schema-version="1.0"
|
||||
# org.label-schema.description="Let it be pulled from Readme.md..." \
|
||||
WORKDIR /app
|
||||
ARG SHA
|
||||
RUN mkdir /work
|
||||
WORKDIR /work
|
||||
COPY --from=builder /work/node_modules ./node_modules
|
||||
RUN npm rebuild -q
|
||||
ADD . .
|
||||
ENV NPM_CONFIG_LOGLEVEL warn
|
||||
RUN apk update && apk upgrade \
|
||||
&& apk add --no-cache ca-certificates nodejs npm \
|
||||
&& apk add --no-cache --virtual .build-dependencies python2 make g++ git \
|
||||
&& npm install --production=false \
|
||||
&& apk del .build-dependencies && rm -rf /var/cache/* /tmp/npm*
|
||||
RUN echo "{ \"sha\": \"$SHA\" }" > version.json
|
||||
RUN cat version.json
|
||||
EXPOSE 8080
|
||||
EXPOSE 8765
|
||||
CMD ["npm","start"]
|
||||
|
||||
37
README.md
37
README.md
@ -5,11 +5,15 @@
|
||||
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Famark%2Fgun?ref=badge_shield)
|
||||
[](http://chat.gun.eco)
|
||||
|
||||
**GUN** is an _ecosystem_ of tools that let you build [community run](https://www.nbcnews.com/tech/tech-news/these-technologists-think-internet-broken-so-they-re-building-another-n1030136) and [encrypted applications](https://gun.eco/docs/Cartoon-Cryptography).
|
||||
**GUN** is an [ecosystem](https://gun.eco/docs/Ecosystem) of **tools** that let you build [community run](https://www.nbcnews.com/tech/tech-news/these-technologists-think-internet-broken-so-they-re-building-another-n1030136) and [encrypted applications](https://gun.eco/docs/Cartoon-Cryptography) - like an Open Source Firebase or a Decentralized Dropbox.
|
||||
|
||||
Currently, [Internet Archive](https://news.ycombinator.com/item?id=17685682) and [HackerNoon](https://www.coindesk.com/hacker-noon-is-storing-content-on-a-blockchain-after-ditching-medium) run GUN in production.
|
||||
The [Internet Archive](https://news.ycombinator.com/item?id=17685682), [HackerNoon](https://www.coindesk.com/hacker-noon-is-storing-content-on-a-blockchain-after-ditching-medium), and [100s of other apps](https://github.com/amark/gun/wiki/awesome-gun) run GUN in-production. GUN is also part of [Twitter's Bluesky](https://blueskycommunity.net/) initiative!
|
||||
|
||||
Decentralized alternatives to [Zoom](https://www.zdnet.com/article/era-hatches-meething-an-open-source-browser-based-video-conferencing-system/), [Reddit](https://notabug.io/t/whatever/comments/36588a16b9008da4e3f15663c2225e949eca4a15/gpu-bot-test), [Slack](https://iris.to/), [YouTube](https://d.tube/), [Wikipedia](https://news.ycombinator.com/item?id=17685682), etc. have already pushed terabytes of daily P2P traffic on GUN. We are a [friendly community](http://chat.gun.eco/) creating a [free fun future for freedom](https://youtu.be/1HJdrBk3BlE):
|
||||
+ Multiplayer by default with realtime p2p state synchronization!
|
||||
+ Graph data let's you use key/value, tables, documents, videos, & more!
|
||||
+ Local-first, offline, and decentralized with end-to-end encryption.
|
||||
|
||||
Decentralized alternatives to [Zoom](https://www.zdnet.com/article/era-hatches-meething-an-open-source-browser-based-video-conferencing-system/), [Reddit](https://notabug.io/t/whatever/comments/36588a16b9008da4e3f15663c2225e949eca4a15/gpu-bot-test), [Instagram](https://iris.to/), [Slack](https://iris.to/), [YouTube](https://d.tube/), [Stripe](https://twitter.com/marknadal/status/1422717427427647489), [Wikipedia](https://news.ycombinator.com/item?id=17685682), Facebook [Horizon](https://twitter.com/marknadal/status/1424476179189305347) and more have already pushed terabytes of daily P2P traffic on GUN. We are a [friendly community](http://chat.gun.eco/) creating a [free fun future for freedom](https://youtu.be/1HJdrBk3BlE):
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
@ -29,15 +33,10 @@ Decentralized alternatives to [Zoom](https://www.zdnet.com/article/era-hatches-m
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
The ecosystem is one nice stack of technologies that looks like this: (names -> use case)
|
||||
|
||||
<div><img width="48%" src="https://gun.eco/see/stack.png"/>
|
||||
<img width="48%" align="right" src="https://gun.eco/see/layers.png"/></div>
|
||||
|
||||
For now, it is best to start with GUN and _just use it_ to learn the basics, since it is _**so easy**_: (**or** want to read more? Skip ahead to the "[What is GUN?](#what-is-gun)" section.)
|
||||
|
||||
## Quickstart
|
||||
|
||||
GUN is *super easy* to get started with:
|
||||
|
||||
- Try the [interactive tutorial](https://gun.eco/docs/Todo-Dapp) in the browser (**5min** ~ average developer).
|
||||
- Or `npm install gun` and run the examples with `cd node_modules/gun && npm start` (**5min** ~ average developer).
|
||||
|
||||
@ -80,7 +79,7 @@ gun.get('mark').get('boss').get('name').once(function(data, key){
|
||||
|
||||
// traverse a graph of circular references!
|
||||
gun.get('mark').get('boss').get('slave').once(function(data, key){
|
||||
console.log("Mark is the slave!", data);
|
||||
console.log("Mark is the cat's slave!", data);
|
||||
});
|
||||
|
||||
// add both of them to a table!
|
||||
@ -93,14 +92,19 @@ gun.get('list').map().once(function(data, key){
|
||||
});
|
||||
|
||||
// live update the table!
|
||||
gun.get('list').set({type: "cucumber", goal: "scare cat"});
|
||||
gun.get('list').set({type: "cucumber", goal: "jumping cat"});
|
||||
```
|
||||
|
||||
Want to keep building more? **Jump to [THE DOCUMENTATION](#documentation)!**
|
||||
|
||||
# What is GUN?
|
||||
# About
|
||||
|
||||
First & foremost, GUN is **a community of the nicest and most helpful people** out there. So [I want to invite you](https://gitter.im/amark/gun) to come tell us about what **you** are working on & wanting to build (new or old school alike! Just be nice as well.) and ask us your questions directly. :)
|
||||
First & foremost, GUN is **a community of the nicest and most helpful people** out there. So [I want to invite you](http://chat.gun.eco) to come tell us about what **you** are working on & wanting to build (new or old school alike! Just be nice as well.) and ask us your questions directly. :)
|
||||
|
||||
The GUN ecosystem stack is a collection of independent and modular tools covering everything from [CRDT](https://crdt.tech/) [conflict resolution](https://gun.eco/distributed/matters.html), [cryptographic security](https://gun.eco/docs/Cartoon-Cryptography) & [encryption](https://gun.eco/docs/SEA), [radix storage serialization](https://gun.eco/docs/RAD), [mesh networking](https://gun.eco/docs/DAM) & [routing algorithms](https://gun.eco/docs/Routing), to distributed systems [correctness & load testing](https://github.com/gundb/panic-server), CPU scheduled [JSON parser](https://github.com/amark/gun/blob/master/lib/yson.js) to prevent UI lag, and more!
|
||||
|
||||
<div><img width="48%" src="https://gun.eco/see/stack.png"/>
|
||||
<img width="48%" align="right" src="https://gun.eco/see/layers.png"/></div>
|
||||
|
||||
On that note, let's get some official shout outs covered first:
|
||||
|
||||
@ -134,13 +138,14 @@ Thanks to:
|
||||
<a href="http://github.com/bmatusiak">Bradley Matusiak</a>,
|
||||
<a href="https://github.com/sjuxax">Jeff Cook</a>,
|
||||
<a href="https://github.com/nmauersberg">Nico</a>,
|
||||
<a href="https://github.com/ajartille">Aaron Artille</a>
|
||||
<a href="https://github.com/ajartille">Aaron Artille</a>,
|
||||
<a href="https://github.com/timjrobinson">Tim Robinson</a>
|
||||
</p>
|
||||
|
||||
- Join others in sponsoring code: https://www.patreon.com/gunDB !
|
||||
- Ask questions: http://stackoverflow.com/questions/tagged/gun ?
|
||||
- Found a bug? Report at: https://github.com/amark/gun/issues ;
|
||||
- **Need help**? Chat with us: https://gitter.im/amark/gun .
|
||||
- **Need help**? Chat with us: http://chat.gun.eco .
|
||||
|
||||
### History
|
||||
|
||||
|
||||
89
lib/hub.js
89
lib/hub.js
@ -15,37 +15,94 @@ try { chokidar = require('chokidar') } catch (error) {
|
||||
* @param {Object} options - https://gun.eco/docs/hub.js#options
|
||||
*/
|
||||
function watch(what, options) {
|
||||
options = options || { msg: true }
|
||||
options = options ?? { msg: true, hubignore: false }
|
||||
|
||||
let modifiedPath = (options.file || "");
|
||||
options.msg = options.msg ?? true;
|
||||
options.hubignore = options.hubignore ?? false;
|
||||
|
||||
let modifiedPath = (options.file ?? "");
|
||||
|
||||
let watcher;
|
||||
try {
|
||||
// Set up the file watcher.
|
||||
watcher = chokidar.watch(what, {
|
||||
ignored: /(^|[\/\\])\../, // ignore dotfiles
|
||||
persistent: true
|
||||
});
|
||||
|
||||
if (options.hubignore) {
|
||||
|
||||
watcher = chokidar.watch(what, {
|
||||
persistent: true
|
||||
});
|
||||
|
||||
} else if (!options.hubignore) {
|
||||
|
||||
watcher = chokidar.watch(what, {
|
||||
ignored: /(^|[\/\\])\../, // ignore dotfiles
|
||||
persistent: true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
const log = console.log.bind(console);
|
||||
|
||||
let hubignore;
|
||||
|
||||
// Handle events !
|
||||
watcher
|
||||
.on('add', async function(path) {
|
||||
if (options.msg) log(`File ${path} has been added`);
|
||||
gun.get('hub').get(modifiedPath + '/' + path).put(fs.readFileSync(path, 'utf-8'))
|
||||
|
||||
if (options.hubignore && path.includes('.hubignore')) {
|
||||
|
||||
hubignore = fs.readFileSync(what + '/.hubignore', 'utf-8');
|
||||
|
||||
} else if (!path.includes('.hubignore') && !hubignore?.includes(path.substring(path.lastIndexOf("/") + 1))) {
|
||||
|
||||
if (options.msg) log(`File ${path} has been added`);
|
||||
|
||||
if(path[path.search(/^./gm)] === "/" || ".") {
|
||||
gun.get('hub').get(modifiedPath + path).put(fs.readFileSync(path, 'utf-8'))
|
||||
} else {
|
||||
gun.get('hub').get(modifiedPath + '/' + path).put(fs.readFileSync(path, 'utf-8'))
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(options.msg) log(`The addition of ${path} has been ignored !`)
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
.on('change', async function(path) {
|
||||
|
||||
if (options.msg) log(`File ${path} has been changed`);
|
||||
gun.get('hub').get(modifiedPath + '/' + path).put(fs.readFileSync(path, 'utf-8'))
|
||||
|
||||
if (options.hubignore && path.includes('.hubignore')) {
|
||||
|
||||
hubignore = fs.readFileSync(what + '/.hubignore', 'utf-8');
|
||||
|
||||
} else if (!path.includes('.hubignore') && !hubignore?.includes(path.substring(path.lastIndexOf('/') + 1))) {
|
||||
|
||||
if (options.msg) log(`File ${path} has been changed`);
|
||||
gun.get('hub').get(modifiedPath + '/' + path).put(fs.readFileSync(path, 'utf-8'))
|
||||
|
||||
} else {
|
||||
|
||||
if(options.msg) log(`The changes on ${path} has been ignored.`)
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
.on('unlink', async function (path) {
|
||||
|
||||
if(options.msg) log(`File ${path} has been removed`);
|
||||
gun.get('hub').get(modifiedPath + '/' + path).put(null)
|
||||
.on('unlink', async function (path) {
|
||||
|
||||
if (options.hubignore && path.includes('.hubignore')) {
|
||||
|
||||
hubignore = fs.readFileSync(what + '/.hubignore', 'utf-8');
|
||||
|
||||
} else if (!path.includes('.hubignore') && !hubignore?.includes(path.substring(path.lastIndexOf('/') + 1))) {
|
||||
|
||||
if(options.msg) log(`File ${path} has been removed`);
|
||||
gun.get('hub').get(modifiedPath + '/' + path).put(null)
|
||||
|
||||
} else {
|
||||
|
||||
if(options.msg) log(`The deletion of ${path} has been ignored!`)
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
if (options.msg) {
|
||||
|
||||
1
test/hub/.hubignore
Normal file
1
test/hub/.hubignore
Normal file
@ -0,0 +1 @@
|
||||
/whatever/aws-key.txt
|
||||
9
test/hub/hub-test.js
Normal file
9
test/hub/hub-test.js
Normal file
@ -0,0 +1,9 @@
|
||||
// const Gun = require('../..');
|
||||
// const gun = Gun();
|
||||
|
||||
// gun.get('hub').on(data => {
|
||||
// console.log(data['/home/noctisatrae/gun/test/hub/index.html'])
|
||||
// })
|
||||
|
||||
const hub = require('../../lib/hub');
|
||||
hub.watch('/home/noctisatrae/gun/test/hub', {msg: true, hubignore: true})
|
||||
12
test/hub/index.html
Normal file
12
test/hub/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
2
test/hub/whatever/aws-key.txt
Normal file
2
test/hub/whatever/aws-key.txt
Normal file
@ -0,0 +1,2 @@
|
||||
I'M A SUPER SECRET KEY WHICH SHALL NOT BE LEAKED
|
||||
FOR YOUR OWN SAKE.
|
||||
Loading…
x
Reference in New Issue
Block a user