From 0eec835c315a96be4ece75f7f7e564e1f36c9205 Mon Sep 17 00:00:00 2001 From: Torsten Curdt Date: Mon, 30 Aug 2021 23:26:44 +0200 Subject: [PATCH 1/4] cleaning up and improving the CI/CD pipeline (#1122) * no artifacts, not required * renamed * cleanup and comments * pass build args * two-step docker build --- .github/workflows/ci.yml | 49 +++++++------------ .github/workflows/cleanup.yml | 17 ------- .../{dockerhub.yml => release-dockerhub.yml} | 19 +++++-- .../workflows/{npm.yml => release-npm.yml} | 2 +- Dockerfile | 29 +++++++---- 5 files changed, 52 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/cleanup.yml rename .github/workflows/{dockerhub.yml => release-dockerhub.yml} (50%) rename .github/workflows/{npm.yml => release-npm.yml} (93%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index befb97d2..f3b586f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml deleted file mode 100644 index 067e221e..00000000 --- a/.github/workflows/cleanup.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/release-dockerhub.yml similarity index 50% rename from .github/workflows/dockerhub.yml rename to .github/workflows/release-dockerhub.yml index 17eb638a..39dd96d8 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/release-dockerhub.yml @@ -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 }} diff --git a/.github/workflows/npm.yml b/.github/workflows/release-npm.yml similarity index 93% rename from .github/workflows/npm.yml rename to .github/workflows/release-npm.yml index 6af0892d..d66cbed6 100644 --- a/.github/workflows/npm.yml +++ b/.github/workflows/release-npm.yml @@ -2,7 +2,7 @@ name: npm on: release: - types: [published] + types: [ published ] jobs: diff --git a/Dockerfile b/Dockerfile index c1d6fd9c..564dee47 100644 --- a/Dockerfile +++ b/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"] From 084e2907daaa5c3d59b1d40fb5b0e041b178ac71 Mon Sep 17 00:00:00 2001 From: Hector <46224745+noctisatrae@users.noreply.github.com> Date: Mon, 30 Aug 2021 23:29:55 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8E=89=20Introducing=20a=20new=20feat?= =?UTF-8?q?ure=20!=20(#1121)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ๐ŸŽ‰ .hubignore is ready ! * ๐Ÿงช Add tests for hub.js ! --- lib/hub.js | 89 ++++++++++++++++++++++++++++------- test/hub/.hubignore | 1 + test/hub/hub-test.js | 9 ++++ test/hub/index.html | 12 +++++ test/hub/whatever/aws-key.txt | 2 + 5 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 test/hub/.hubignore create mode 100644 test/hub/hub-test.js create mode 100644 test/hub/index.html create mode 100644 test/hub/whatever/aws-key.txt diff --git a/lib/hub.js b/lib/hub.js index 9186f02e..58ff6adb 100644 --- a/lib/hub.js +++ b/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) { diff --git a/test/hub/.hubignore b/test/hub/.hubignore new file mode 100644 index 00000000..44cd6488 --- /dev/null +++ b/test/hub/.hubignore @@ -0,0 +1 @@ +/whatever/aws-key.txt \ No newline at end of file diff --git a/test/hub/hub-test.js b/test/hub/hub-test.js new file mode 100644 index 00000000..9687b92a --- /dev/null +++ b/test/hub/hub-test.js @@ -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}) \ No newline at end of file diff --git a/test/hub/index.html b/test/hub/index.html new file mode 100644 index 00000000..56efbdba --- /dev/null +++ b/test/hub/index.html @@ -0,0 +1,12 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/test/hub/whatever/aws-key.txt b/test/hub/whatever/aws-key.txt new file mode 100644 index 00000000..da508084 --- /dev/null +++ b/test/hub/whatever/aws-key.txt @@ -0,0 +1,2 @@ +I'M A SUPER SECRET KEY WHICH SHALL NOT BE LEAKED +FOR YOUR OWN SAKE. \ No newline at end of file From bdf4717d2d219c59af8c61d90d8b3c2a6b6c9900 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Mon, 30 Aug 2021 21:05:29 -0700 Subject: [PATCH 3/4] Thanks @timjrobinson ! :) --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22259c30..a620e483 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,8 @@ Thanks to: Bradley Matusiak, Jeff Cook, Nico, -Aaron Artille +Aaron Artille, +Tim Robinson

- Join others in sponsoring code: https://www.patreon.com/gunDB ! From ae0ffadc293704749db719cc412b5a324ebfbaf3 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Mon, 30 Aug 2021 23:54:15 -0700 Subject: [PATCH 4/4] Update README.md --- README.md | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a620e483..7d5b79e1 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,15 @@ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Famark%2Fgun.svg?size=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Famark%2Fgun?ref=badge_shield) [![Gitter](https://img.shields.io/gitter/room/amark/gun.js.svg)](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): @@ -29,15 +33,10 @@ Decentralized alternatives to [Zoom](https://www.zdnet.com/article/era-hatches-m
-The ecosystem is one nice stack of technologies that looks like this: (names -> use case) - -
-
- -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! + +
+
On that note, let's get some official shout outs covered first: @@ -141,7 +145,7 @@ Thanks to: - 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