Skip to content

Commit

Permalink
Merge pull request #264 from dappnode/v0.2.10
Browse files Browse the repository at this point in the history
v0.2.10 Release
  • Loading branch information
eduadiez authored Sep 19, 2019
2 parents 10acf0a + 23398a8 commit b02c688
Show file tree
Hide file tree
Showing 350 changed files with 20,275 additions and 10,957 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ build/src/dappmanagerdb.json

# Test artifacts
test_build/
test_build/*
test_build/.git/
test_build/.git/*
build/src/undefined/
build/src/test_files/
build/src/test_files/*
build/src/.temp-transfer/
build/src/.temp-transfer/*

# Version data file
.version.json
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/src/tmp_dnp_repo/
build/src/dnp_repo/
build/src/DNCORE/
build/src/cache/
build/src/dist/
build/src/dappmanagerdb.json
test_build/
.DS_Store
Expand All @@ -23,4 +24,5 @@ build/src/test_files/*
node_modules/\.yarn-integrity

# Typescript build artifacts
build/src/dist/
build/src/dist/
build/src/.temp-transfer/
25 changes: 12 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,27 @@ jobs:
directories:
- build/src/node_modules
install:
# This is a dockerized application, the node app is in /build/src
- cd ./build/src
- npm install
- cd ./build/src # Dockerized nodejs application
- yarn
before_script:
- npm run lint
- yarn lint
script:
- npm test -- --coverage # Include coverage when running tests
after_success: # Upload coverage reports
- COVERALLS_REPO_TOKEN=$coveralls_repo_token npm run coveralls
- yarn test

# Integration tests
###################
- stage: test
name: Integration tests
name: In app integration tests
node_js:
- "10.15.3"
services:
- docker
before_script:
- test/before_install.sh
cache:
directories:
- build/src/node_modules
install:
- cd ./build/src # Dockerized nodejs application
- yarn
script:
- test/test_integration.sh
- yarn test:int

# Test that it builds correctly
###############################
Expand Down
7 changes: 1 addition & 6 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ RUN yarn add typescript
COPY build/src .
RUN yarn build

# Typescript files
# While there is mixed content, .ts files get compiled in the same location
# to .js files, so the .ts should be ignored (deleted)
RUN rm src/**/*.ts


# Layer 3: Final layer
#####################################
Expand Down Expand Up @@ -95,6 +90,6 @@ RUN crontab -l | { cat; echo "* * * * * run-parts
# Copy the src last as it's the layer most likely to change
COPY --from=build-deps /usr/src/app /usr/src/app
COPY build/src/test /usr/src/app/test
COPY --from=build-src /usr/src/app/src /usr/src/app/src
COPY --from=build-src /usr/src/app/dist /usr/src/app/src

ENTRYPOINT /usr/src/app/entrypoint.sh
2 changes: 1 addition & 1 deletion build/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
crond
NODE_PATH=src node src/index.js
node src/index
1 change: 1 addition & 0 deletions build/src/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typings/
15 changes: 12 additions & 3 deletions build/src/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"extends": ["plugin:prettier/recommended","eslint:recommended"],
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended" // Uses the recommended rules from the @typescript-eslint/eslint-plugin
],
// "extends": ["plugin:prettier/recommended","eslint:recommended"],
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2018,
"sourceType": "module" // Allows for the use of imports
},
"env": {
"node": true,
"mocha": true,
"es6": true
},
"rules": {
"max-len": ["error", 1000]
"max-len": ["error", 1000],
// ##### Some libraries do not have typings and the compiler does not understand .d.ts files
"@typescript-eslint/no-var-requires": "off",
// ##### typescript does not understand hoisting
"@typescript-eslint/no-use-before-define": "off"
}
}
7 changes: 4 additions & 3 deletions build/src/getVersionData.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
# The purpose of this script is to export version variables
# The nodejs app should import the TARGET_FILE at runtime

export TARGET_FILE=.version.json
export VERSION_DATA_FILE="/usr/src/app/.version.json"

export VERSION=$(cat dappnode_package.json | jq -r '.version')
export BRANCH=$(git rev-parse --abbrev-ref HEAD)
export COMMIT=$(git rev-parse --verify HEAD)

jq -n --arg b "$BRANCH" --arg c "$COMMIT" --arg v "$VERSION" '{branch: $b, commit: $c, version: $v}' > $TARGET_FILE
jq -n --arg b "$BRANCH" --arg c "$COMMIT" --arg v "$VERSION" '{branch: $b, commit: $c, version: $v}' > $VERSION_DATA_FILE
# Make sure the file is created correctly
cat $TARGET_FILE
cat $VERSION_DATA_FILE

# Clean useless files
rm dappnode_package.json && rm -r .git
52 changes: 35 additions & 17 deletions build/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "NODE_PATH=src node src/index.js",
"start": "node dist/index.js",
"dev": "NODE_ENV=development npm start",
"build": "node_modules/.bin/tsc && npm run lint",
"file": "NODE_PATH=src node",
"test": "NODE_PATH=src TEST=true mocha --exit \"./{,!(node_modules)/**}/*.test.js\" ",
"test:file": "NODE_PATH=src TEST=true mocha --exit ",
"test:int": "NODE_PATH=src NODE_ENV=development LOG_LEVEL=debug mocha --exit \"./{,!(node_modules)/**}/*.test.int.js\" ",
"test:nyc": "nyc npm run test",
"test:int:nyc": "nyc npm run test.int",
"coverage": "NODE_PATH=src ./node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls",
"lint": "NODE_PATH=src ./node_modules/.bin/eslint . --ext .js --fix",
"pre-commit": "npm run lint && npm run test"
"watch-ts": "./node_modules/.bin/tsc -w",
"file": "node",
"test": "npm run test:file \"./{,!(node_modules)/**}/*.test.ts\" ",
"test:file": "TEST=true mocha -r ts-node/register --exit ",
"test:int": "npm run test:int:file \"./{,!(node_modules)/**}/*.test.int.ts\" ",
"test:int:file": "NODE_ENV=development LOG_LEVEL=debug WEB3_HOST=https://mainnet.infura.io/v3/bb15bacfcdbe45819caede241dcf8b0d IPFS_HOST=ipfs.dappnode.io mocha -r ts-node/register --exit",
"test:all": "npm run test && npm run test:int",
"coverage": "./node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls",
"lint": "./node_modules/.bin/eslint . --ext .ts --fix",
"pre-commit": "npm run build && npm run test"
},
"author": "dappLion",
"license": "ISC",
Expand All @@ -30,6 +31,7 @@
"datauri": "^1.1.0",
"deepmerge": "^2.2.1",
"docker-remote-api": "^5.0.0",
"dockerode": "^2.5.8",
"ethjs-provider-http": "^0.1.6",
"ethjs-rpc": "^0.2.0",
"express": "^4.17.1",
Expand All @@ -44,30 +46,46 @@
"lowdb": "^1.0.0",
"monero-rpc": "^0.5.0",
"node-docker-api": "^1.1.22",
"pretty-bytes": "^5.3.0",
"semver": "^5.5.0",
"shelljs": "^0.8.2",
"simple-statistics": "^6.0.1",
"table-parser": "^1.0.1",
"web3": "^1.0.0-beta.34",
"web3": "^1.0.0-beta.55",
"winston": "^3.0.0",
"yamljs": "^0.3.0"
},
"devDependencies": {
"@types/async": "^3.0.1",
"@types/autobahn": "^18.10.0",
"@types/chai": "^4.2.0",
"@types/cors": "^2.8.6",
"@types/dockerode": "^2.5.20",
"@types/express": "^4.17.0",
"@types/express-fileupload": "^1.1.0",
"@types/imagemin-pngquant": "^7.0.0",
"@types/joi": "^14.3.3",
"@types/lodash": "^4.14.137",
"@types/lowdb": "^1.0.9",
"@types/mocha": "^5.2.7",
"@types/node": "^12.7.1",
"@types/semver": "^6.0.1",
"@types/sinon": "^7.0.13",
"@types/web3": "^1.0.19",
"@types/winston": "^2.4.4",
"@types/yamljs": "^0.2.30",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"chai": "^4.1.2",
"coveralls": "^3.0.2",
"eslint": "^5.16.0",
"eslint": "^6.2.2",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-prettier": "^3.1.0",
"husky": "^2.3.0",
"mocha": "^6.1.4",
"mocha": "^6.2.0",
"nyc": "^11.8.0",
"prettier": "^1.16.4",
"proxyquire": "^2.0.1",
"rewiremock": "^3.13.7",
"sinon": "^5.0.10",
"sinon-chai": "^3.1.0",
"ts-node": "^8.3.0",
"typescript": "^3.5.3"
},
"husky": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
const semver = require("semver");
const params = require("params");
const { listContainers } = require("modules/dockerList");
const { getCoreVersionId } = require("utils/coreVersionId");
const autoUpdateHelper = require("utils/autoUpdateHelper");
const { shortNameCapitalized } = require("utils/format");
import semver from "semver";
import params from "../params";
import { listContainers } from "../modules/docker/listContainers";
import { getCoreVersionId } from "../utils/coreVersionId";
import * as autoUpdateHelper from "../utils/autoUpdateHelper";
import { shortNameCapitalized } from "../utils/format";
import {
AutoUpdateSettings,
AutoUpdateRegistry,
AutoUpdatePending,
AutoUpdateFeedback,
RpcHandlerReturn
} from "../types";

const { MY_PACKAGES, SYSTEM_PACKAGES } = autoUpdateHelper;

interface DnpsToShowInterface {
id: string;
displayName: string;
enabled: boolean;
feedback: AutoUpdateFeedback;
}

interface RpcAutoUpdateDataGetReturn extends RpcHandlerReturn {
result: {
settings: AutoUpdateSettings;
registry: AutoUpdateRegistry;
pending: AutoUpdatePending;
dnpsToShow: DnpsToShowInterface[];
};
}

/**
* Returns a auto-update data:
* - settings: If auto-updates are enabled for a specific DNP or DNPs
Expand Down Expand Up @@ -43,19 +66,21 @@ const { MY_PACKAGES, SYSTEM_PACKAGES } = autoUpdateHelper;
* }, ... ]
* }
*/
async function autoUpdateDataGet() {
const settings = await autoUpdateHelper.getSettings();
const registry = await autoUpdateHelper.getRegistry();
const pending = await autoUpdateHelper.getPending();
export default async function autoUpdateDataGet(): Promise<
RpcAutoUpdateDataGetReturn
> {
const settings = autoUpdateHelper.getSettings();
const registry = autoUpdateHelper.getRegistry();
const pending = autoUpdateHelper.getPending();

const dnpList = await listContainers();

const dnpsToShow = [
const dnpsToShow: DnpsToShowInterface[] = [
{
id: SYSTEM_PACKAGES,
displayName: "System packages",
enabled: await autoUpdateHelper.isCoreUpdateEnabled(),
feedback: await autoUpdateHelper.getCoreFeedbackMessage({
enabled: autoUpdateHelper.isCoreUpdateEnabled(),
feedback: autoUpdateHelper.getCoreFeedbackMessage({
currentVersionId: getCoreVersionId(
dnpList.filter(({ isCore }) => isCore)
)
Expand All @@ -64,16 +89,16 @@ async function autoUpdateDataGet() {
{
id: MY_PACKAGES,
displayName: "My packages",
enabled: await autoUpdateHelper.isDnpUpdateEnabled(),
enabled: autoUpdateHelper.isDnpUpdateEnabled(),
feedback: {}
}
];

if (await autoUpdateHelper.isDnpUpdateEnabled()) {
if (autoUpdateHelper.isDnpUpdateEnabled()) {
const singleDnpsToShow = [];
for (const dnp of dnpList) {
const storedDnp = singleDnpsToShow.find(_dnp => _dnp.name === dnp.name);
const storedVersion = (storedDnp || {}).version;
const storedVersion = storedDnp ? storedDnp.version : "";
if (
dnp.name &&
// Ignore core DNPs
Expand All @@ -89,13 +114,13 @@ async function autoUpdateDataGet() {
}

for (const dnp of singleDnpsToShow) {
const enabled = await autoUpdateHelper.isDnpUpdateEnabled(dnp.name);
const enabled = autoUpdateHelper.isDnpUpdateEnabled(dnp.name);
dnpsToShow.push({
id: dnp.name,
displayName: shortNameCapitalized(dnp.name),
enabled,
feedback: enabled
? await autoUpdateHelper.getDnpFeedbackMessage({
? autoUpdateHelper.getDnpFeedbackMessage({
id: dnp.name,
currentVersion: dnp.version
})
Expand All @@ -114,5 +139,3 @@ async function autoUpdateDataGet() {
}
};
}

module.exports = autoUpdateDataGet;
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
const {
import {
MY_PACKAGES, // "my-packages"
SYSTEM_PACKAGES, // "system-packages"
editDnpSetting,
editCoreSetting
} = require("utils/autoUpdateHelper");
} from "../utils/autoUpdateHelper";
import { RpcHandlerReturn } from "../types";

/**
* Edits the auto-update settings
*
* @param {string} id = "my-packages", "system-packages" or "bitcoin.dnp.dappnode.eth"
* @param {bool} enabled Auto update is enabled for ID
*/
const autoUpdateSettingsEdit = async ({ id, enabled }) => {
export default async function autoUpdateSettingsEdit({
id,
enabled
}: {
id: string;
enabled: boolean;
}): Promise<RpcHandlerReturn> {
if (!id)
throw Error(`Argument id is required or generalSettings must be true`);

if (id === MY_PACKAGES) await editDnpSetting(enabled);
else if (id === SYSTEM_PACKAGES) await editCoreSetting(enabled);
else await editDnpSetting(enabled, id);
if (id === MY_PACKAGES) editDnpSetting(enabled);
else if (id === SYSTEM_PACKAGES) editCoreSetting(enabled);
else editDnpSetting(enabled, id);

const name = ((id || "").split(".")[0] || "").replace("-", " ");
return {
message: `${enabled ? "Enabled" : "Disabled"} auto updates for ${name}`,
logMessage: true,
userAction: true
};
};

module.exports = autoUpdateSettingsEdit;
}
Loading

0 comments on commit b02c688

Please sign in to comment.