Skip to content

Commit af38550

Browse files
authored
Merge pull request #10 from scramjetorg/fix/make-all-samples-bundle
Make scripts for all samples
2 parents c7eccd2 + 66841a5 commit af38550

File tree

135 files changed

+16687
-5437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+16687
-5437
lines changed

.github/workflows/node.js.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/refapps-build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Make a refapps release with compiled package archives
2+
3+
on: pull_request
4+
5+
jobs:
6+
build-only:
7+
name: Build refapps
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Setup Nodejs v16
14+
uses: actions/setup-node@v2
15+
with:
16+
node-version: 16
17+
18+
- name: Install dependencies
19+
run: npm install
20+
21+
- name: Build sample sequences
22+
run: npm run build
23+
24+
- name: Pack sample sequences
25+
run: npm run pack
26+
27+
- name: List packages
28+
run: ls -la dist/

.github/workflows/refapps-release.yml

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,17 @@ jobs:
1919
node-version: 16
2020

2121
- name: Install dependencies
22-
run: yarn install
22+
run: npm install
2323

2424
- name: Build reference apps
25-
run: yarn build:refapps
26-
27-
- name: Prefix python packages to prevent name clash
28-
run: |
29-
cd python;
30-
for pkg in *.tar.gz; do
31-
mv $pkg python-$pkg;
32-
done
33-
34-
- name: Prefix typescript packages to prevent name clash
35-
run: |
36-
cd typescript;
37-
for pkg in *.tar.gz; do
38-
mv $pkg typescript-$pkg;
39-
done
40-
41-
- name: Prefix javascript packages to prevent name clash
42-
run: |
43-
cd javascript;
44-
for pkg in *.tar.gz; do
45-
mv $pkg javascript-$pkg;
46-
done
25+
run: npm run build
26+
27+
- name: Build reference apps
28+
run: npm run pack
4729

4830
- name: Create a release and upload artifacts
4931
run: >
5032
gh release create ${{ github.ref }}
51-
javascript/*.tar.gz
52-
typescript/*.tar.gz
53-
python/*.tar.gz
33+
dist/*.tar.gz
5434
env:
5535
GITHUB_TOKEN: ${{ secrets.SCRAMJET_BOT_TOKEN }}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 scramjet.org
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Samples
2+
3+
Try out our samples prepared some samples for you. We differentiated them according to the language in which they were written.
4+
5+
Every sample contains a short readme with a guidance describing the procedure for running the example. The execution will be performed from the command line using our CLI, which full description and documentation you will find [here](https://docs.scramjet.org/platform/cli-reference).
6+
7+
## Python samples
8+
9+
Python packages work in a similar way to all the others. They need to pack the dependencies and carry over anything they may need to run the program. They also need a `package.json` file.
10+
11+
- [kafka-transformer](python/kafka-transformer/) - Sequence sending data to any Kafka topic
12+
- [kafka-consumer](python/kafka-consumer/) - Sequence fetching data from any Kafka topic
13+
- [voice-recognition](python/voice-recognition) - a sample Sequence that performs voice recognition in real time.
14+
15+
## JavaScript samples
16+
17+
JavaScript packages are pretty straight forward in use. After the dependency installation is performed inside the Sequence package it is ready to be compressed and sent to STH.
18+
19+
- [hello](javascript/hello) - Sequence that modifies incoming stream of strings by saying "Hello".
20+
- [hello-snowman](javascript/hello-snowman) - Sequence that reads incoming stream, and modifies it by adding a text message according to the incoming data.
21+
- [simple-counter-js](javascript/simple-counter-js) - Sequence, that counts to 1000, and logs the number in one-second intervals.
22+
- [test-output](javascript/test-output) - Sequence that simply writes random values to the output stream.
23+
- [json-url-stdout](javascript/json-url-stdout/) - Make a real-time JSON API scraper (stdout version)
24+
- [json-url-output](javascript/json-url-output/) - Make a real-time JSON API scraper (output version)
25+
26+
## TypeScript samples
27+
28+
TypeScript compiles to JavaScript. It means that TypeScript packages except dependency installation also need to be compiled. We added a `build` and `postbuild` scripts to every `package.json` in TypeScript packages, which are responsible for compiling files into a `dist` folder and coping `package.json` file into the `dist` folder. In effect, it is the `dist` folder, that becomes the Sequence package, ready to be compressed and sent to STH.
29+
30+
- [crypto-prices](typescript/crypto-prices) - Sequence that keeps printing current crypto prices for a provided pair of currencies every 3s.
31+
- [slack-write](typescript/slack-write/) - Write incoming data to a slack channel
32+
- [slack-read](typescript/slack-read/) - Read data from Slack
33+
- [discord-write](typescript/discord-write/) - Write to Discord
34+
- [discord-read](typescript/discord-read/) - Read from Discord
35+
- [mediawiki](typescript/mediawiki) - Sequence that keeps printing mediawiki event stream.
36+
- [rss](typescript/rss) - Sequence that gets a list of RSS and then retrieves each feed and passes links to scraper.
37+
- [write-to-database](typescript/write-to-database/) - Write incoming data to a database table
38+
- [scraping](typescript/scraping) - Sequence that scrapes web pages.
39+
- [stack-overflow](typescript/stack-overflow) - Sequence that gets a number of changes in Stack Overflow tag count.
40+
- [transform-string-stream](typescript/transform-string-stream) - Sequence that modifies incoming stream of strings by adding a prefix and a suffix.
41+
- [read-targz-stats](typescript/read-targz-stats/) - Stream through tar.gz file and output stats
42+
- [send-to-github](typescript/send-to-github/) - Write incoming data to a file on github
43+
- [linkedin](typescript/linkedin/) - Enrich csv data with Linkedin via RapidAPI
44+
- [hexdump](typescript/hexdump/) -Sequence returns input in hex format.
45+
46+
## Guides and complex examples
47+
48+
- [kafka-setup](guides/kafka-setup/) - how to set up a kafka instance and consume data from it with Scramjet Cloud Platform
49+
- [discord-slack-connection](guides/discord-slack-connection/) - how to interconnect discord and slack with Scramjet Cloud Platform
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Discord to Slack (and vice versa) Connection
2+
3+
___
4+
5+
### The video that illustrates the execution of the sample is on our [YouTube](https://www.youtube.com/channel/UChgTmKeuAsKj8kDnylkmP6Q) channel [How to Connect Discord and Slack in 4 minutes](https://www.youtube.com/watch?v=y2L1f-f-wLM&t=1s).
6+
7+
___
8+
9+
> 💡 **Please note that the sample below requires some previous installations before you start running it, you will find them [here](../../README.md#3-install-scramjet-transform-hub).**
10+
11+
In this project you will find 4 STH Sequences:
12+
13+
* [discord-read](../../typescript/discord-read/)
14+
* [discord-write](../../typescript/discord-write/)
15+
* [slack-read](../../typescript/slack-read/)
16+
* [slack-write](../../typescript/slack-write/)
17+
18+
You must run at least two (discord-read, slack write or discord-write, slack-read) in order to get one directional communication or all four for bi-directional communication.
19+
20+
Each Sequence either reads or writes to specified application respectively and uses `const TOPIC = ...` topic to exchange data between applications. You need two topics for bi-directional communication.
21+
22+
You can add your own topics at invoke time
23+
24+
## TODO
25+
26+
As there is no way to map message IDs between the two applications, threads are not supported.
27+
28+
In order to get this working, Sequences must keep a track of posted and written IDs.

python/kaffka-setup/README.md renamed to guides/kafka-setup/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Sequences fetching and sending data from any Kafka server
22

3-
Easy example of usage Kaffka with Scramjet platform. As the part of this PR, three different directories are created for organizational purposes. You need also 3 different terminals to check the whole.
3+
Easy example of usage Kafka with Scramjet platform. As the part of this PR, three different directories are created for organizational purposes. You need also 3 different terminals to check the whole.
44

55
On first terminal:
66

7-
setup kaffka in docker container
7+
setup kafka in docker container
88

99
```bash
10-
cd kaffka-setup
10+
cd docs/kafka-setup
1111
docker-compose up -d
1212
```
1313

@@ -17,34 +17,34 @@ create 'scramjet' topic
1717
docker-compose exec kafka kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic scramjet
1818
```
1919

20-
run watcher for 'scramjet' topic, you will see here logs directly from kaffka
20+
run watcher for 'scramjet' topic, you will see here logs directly from kafka
2121

2222
```bash
2323
docker-compose exec kafka kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic scramjet --from-beginning
2424
```
2525

26-
On second terminal run STH
26+
On a second terminal run STH
2727

2828
```bash
2929
DEVELOPMENT=1 sth --runtime-adapter=process
3030
```
3131

32-
On last terminal you need to make few things. First you need to build our two samples. You can run command visible below in main directory of platform-samples project to build all samples, or you can run it directly from the kaffka-transformer and kaffka-consumer directories.
32+
On another terminal you need to make few things. First you need to build our two samples. You can run command visible below in main directory of platform-samples project to build all samples, or you can run it directly from the kafka-transformer and kafka-consumer directories.
3333

3434
```bash
35-
yarn build:refapps
35+
npm run build
3636
```
3737

3838
Once you've built these packages, you need to run consumer Sequence first. Please note that we are passing two arguments to Sequence, topic name and server name.
3939

4040
```bash
41-
si seq deploy kaffka-consumer/dist --args [{\"topic\":\"scramjet\"},{\"server\":\"0.0.0.0:29092\"}]
41+
si seq deploy python/kafka-consumer/dist --args [{\"topic\":\"scramjet\"},{\"server\":\"0.0.0.0:29092\"}]
4242
```
4343

4444
Now you can deploy transform Sequence, with exactly same arguments:
4545

4646
```bash
47-
si seq deploy kaffka-transformer/dist --args [{\"topic\":\"scramjet\"},{\"server\":\"0.0.0.0:29092\"}]
47+
si seq deploy python/kafka-transformer/dist --args [{\"topic\":\"scramjet\"},{\"server\":\"0.0.0.0:29092\"}]
4848
```
4949

5050
You should be able to list both instances with command:
@@ -53,13 +53,13 @@ You should be able to list both instances with command:
5353
si inst ls`
5454
```
5555

56-
Last step is to start sending some data to transformer Sequence, which send it to Kaffka topic.
56+
Last step is to start sending some data to transformer Sequence, which send it to Kafka topic.
5757

5858
```bash
5959
si inst input -
6060
```
6161

62-
Type anything you want to blinking terminal, you should then see same data in first terminal, which shows logs from kaffka directly, but also you should be able to see information on STH terminal. It should look similar to:
62+
Type anything you want to blinking terminal, you should then see same data in first terminal, which shows logs from kafka directly, but also you should be able to see information on STH terminal. It should look similar to:
6363

6464
```bash
6565
Topic name=scramjet, Message=b'test message'

javascript/hello-snowman/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# hello-snowman ⛄
2+
3+
Sequence that reads incoming stream (input), and and modifies it by adding a text message according to the incoming data.
4+
5+
Stream is generated in [stream-gen.js](../tools/stream-gen-tool/stream-gen.js) file, where numbers in range of <-50,50> are randomly chosen and sent as Celsius degrees to `hello-snowman` Instance API endpoint `/input`.
6+
7+
Our `hello-snowman` app will read and interpret these Celsius degrees, and will inform us about state of our Snowman:
8+
9+
- if temperature will be 0 or below, Sequence will return message:
10+
11+
```bash
12+
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
13+
```
14+
15+
- in the other case (temperature above 0 degrees), Sequence will return message:
16+
17+
```bash
18+
Snowman ⛄ is melting! 🥵
19+
```
20+
21+
> 💡 **Please note that the sample below requires some previous installations before you start running it, you will find them [here](../../README.md#3-install-scramjet-transform-hub).**
22+
23+
## Running
24+
25+
Open three terminals and run the following commands:
26+
27+
**The first terminal:**
28+
29+
```bash
30+
# start sth
31+
scramjet-transform-hub
32+
```
33+
34+
**The second terminal**
35+
36+
```bash
37+
# go to 'hello-snowman' directory
38+
cd samples/hello-snowman
39+
40+
# install dependencies
41+
npm install
42+
43+
# go back to samples/ directory
44+
cd ../
45+
46+
# deploy 'hello-snowman' Sequence
47+
si seq deploy hello-snowman
48+
49+
# see the Instance output
50+
si inst output - # nothing happens until some is sent to input
51+
```
52+
53+
> 💡**NOTE:** Command `deploy` performs three actions at once: `pack`, `send` and `start` the Sequence. It is the same as if you would run those three commands separately:
54+
55+
```bash
56+
si seq pack . -o hello-snowman.tar.gz # compress 'hello-snowman/' directory into file named 'hello-snowman.tar.gz'
57+
58+
si seq send hello-snowman.tar.gz # send compressed Sequence to STH, this will output Sequence ID
59+
60+
si seq start - # start the Sequence, this will output Instance ID
61+
```
62+
63+
**In the third terminal**
64+
65+
```bash
66+
# Start stream generator tool with Instance ID as parameter
67+
node ./tools/stream-gen-tool/stream-gen.js <instance_id>
68+
```
69+
70+
## Output
71+
72+
Now you should see the output in the console:
73+
74+
```js
75+
$ si inst output -
76+
----------------------------------------
77+
Message# 1 | Temperature measure
78+
INPUT | -16
79+
OUTPUT| Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
80+
81+
----------------------------------------
82+
Message# 2 | Temperature measure
83+
INPUT | 49
84+
OUTPUT| Snowman ⛄ is melting! 🥵
85+
86+
----------------------------------------
87+
Message# 3 | Temperature measure
88+
INPUT | 16
89+
OUTPUT| Snowman ⛄ is melting! 🥵
90+
91+
----------------------------------------
92+
Message# 4 | Temperature measure
93+
INPUT | -46
94+
OUTPUT| Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
95+
96+
----------------------------------------
97+
```

javascript/hello-snowman/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { PassThrough } = require("stream");
2+
3+
module.exports = function(input) {
4+
// create output stream
5+
const out = new PassThrough({encoding: 'utf-8'});
6+
7+
// do something for each number in input stream
8+
input.on("data", data => {
9+
let outMessage = "";
10+
if (data > 0) {
11+
outMessage = "Snowman ⛄ is melting! 🥵" + "\n";
12+
} else {
13+
outMessage = "Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️" + "\n";
14+
}
15+
// write to output stream
16+
out.write(outMessage)
17+
});
18+
// return output stream so it can be consumed (e.g. by CLI client)
19+
return out;
20+
};

0 commit comments

Comments
 (0)