Skip to content

Commit

Permalink
v3.1.0 - More features and improvements
Browse files Browse the repository at this point in the history
 - Improved Dockerfile

    - Docker's `onbuild` images are seemingly deprecated. Now manually running `npm install` and copying
      required files to the image.

    - Updated from NodeJS version `8.11.4-onbuild` to `12.16.1-alpine3.11`

    - `config.json` is now a volume inside the container, allowing it to be updated with a simple `restart` instead
      of rebuilding the container

 - Added `publishonce` feature, which causes the script to publish a feed update immediately, then exit.

 - Added `repository` to `package.json` to silence `npm` errors.

 - Created `run.sh` management script, which will make it much simpler to use the dockerized `steemfeed-js`.
   Large portion of the run.sh code is based on https://github.com/Someguy123/steem-docker `run.sh`

    - Easy install docker with `./run.sh install_docker`

    - `./run.sh start` intelligently builds the docker image if it doesn't already exist, then creates and runs
      the container with the appropriate `docker run` flags.

    - `./run.sh publish` uses the `publishonce` steemfeed-js feature, combined with a docker container which is auto-removed
      after it finishes - no mess to cleanup :)

    - Various other features (see README.md and `./run.sh help`)

 - Added a `.dockerignore` file, which ensures `node_modules/`, `.env` and `config.json` never get sent to Docker's
   context. Speeding up the build, and preventing active keys etc. being stored inside of an image.

 - Updated README with new `run.sh` instructions for managing dockerized steemfeed
  • Loading branch information
Someguy123 committed Mar 22, 2020
1 parent e52e9c5 commit 1dd58f6
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.env
config.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
config.json
node_modules/
.env
22 changes: 21 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
FROM node:8.11.4-onbuild
FROM node:12.16.1-alpine3.11

WORKDIR /opt/steemfeed/

COPY package.json package-lock.json LICENSE /opt/steemfeed/

RUN npm install

COPY app.js /opt/steemfeed/app.js
COPY lib/ /opt/steemfeed/lib/
COPY tools/ /opt/steemfeed/tools/
COPY README.md example.env config.example.json config.advanced.json /opt/steemfeed/

LABEL maintainer="Chris (Someguy123) - https://github.com/Someguy123"
LABEL git_repository="https://github.com/Someguy123/steemfeed-js"


VOLUME /opt/steemfeed/config.json

CMD ["sh", "-c", "npm start"]

48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,34 @@ I recommend using Docker, however you can also use a locally installed copy of N

**Starting Via Docker**

```
docker build -t steemfeed-js .
docker run -itd --rm --name steemfeed steemfeed-js
```sh

# If you don't have docker installed yet, you can easily install it using run.sh
./run.sh install_docker

# (Optional) To save a little time, you can use my binary docker image, instead of having
# to build the container - which takes a few minutes (vs. a few seconds via binary install)
./run.sh install

# Now just start your feed :)
./run.sh start

# Check the logs / status to make sure it's working properly
./run.sh logs # Check the status with docker logs
./run.sh status # This will also help you check if it's running or not.

# If you need to force update your feed at any point
./run.sh publish

# Other useful commands:
./run.sh stop # To stop the steemfeed-js container
./run.sh restart # To restart the steemfeed-js container (e.g. after config changes)
./run.sh build # If you don't want to / can't use my binary image, this will force build a new image locally.

# Check the status with docker logs
docker logs steemfeed
```

**Starting Via NodeJS (assuming you have the correct version installed)**

```
npm install
npm start
Expand All @@ -40,32 +59,27 @@ npm start

To update the dockerised version simply do the following:

```
```sh
git pull
docker build -t steemfeed-js .
docker stop steemfeed
docker rm steemfeed
docker run -itd --name=steemfeed steemfeed-js
######
# You can also use this one-liner for the docker commands
###
docker build -t steemfeed-js .; docker stop steemfeed; docker rm steemfeed; docker run -itd --name=steemfeed steemfeed-js
./run.sh install
./run.sh restart
```

**Crontab**

As NodeJS is somewhat unreliable, it's recommended to use a cron to restart it every 2 hrs.
As NodeJS is somewhat unreliable, it's recommended to use a cron to restart it every 3 to 4 hrs.

crontab -e

For docker you can use the following
For docker you can use the following (restarts every 4 hrs)

```
0 */2 * * * docker restart steemfeed
0 */4 * * * docker restart steemfeed
```

Configuration
===========

```
{
"name": "your steem/hive name",
Expand Down
9 changes: 6 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ try {
process.exit(1);
}

var shouldPublish = process.argv.length > 2 && process.argv[2] == "publishnow";
var dryRun = process.argv.length > 2 && process.argv[2] == "dry";
var shouldPublish = settings.shouldPublish;
var dryRun = settings.dryRun;

var cap_sym = config.ex_symbol.toUpperCase(),
cap_comp = config.ex_compare.toUpperCase();
Expand Down Expand Up @@ -207,7 +207,10 @@ accountmgr.login().then((user_data) => {
var {username} = user_data;
log(`Successfully logged into ${username}`);
console.log();
if(shouldPublish || dryRun) {
if (settings.publishOnce) {
log('Argument "publishonce" passed. Publishing immediately, then exiting.');
return main();
} else if (shouldPublish || dryRun) {
log('Publishing immediately, then every %s minute(s)',config.interval);
main();
} else {
Expand Down
12 changes: 12 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Name of the container to create when calling ./run.sh start
DOCKER_NAME="steemfeed"

# Name of the docker image to run (also used as the image name when building)
DOCKER_IMAGE="steemfeed-js"

# DockerHub image source for ./run.sh install
DK_TAG="someguy123/steemfeed-js"

# Amount of seconds to wait with './run.sh stop' before killing the container
STOP_TIME=30

2 changes: 2 additions & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var config = require('../config.json');
var settings = {
shouldPublish: false,
dryRun: false,
publishOnce: false,
// Attempts = how many times to allow an RPC problem before giving up
// Delay = how long before a retry
retry_conf: {
Expand Down Expand Up @@ -59,6 +60,7 @@ for(var t_arg of process.argv) {
if(t_arg == '-v') global.verbose = true;
if (t_arg == "publishnow") settings.shouldPublish = true;
if (t_arg == "dry") settings.dryRun = true;
if (t_arg == "publishonce") settings.publishOnce = true;
}

settings.config = config;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "steemfeed-js",
"version": "2.1.0",
"description": "Steem Price Feed in JS with automatic retry for down nodes",
"repository": "https://github.com/someguy123/steemfeed-js",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
Loading

0 comments on commit 1dd58f6

Please sign in to comment.